diff --git a/bin/RabiClone.jar b/bin/RabiClone.jar index 8224fbf..6434a56 100644 Binary files a/bin/RabiClone.jar and b/bin/RabiClone.jar differ diff --git a/src/sig/DrawLoop.java b/src/sig/DrawLoop.java index 6b3dded..d28715c 100644 --- a/src/sig/DrawLoop.java +++ b/src/sig/DrawLoop.java @@ -11,7 +11,7 @@ public class DrawLoop { for (int y=0;y=p.length||p[index]==sprite.getBi_array()[Y*sprite.getWidth()+X]) { + 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) { continue; } else { - Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],true); - //Draw(p,index,sprite.getBi_array()[Y*sprite.getWidth()+X],false); + int index = (Y-(int)yOffset+(int)y)*RabiClone.BASE_WIDTH+X-(int)xOffset+(int)x; + 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],false); + } } } } diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index 44ec568..7432bb0 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -6,9 +6,8 @@ import java.util.ArrayList; import java.util.List; import sig.engine.Panel; -import sig.map.Map; import sig.map.Maps; -import sig.map.Tile; +import sig.objects.LevelRenderer; import sig.objects.Player; import sig.engine.Object; import java.awt.Toolkit; @@ -44,19 +43,9 @@ public class RabiClone{ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); + OBJ.add(new LevelRenderer(p)); OBJ.add(new Player(p)); - for (int i=0;i<12;i++) { - CURRENT_MAP.ModifyTile(0, i, Tile.WALL); - } - for (int i=0;i<36;i++) { - CURRENT_MAP.ModifyTile(i, 11, Tile.FLOOR); - } - for (int i=0;i<10;i++) { - CURRENT_MAP.ModifyTile(i+5, 8, Tile.PLATFORM_LEDGE); - } - Map.SaveMap(CURRENT_MAP); - p.render(); long lastGameTime = System.nanoTime(); diff --git a/src/sig/engine/Object.java b/src/sig/engine/Object.java index f0b3ef4..1a46f6b 100644 --- a/src/sig/engine/Object.java +++ b/src/sig/engine/Object.java @@ -1,5 +1,7 @@ package sig.engine; +import sig.DrawLoop; + public abstract class Object implements GameEntity{ double x,y; Sprite spr; @@ -45,6 +47,14 @@ public abstract class Object implements GameEntity{ this.spr = spr; } + protected void Draw_Sprite(double x, double y, Sprite sprite){ + DrawLoop.Draw_Sprite(x,y,sprite); + } + + protected void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite){ + DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite); + } + protected boolean KeyHeld(int key) { return panel.KEYS.getOrDefault(key,false); } diff --git a/src/sig/engine/Sprite.java b/src/sig/engine/Sprite.java index 2559803..218c2d5 100644 --- a/src/sig/engine/Sprite.java +++ b/src/sig/engine/Sprite.java @@ -10,6 +10,7 @@ public enum Sprite{ NANA(new File("..","3x.png")), NANA_SMALL(new File("..","1x.png")), + TILE_SHEET(new File("..","tiles.png")), ; diff --git a/src/sig/engine/SpriteImage.java b/src/sig/engine/SpriteImage.java deleted file mode 100644 index e69de29..0000000 diff --git a/src/sig/map/Maps.java b/src/sig/map/Maps.java index 0c7020a..bb52597 100644 --- a/src/sig/map/Maps.java +++ b/src/sig/map/Maps.java @@ -28,4 +28,13 @@ public enum Maps { map.ModifyTile(x, y, t); //System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+"."); } + + public Tile getTile(int x,int y) { + int index = y*Map.MAP_WIDTH+x; + if (index<0||index>=this.map.tiles.length) { + return Tile.VOID; + } else { + return Tile.values()[this.map.tiles[index]]; + } + } } diff --git a/src/sig/map/Tile.java b/src/sig/map/Tile.java index 15f3620..35ff1e1 100644 --- a/src/sig/map/Tile.java +++ b/src/sig/map/Tile.java @@ -5,7 +5,7 @@ public enum Tile { WALL(0,0), FLOOR(1,0), PLATFORM_LEDGE(2,0), - INVISIBLE_WALL(0,0,false), + INVISIBLE_WALL(0,0,true), ; final public static int TILE_WIDTH=32; diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java new file mode 100644 index 0000000..230ba2d --- /dev/null +++ b/src/sig/objects/LevelRenderer.java @@ -0,0 +1,47 @@ +package sig.objects; + +import java.awt.event.KeyEvent; +import sig.RabiClone; +import sig.engine.Object; +import sig.engine.Panel; +import sig.engine.Sprite; +import sig.map.Tile; + +public class LevelRenderer extends Object{ + + public LevelRenderer(Panel panel) { + super(panel); + this.setSprite(Sprite.TILE_SHEET); + } + + @Override + public void update(double updateMult) { + int right = KeyHeld(KeyEvent.VK_RIGHT)?1:0; + int left = KeyHeld(KeyEvent.VK_LEFT)?1:0; + int up = KeyHeld(KeyEvent.VK_UP)?1:0; + int down = KeyHeld(KeyEvent.VK_DOWN)?1:0; + if (right-left!=0) { + setX(getX()+(right-left)*256*updateMult); + } + if (up-down!=0) { + setY(getY()+(down-up)*256*updateMult); + } + } + + @Override + public void draw(int[] p) { + for (int y=(int)(0+this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) { + for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH);x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1);x++) { + if (RabiClone.CURRENT_MAP.getTile(x,y)!=Tile.VOID) { + DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getTile(x,y)); + //System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT))); + } + } + } + } + + private void DrawTile(double x, double y, Tile tile) { + Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite()); + } + +} diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index 523b1d2..26a7952 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -1,6 +1,5 @@ package sig.objects; -import sig.DrawLoop; import sig.RabiClone; import sig.engine.Object; import sig.engine.Panel; @@ -19,21 +18,11 @@ public class Player extends Object{ @Override public void update(double updateMult) { - int right = KeyHeld(KeyEvent.VK_RIGHT)?1:0; - int left = KeyHeld(KeyEvent.VK_LEFT)?1:0; - int up = KeyHeld(KeyEvent.VK_UP)?1:0; - int down = KeyHeld(KeyEvent.VK_DOWN)?1:0; - if (right-left!=0) { - setX(getX()+(right-left)*32*updateMult); - } - if (up-down!=0) { - setY(getY()+(down-up)*32*updateMult); - } } @Override public void draw(int[] p) { - DrawLoop.Draw_Sprite(this.getX(), this.getY(), this.getSprite()); + Draw_Sprite(this.getX(), this.getY(), this.getSprite()); } }