diff --git a/1x.gif b/1x.gif new file mode 100644 index 0000000..6c22ce7 Binary files /dev/null and b/1x.gif differ diff --git a/1x.png b/1x.png index 66e874d..7bd2a07 100644 Binary files a/1x.png and b/1x.png differ diff --git a/GamePalette.icc b/GamePalette.icc new file mode 100644 index 0000000..c1105e3 Binary files /dev/null and b/GamePalette.icc differ diff --git a/src/sig/DrawLoop.java b/src/sig/DrawLoop.java index e740c3e..0396b5d 100644 --- a/src/sig/DrawLoop.java +++ b/src/sig/DrawLoop.java @@ -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=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))); } } diff --git a/src/sig/engine/Alpha.java b/src/sig/engine/Alpha.java new file mode 100644 index 0000000..dfd61f5 --- /dev/null +++ b/src/sig/engine/Alpha.java @@ -0,0 +1,13 @@ +package sig.engine; + +public enum Alpha { + ALPHA0, + ALPHA32, + ALPHA64, + ALPHA96, + ALPHA128, + ALPHA160, + ALPHA192, + ALPHA224, + ALPHA256; +} diff --git a/src/sig/engine/GameEntity.java b/src/sig/engine/GameEntity.java index df2cd1c..c8581fa 100644 --- a/src/sig/engine/GameEntity.java +++ b/src/sig/engine/GameEntity.java @@ -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); } diff --git a/src/sig/engine/Object.java b/src/sig/engine/Object.java index ac86c42..ea2bd5b 100644 --- a/src/sig/engine/Object.java +++ b/src/sig/engine/Object.java @@ -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); } diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 1e21bda..9db31f4 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -51,6 +51,40 @@ public class Panel extends JPanel implements Runnable,KeyListener { public Point highlightedSquare = new Point(0,0); public HashMap KEYS = new HashMap<>(); public HashMap 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 edges_sorted = new ArrayList(); @@ -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=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) { - 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 void Draw(byte[] canvas,int index, byte col) { + canvas[index]=col; } @Override @@ -425,7 +414,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { @Override public void keyTyped(KeyEvent e) { - // TODO Auto-generated method stub } diff --git a/src/sig/engine/Sprite.java b/src/sig/engine/Sprite.java index 218c2d5..557533a 100644 --- a/src/sig/engine/Sprite.java +++ b/src/sig/engine/Sprite.java @@ -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; }; diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index ab73a2a..d4958c2 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -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); } diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index 9db9408..17e438b 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -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()); }