diff --git a/maps/world1.map b/maps/world1.map index 43f8d92..932b45e 100644 Binary files a/maps/world1.map and b/maps/world1.map differ diff --git a/src/sig/map/CollisionType.java b/src/sig/map/CollisionType.java new file mode 100644 index 0000000..095a54d --- /dev/null +++ b/src/sig/map/CollisionType.java @@ -0,0 +1,6 @@ +package sig.map; + +public enum CollisionType { + BLOCK, + NONE +} diff --git a/src/sig/map/Tile.java b/src/sig/map/Tile.java index 761f127..f4ca9fc 100644 --- a/src/sig/map/Tile.java +++ b/src/sig/map/Tile.java @@ -1,12 +1,12 @@ package sig.map; public enum Tile { - VOID(0,0,true), //File is populated by 0s by default. This represents the void. - WALL(0,0), - FLOOR(1,0), - PLATFORM_LEDGE(2,0), - INVISIBLE_WALL(0,0,true), - HIGHLIGHTED_TILE(3,0), + VOID(0,0,true,CollisionType.NONE), //File is populated by 0s by default. This represents the void. + WALL(0,0,CollisionType.BLOCK), + FLOOR(1,0,CollisionType.BLOCK), + PLATFORM_LEDGE(2,0,CollisionType.BLOCK), + INVISIBLE_WALL(0,0,true,CollisionType.BLOCK), + HIGHLIGHTED_TILE(3,0,CollisionType.BLOCK), ; final public static int TILE_WIDTH=32; @@ -14,7 +14,20 @@ public enum Tile { int spriteSheetX,spriteSheetY; boolean invisible; + CollisionType collision; + public boolean isInvisible() { + return invisible; + } + public void setInvisible(boolean invisible) { + this.invisible = invisible; + } + public CollisionType getCollision() { + return collision; + } + public void setCollision(CollisionType collision) { + this.collision = collision; + } int tileWidth=TILE_WIDTH,tileHeight=TILE_HEIGHT; /*Tile(int spriteSheetX,int spriteSheetY,int tileWidth,int tileHeight) { this.spriteSheetX=spriteSheetX; @@ -22,13 +35,14 @@ public enum Tile { this.tileWidth=tileWidth; this.tileHeight=tileHeight; }*/ - Tile(int spriteSheetX,int spriteSheetY,boolean invisible) { + Tile(int spriteSheetX,int spriteSheetY,boolean invisible, CollisionType collision) { this.spriteSheetX=spriteSheetX; this.spriteSheetY=spriteSheetY; this.invisible=invisible; + this.collision=collision; } - Tile(int spriteSheetX,int spriteSheetY) { - this(spriteSheetX, spriteSheetY, false); + Tile(int spriteSheetX,int spriteSheetY, CollisionType collision) { + this(spriteSheetX, spriteSheetY, false, collision); } public int getSpriteSheetX() { diff --git a/src/sig/objects/LevelRenderer.java b/src/sig/objects/LevelRenderer.java index 6f3c3e3..ab73a2a 100644 --- a/src/sig/objects/LevelRenderer.java +++ b/src/sig/objects/LevelRenderer.java @@ -45,7 +45,7 @@ public class LevelRenderer extends Object{ Map.SaveMap(RabiClone.CURRENT_MAP); System.out.println("Map saved"); } - setY(RabiClone.player.getY()); + setY(RabiClone.player.getY()-RabiClone.BASE_HEIGHT*(2/3d)); } @Override diff --git a/src/sig/objects/Player.java b/src/sig/objects/Player.java index fd447a0..26db60a 100644 --- a/src/sig/objects/Player.java +++ b/src/sig/objects/Player.java @@ -4,12 +4,14 @@ import sig.RabiClone; import sig.engine.Object; import sig.engine.Panel; import sig.engine.Sprite; +import sig.map.CollisionType; +import sig.map.Tile; public class Player extends Object{ - double y_acceleration = 20; + double y_acceleration = 15; double x_acceleration = 0; double x_velocity = 0; - double y_velocity = -4; + double y_velocity = 5; public Player(Panel panel) { super(panel); @@ -23,7 +25,23 @@ public class Player extends Object{ public void update(double updateMult) { y_velocity += y_acceleration*updateMult; double displacement = y_velocity*updateMult; - this.setY(this.getY()+displacement); + boolean is_collision = false; + for(int i=0;i<4;i++){ + double check_distance = (displacement/4)*(i+1); + Tile checked_tile_top = RabiClone.CURRENT_MAP.getTile((int)getX()/Tile.TILE_WIDTH, (int)(getY()+check_distance)/Tile.TILE_HEIGHT); + Tile checked_tile_bottom = RabiClone.CURRENT_MAP.getTile((int)(getX()+getSprite().getWidth())/Tile.TILE_WIDTH, (int)(getY()+getSprite().getHeight()+check_distance)/Tile.TILE_HEIGHT); + //System.out.println((int)getX()/Tile.TILE_WIDTH); + if(checked_tile_bottom.getCollision()==CollisionType.BLOCK){ + setY((getY()+check_distance)+getSprite().getHeight()/2); + y_acceleration = 0; + y_velocity = 0; + is_collision=true; + break; + } + } + if (!is_collision){ + this.setY(this.getY()+displacement); + } } @Override