diff --git a/src/main/java/se/urmo/game/collision/CollisionChecker.java b/src/main/java/se/urmo/game/collision/CollisionChecker.java index d6d2f40..cff0e33 100644 --- a/src/main/java/se/urmo/game/collision/CollisionChecker.java +++ b/src/main/java/se/urmo/game/collision/CollisionChecker.java @@ -57,4 +57,8 @@ public class CollisionChecker { return new Point(x, y); } + + public void removeTile(Point destination) { + map.removeTileImage(destination); + } } diff --git a/src/main/java/se/urmo/game/entities/PacMan.java b/src/main/java/se/urmo/game/entities/PacMan.java index ef77e09..acf531e 100644 --- a/src/main/java/se/urmo/game/entities/PacMan.java +++ b/src/main/java/se/urmo/game/entities/PacMan.java @@ -83,6 +83,7 @@ public class PacMan { Point destination = collisionChecker.getValidDestination(direction, newPosition, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE); if(destination != null) { + collisionChecker.removeTile(destination); position = destination; } } diff --git a/src/main/java/se/urmo/game/map/GameMap.java b/src/main/java/se/urmo/game/map/GameMap.java index 0f82716..ddbfe3f 100644 --- a/src/main/java/se/urmo/game/map/GameMap.java +++ b/src/main/java/se/urmo/game/map/GameMap.java @@ -50,6 +50,7 @@ public class GameMap { private BufferedImage getSprite(int value) { return switch (value){ + case 0 -> images[1][1]; case 1 -> images[0][0]; case 2 -> images[0][1]; case 3 -> images[0][2]; @@ -111,7 +112,7 @@ public class GameMap { } private void loadSprites() { - BufferedImage img = LoadSave.GetSpriteAtlas("sprites/PacMan-custom-spritemap-0-1.png");//473B78 + BufferedImage img = LoadSave.GetSpriteAtlas("sprites/PacMan-custom-spritemap-0-3.png");//473B78 for (int row = 0; row < 5; row++) { for (int col = 0; col < 11; col++) { images[row][col] = img.getSubimage(MAP_TILESIZE * col, MAP_TILESIZE * row, MAP_TILESIZE, MAP_TILESIZE); @@ -158,4 +159,11 @@ public class GameMap { public int getHeight() { return GamePanel.SCREEN_HEIGHT; } + + public void removeTileImage(Point destination) { + int row = (destination.y - OFFSET_Y) / MAP_TILESIZE; + int col = (destination.x - OFFSET_X) / MAP_TILESIZE; + MapTile tile = mapData[row][col]; + if(tile.getValue() == 0) tile.setImage(null); + } } diff --git a/src/main/java/se/urmo/game/map/MapTile.java b/src/main/java/se/urmo/game/map/MapTile.java index 9e9968b..e640c02 100644 --- a/src/main/java/se/urmo/game/map/MapTile.java +++ b/src/main/java/se/urmo/game/map/MapTile.java @@ -4,17 +4,15 @@ import java.awt.image.BufferedImage; public class MapTile { private final int value; - private final BufferedImage image; + private BufferedImage image; private final boolean solid; private final boolean[][] collisionMask; public MapTile(BufferedImage image, int value) { this.value = value; this.image = image; -// this.image = value != 0 ? MiscUtil.createOutlinedBox(16, 16, Color.blue, 2) : null; - this.solid = value != 0; - this.collisionMask = createCollisionMask(image); + this.collisionMask = value != 0 ? createCollisionMask(image) : null; } public boolean[][] getCollisionMask() { @@ -42,4 +40,12 @@ public class MapTile { public boolean isPassable() { return ! this.solid; } + + public void setImage(BufferedImage img) { + this.image = img; + } + + public int getValue() { + return this.value; + } } diff --git a/src/main/resources/maps/map1.csv b/src/main/resources/maps/map1.csv index e9ac27d..be99ec7 100644 --- a/src/main/resources/maps/map1.csv +++ b/src/main/resources/maps/map1.csv @@ -7,16 +7,16 @@ 12, 0,26,27,27,28, 0,15,17, 0,26,27,27, 7, 8,27,27,28, 0,15,17, 0,26,27,27,28, 0,14 12, 0, 0, 0, 0, 0, 0,15,17, 0, 0, 0, 0,15,17, 0, 0, 0, 0,15,17, 0, 0, 0, 0, 0, 0,14 23,24,24,24,24,11, 0,15,19, 5, 5, 6, 0,15,17, 0, 4, 5, 5,18,17, 0, 9,10,10,10,10,25 - 0, 0, 0, 0, 0,22, 0,15, 8,27,27,28, 0,26,28, 0,26,27,27, 7,17, 0,20, 0, 0, 0, 0, 0 - 0, 0, 0, 0, 0,22, 0,15,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,17, 0,20, 0, 0, 0, 0, 0 - 0, 0, 0, 0, 0,22, 0,15,17, 0,34,35,36,37,38,35,35,39, 0,15,17, 0,20, 0, 0, 0, 0, 0 -32,32,32,32,32,33, 0,26,28, 0,40, 0, 0, 0, 0, 0, 0,41, 0,26,28, 0,31,32,32,32,32,32 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,40, 0, 0, 0, 0, 0, 0,41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -10,10,10,10,10,11, 0, 4, 6, 0,40, 0, 0, 0, 0, 0, 0,41, 0, 4, 6, 0, 9,10,10,10,10,10 - 0, 0, 0, 0, 0,22, 0,15,17, 0,42,43,43,43,43,43,43,44, 0,15,17, 0,20, 0, 0, 0, 0, 0 - 0, 0, 0, 0, 0,22, 0,15,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,17, 0,20, 0, 0, 0, 0, 0 - 0, 0, 0, 0, 0,22, 0,15,17, 0, 4, 5, 5, 5, 5, 5, 5, 6, 0,15,17, 0,20, 0, 0, 0, 0, 0 - 1,32,32,32,32,33, 0,26,28, 0,26,27,27, 7, 8,27,27,28, 0,26,28, 0,31, 2, 2, 2, 2, 3 +99,99,99,99,99,22, 0,15, 8,27,27,28, 0,26,28, 0,26,27,27, 7,17, 0,20,99,99,99,99,99 +99,99,99,99,99,22, 0,15,17,99,99,99,99,99,99,99,99,99,99,15,17, 0,20,99,99,99,99,99 +99,99,99,99,99,22, 0,15,17,99,34,35,36,37,38,35,35,39,99,15,17, 0,20,99,99,99,99,99 +32,32,32,32,32,33, 0,26,28,99,40,99,99,99,99,99,99,41,99,26,28, 0,31,32,32,32,32,32 + 0, 0, 0, 0, 0, 0, 0, 0, 0,99,40,99,99,99,99,99,99,41,99, 0, 0, 0, 0, 0, 0, 0, 0, 0 +10,10,10,10,10,11, 0, 4, 6,99,40,99,99,99,99,99,99,41,99, 4, 6, 0, 9,10,10,10,10,10 +99,99,99,99,99,22, 0,15,17,99,42,43,43,43,43,43,43,44,99,15,17, 0,20,99,99,99,99,99 +99,99,99,99,99,22, 0,15,17,99,99,99,99,99,99,99,99,99,99,15,17, 0,20,99,99,99,99,99 +99,99,99,99,99,22, 0,15,17,99, 4, 5, 5, 5, 5, 5, 5, 6,99,15,17, 0,20,99,99,99,99,99 + 1,32,32,32,32,33, 0,26,28,99,26,27,27, 7, 8,27,27,28,99,26,28, 0,31, 2, 2, 2, 2, 3 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,14 12, 0, 4, 5, 5, 6, 0, 4, 5, 5, 5, 6, 0,15,17, 0, 4, 5, 5, 5, 6, 0, 4, 5, 5, 6, 0,14 12, 0,26,27, 7,17, 0,26,27,27,27,28, 0,26,28, 0,26,27,27,27,28, 0,15, 8,27,28, 0,14