Load images as gif indexed images
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
e2ebedca4d
commit
1d8438bc9a
BIN
1x.png
BIN
1x.png
Binary file not shown.
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 8.5 KiB |
BIN
GamePalette.icc
Normal file
BIN
GamePalette.icc
Normal file
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
package sig;
|
||||
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.Sprite;
|
||||
|
||||
@ -11,7 +12,7 @@ public class DrawLoop {
|
||||
|
||||
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
|
||||
for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
|
||||
p[y*RabiClone.BASE_WIDTH+x]=19;//RGB
|
||||
p[y*RabiClone.BASE_WIDTH+x]=0;//RGB
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +40,7 @@ public class DrawLoop {
|
||||
if (index<0||index>=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) {
|
||||
continue;
|
||||
} else {
|
||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],Alpha.ALPHA0);
|
||||
//Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false);
|
||||
}
|
||||
}
|
||||
@ -47,8 +48,8 @@ public class DrawLoop {
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, int alpha){
|
||||
int[] p = panel.pixel;
|
||||
public static void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha){
|
||||
byte[] p = panel.pixel;
|
||||
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
|
||||
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){
|
||||
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=RabiClone.BASE_WIDTH||Y-yOffset+y>=RabiClone.BASE_HEIGHT) {
|
||||
@ -58,52 +59,14 @@ public class DrawLoop {
|
||||
if (index<0||index>=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) {
|
||||
continue;
|
||||
} else {
|
||||
if (alpha==255) {
|
||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||
} else {
|
||||
int oldAlpha = sprite.getBi_array()[Y*sprite.getWidth()+X]>>>24;
|
||||
if (oldAlpha==0) {
|
||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true);
|
||||
} else
|
||||
if (oldAlpha==255) {
|
||||
Draw(p,index,(sprite.getBi_array()[Y*sprite.getWidth()+X]&0x00FFFFFF)|(alpha<<24),true);
|
||||
} else {
|
||||
Draw(p,index,(sprite.getBi_array()[Y*sprite.getWidth()+X]&0x00FFFFFF)|((int)((alpha/255d)*oldAlpha)<<24),true);
|
||||
}
|
||||
}
|
||||
//Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false);
|
||||
Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw(int[] canvas,int index, int col,boolean transparency) {
|
||||
if (!transparency) {
|
||||
canvas[index]=col;
|
||||
return;
|
||||
}
|
||||
int alpha = col>>>24;
|
||||
if (alpha==0) {
|
||||
return;}
|
||||
else
|
||||
if (alpha==255) {
|
||||
canvas[index]=col;
|
||||
} else {
|
||||
float ratio=alpha/255f;
|
||||
int prev_col=canvas[index];
|
||||
int prev_r=(prev_col&0xFF);
|
||||
int prev_g=(prev_col&0xFF00)>>>8;
|
||||
int prev_b=(prev_col&0xFF0000)>>>16;
|
||||
int r=(col&0xFF);
|
||||
int g=(col&0xFF00)>>>8;
|
||||
int b=(col&0xFF0000)>>>16;
|
||||
|
||||
int new_r=(int)(ratio*r+(1-ratio)*prev_r);
|
||||
int new_g=(int)(ratio*g+(1-ratio)*prev_g);
|
||||
int new_b=(int)(ratio*b+(1-ratio)*prev_b);
|
||||
|
||||
canvas[index]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000);
|
||||
}
|
||||
public static void Draw(byte[] canvas,int index, byte col, Alpha alpha) {
|
||||
canvas[index]=(byte)(((int)(col)&0xff)+(alpha.ordinal()*(32)));
|
||||
}
|
||||
}
|
||||
|
13
src/sig/engine/Alpha.java
Normal file
13
src/sig/engine/Alpha.java
Normal file
@ -0,0 +1,13 @@
|
||||
package sig.engine;
|
||||
|
||||
public enum Alpha {
|
||||
ALPHA0,
|
||||
ALPHA32,
|
||||
ALPHA64,
|
||||
ALPHA96,
|
||||
ALPHA128,
|
||||
ALPHA160,
|
||||
ALPHA192,
|
||||
ALPHA224,
|
||||
ALPHA256;
|
||||
}
|
@ -2,5 +2,5 @@ package sig.engine;
|
||||
|
||||
public interface GameEntity {
|
||||
public void update(double updateMult);
|
||||
public void draw(int[] p);
|
||||
public void draw(byte[] p);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public abstract class Object implements GameEntity{
|
||||
this.spr = spr;
|
||||
}
|
||||
|
||||
public void drawOverlay(int[] p) {
|
||||
public void drawOverlay(byte[] p) {
|
||||
}
|
||||
|
||||
protected void Draw_Sprite(double x, double y, Sprite sprite){
|
||||
@ -58,7 +58,7 @@ public abstract class Object implements GameEntity{
|
||||
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite);
|
||||
}
|
||||
|
||||
protected void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, int alpha){
|
||||
protected void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Alpha alpha){
|
||||
DrawLoop.Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,alpha);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,40 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
public Point highlightedSquare = new Point(0,0);
|
||||
public HashMap<Integer,Boolean> KEYS = new HashMap<>();
|
||||
public HashMap<Integer,Boolean> MOUSE = new HashMap<>();
|
||||
public static byte[] generalPalette = new byte[]{
|
||||
(byte)0x5b,(byte)0xa6,(byte)0x75,
|
||||
(byte)0x6b,(byte)0xc9,(byte)0x6c,
|
||||
(byte)0xab,(byte)0xdd,(byte)0x64,
|
||||
(byte)0xfc,(byte)0xef,(byte)0x8d,
|
||||
(byte)0xff,(byte)0xb8,(byte)0x79,
|
||||
(byte)0xea,(byte)0x62,(byte)0x62,
|
||||
(byte)0xcc,(byte)0x42,(byte)0x5e,
|
||||
(byte)0xa3,(byte)0x28,(byte)0x58,
|
||||
(byte)0x75,(byte)0x17,(byte)0x56,
|
||||
(byte)0x39,(byte)0x09,(byte)0x47,
|
||||
(byte)0x61,(byte)0x18,(byte)0x51,
|
||||
(byte)0x87,(byte)0x35,(byte)0x55,
|
||||
(byte)0xa6,(byte)0x55,(byte)0x5f,
|
||||
(byte)0xc9,(byte)0x73,(byte)0x73,
|
||||
(byte)0xf2,(byte)0xae,(byte)0x99,
|
||||
(byte)0xff,(byte)0xc3,(byte)0xf2,
|
||||
(byte)0xee,(byte)0x8f,(byte)0xcb,
|
||||
(byte)0xd4,(byte)0x6e,(byte)0xb3,
|
||||
(byte)0x87,(byte)0x3e,(byte)0x84,
|
||||
(byte)0x1f,(byte)0x10,(byte)0x2a,
|
||||
(byte)0x4a,(byte)0x30,(byte)0x52,
|
||||
(byte)0x7b,(byte)0x54,(byte)0x80,
|
||||
(byte)0xa6,(byte)0x85,(byte)0x9f,
|
||||
(byte)0xd9,(byte)0xbd,(byte)0xc8,
|
||||
(byte)0xff,(byte)0xff,(byte)0xff,
|
||||
(byte)0xae,(byte)0xe2,(byte)0xff,
|
||||
(byte)0x8d,(byte)0xb7,(byte)0xff,
|
||||
(byte)0x6d,(byte)0x80,(byte)0xfa,
|
||||
(byte)0x84,(byte)0x65,(byte)0xec,
|
||||
(byte)0x83,(byte)0x4d,(byte)0xc4,
|
||||
(byte)0x7d,(byte)0x2d,(byte)0xa0,
|
||||
(byte)0x4e,(byte)0x18,(byte)0x7c,
|
||||
};
|
||||
|
||||
public Panel(JFrame f) {
|
||||
super(true);
|
||||
@ -126,51 +160,17 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
* @return color model
|
||||
*/
|
||||
protected static ColorModel getCustomPalette(){
|
||||
char[] generalPalette = new char[]{
|
||||
0x5b,0xa6,0x75,0xff,
|
||||
0x6b,0xc9,0x6c,0xff,
|
||||
0xab,0xdd,0x64,0xff,
|
||||
0xfc,0xef,0x8d,0xff,
|
||||
0xff,0xb8,0x79,0xff,
|
||||
0xea,0x62,0x62,0xff,
|
||||
0xcc,0x42,0x5e,0xff,
|
||||
0xa3,0x28,0x58,0xff,
|
||||
0x75,0x17,0x56,0xff,
|
||||
0x39,0x09,0x47,0xff,
|
||||
0x61,0x18,0x51,0xff,
|
||||
0x87,0x35,0x55,0xff,
|
||||
0xa6,0x55,0x5f,0xff,
|
||||
0xc9,0x73,0x73,0xff,
|
||||
0xf2,0xae,0x99,0xff,
|
||||
0xff,0xc3,0xf2,0xff,
|
||||
0xee,0x8f,0xcb,0xff,
|
||||
0xd4,0x6e,0xb3,0xff,
|
||||
0x87,0x3e,0x84,0xff,
|
||||
0x1f,0x10,0x2a,0xff,
|
||||
0x4a,0x30,0x52,0xff,
|
||||
0x7b,0x54,0x80,0xff,
|
||||
0xa6,0x85,0x9f,0xff,
|
||||
0xd9,0xbd,0xc8,0xff,
|
||||
0xff,0xff,0xff,0xff,
|
||||
0xae,0xe2,0xff,0xff,
|
||||
0x8d,0xb7,0xff,0xff,
|
||||
0x6d,0x80,0xfa,0xff,
|
||||
0x84,0x65,0xec,0xff,
|
||||
0x83,0x4d,0xc4,0xff,
|
||||
0x7d,0x2d,0xa0,0xff,
|
||||
0x4e,0x18,0x7c,0xff,
|
||||
};
|
||||
byte[] finalPalette = new byte[32*3*8];
|
||||
byte[] finalPalette = new byte[32*4*8];
|
||||
for (int i=0;i<8;i++) {
|
||||
for (int j=0;j<generalPalette.length;j+=4) {
|
||||
finalPalette[(32*3*i)+j+0]=(byte)generalPalette[j+0];
|
||||
finalPalette[(32*3*i)+j+1]=(byte)generalPalette[j+1];
|
||||
finalPalette[(32*3*i)+j+2]=(byte)generalPalette[j+2];
|
||||
finalPalette[(32*3*i)+j+3]=(byte)(generalPalette[j+3]-(i*(256/8)));
|
||||
finalPalette[(32*3*i)+j+3]=(byte)(256-(i*(256/8)));
|
||||
}
|
||||
}
|
||||
|
||||
IndexColorModel model = new IndexColorModel(8,32,finalPalette,0,true);
|
||||
IndexColorModel model = new IndexColorModel(5,32,generalPalette,0,false);
|
||||
return model;
|
||||
}
|
||||
|
||||
@ -223,11 +223,16 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
DrawLoop.drawGame(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Until it implements the new indexed coloring mode, this is unusable.
|
||||
*/
|
||||
@Deprecated
|
||||
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
|
||||
for (int xx=0;xx<w;xx++) {
|
||||
for (int yy=0;yy<h;yy++) {
|
||||
int index = ((int)y+yy)*getWidth()+(int)x+xx;
|
||||
Draw(p,index,col.getColor());
|
||||
//TODO Old Color System
|
||||
//Draw(p,index,col.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -265,6 +270,10 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
FillPolygon(p,col,0,0,points);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Until it implements the new indexed coloring mode, this is unusable.
|
||||
*/
|
||||
@Deprecated
|
||||
public void FillPolygon(int[] p,Color col,double x_offset,double y_offset,Point...points) {
|
||||
Edge[] edges = new Edge[points.length];
|
||||
List<Edge> edges_sorted = new ArrayList<Edge>();
|
||||
@ -301,7 +310,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) {
|
||||
int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset;
|
||||
if (index<p.length&&index>=0) {
|
||||
Draw(p,index,col.getColor());
|
||||
//TODO Old color system.
|
||||
//Draw(p,index,col.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -363,29 +373,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(int[] canvas,int index, int col) {
|
||||
int alpha = col>>>24;
|
||||
if (alpha==0) {
|
||||
return;}
|
||||
else
|
||||
if (alpha==255) {
|
||||
public void Draw(byte[] canvas,int index, byte col) {
|
||||
canvas[index]=col;
|
||||
} else {
|
||||
float ratio=alpha/255f;
|
||||
int prev_col=canvas[index];
|
||||
int prev_r=(prev_col&0xFF);
|
||||
int prev_g=(prev_col&0xFF00)>>>8;
|
||||
int prev_b=(prev_col&0xFF0000)>>>16;
|
||||
int r=(col&0xFF);
|
||||
int g=(col&0xFF00)>>>8;
|
||||
int b=(col&0xFF0000)>>>16;
|
||||
|
||||
int new_r=(int)(ratio*r+(1-ratio)*prev_r);
|
||||
int new_g=(int)(ratio*g+(1-ratio)*prev_g);
|
||||
int new_b=(int)(ratio*b+(1-ratio)*prev_b);
|
||||
|
||||
canvas[index]=new_r+(new_g<<8)+(new_b<<16)+(col&0xFF000000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -425,7 +414,6 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,15 @@ package sig.engine;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.awt.image.DataBufferByte;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public enum Sprite{
|
||||
|
||||
NANA(new File("..","3x.png")),
|
||||
NANA_SMALL(new File("..","1x.png")),
|
||||
NANA_SMALL(new File("..","1x.gif")),
|
||||
TILE_SHEET(new File("..","tiles.png")),
|
||||
;
|
||||
|
||||
@ -18,15 +20,14 @@ public enum Sprite{
|
||||
BufferedImage img;
|
||||
int height;
|
||||
int width;
|
||||
int[] bi_array;
|
||||
byte[] bi_array;
|
||||
|
||||
Sprite(File filename){
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(filename);
|
||||
this.width=img.getWidth();
|
||||
this.height=img.getHeight();
|
||||
this.bi_array = new int[width*height];
|
||||
img.getRGB(0,0,width,height,this.bi_array,0,width);
|
||||
bi_array = ((DataBufferByte)(img.getRaster().getDataBuffer())).getData();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -57,11 +58,11 @@ public enum Sprite{
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int[] getBi_array() {
|
||||
public byte[] getBi_array() {
|
||||
return bi_array;
|
||||
}
|
||||
|
||||
public void setBi_array(int[] bi_array) {
|
||||
public void setBi_array(byte[] bi_array) {
|
||||
this.bi_array = bi_array;
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.MouseScrollValue;
|
||||
import sig.engine.Object;
|
||||
import sig.engine.Panel;
|
||||
@ -59,7 +60,7 @@ public class LevelRenderer extends Object{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int[] p) {
|
||||
public void draw(byte[] p) {
|
||||
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) {
|
||||
if (y<0||y>Map.MAP_HEIGHT) {
|
||||
continue;
|
||||
@ -73,7 +74,7 @@ public class LevelRenderer extends Object{
|
||||
//System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT)));
|
||||
}
|
||||
if (x==RabiClone.p.highlightedSquare.getX()&&y==RabiClone.p.highlightedSquare.getY()) {
|
||||
DrawTransparentTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),selectedTile,64);
|
||||
DrawTransparentTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),selectedTile,Alpha.ALPHA64);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,7 +84,7 @@ public class LevelRenderer extends Object{
|
||||
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite());
|
||||
}
|
||||
|
||||
private void DrawTransparentTile(double x, double y, Tile tile, int alpha) {
|
||||
private void DrawTransparentTile(double x, double y, Tile tile, Alpha alpha) {
|
||||
Draw_Sprite_Partial_Ext(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), alpha);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class Player extends Object{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int[] p) {
|
||||
public void draw(byte[] p) {
|
||||
Draw_Sprite(RabiClone.BASE_WIDTH/2-getSprite().getWidth()/2,RabiClone.BASE_HEIGHT*(2/3d)-getSprite().getHeight()/2, this.getSprite());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user