Dots and eating works

This commit is contained in:
Urban Modig
2025-08-16 10:36:54 +02:00
parent 7bcc46122c
commit f15a01837d
5 changed files with 34 additions and 15 deletions

View File

@ -57,4 +57,8 @@ public class CollisionChecker {
return new Point(x, y);
}
public void removeTile(Point destination) {
map.removeTileImage(destination);
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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

1 1 2 2 2 2 2 2 2 2 2 2 2 2 45 46 2 2 2 2 2 2 2 2 2 2 2 2 3
7 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
8 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
9 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
10 0 99 0 99 0 99 0 99 0 99 22 0 15 8 27 27 28 0 26 28 0 26 27 27 7 17 0 20 0 99 0 99 0 99 0 99 0 99
11 0 99 0 99 0 99 0 99 0 99 22 0 15 17 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 15 17 0 20 0 99 0 99 0 99 0 99 0 99
12 0 99 0 99 0 99 0 99 0 99 22 0 15 17 0 99 34 35 36 37 38 35 35 39 0 99 15 17 0 20 0 99 0 99 0 99 0 99 0 99
13 32 32 32 32 32 33 0 26 28 0 99 40 0 99 0 99 0 99 0 99 0 99 0 99 41 0 99 26 28 0 31 32 32 32 32 32
14 0 0 0 0 0 0 0 0 0 0 99 40 0 99 0 99 0 99 0 99 0 99 0 99 41 0 99 0 0 0 0 0 0 0 0 0
15 10 10 10 10 10 11 0 4 6 0 99 40 0 99 0 99 0 99 0 99 0 99 0 99 41 0 99 4 6 0 9 10 10 10 10 10
16 0 99 0 99 0 99 0 99 0 99 22 0 15 17 0 99 42 43 43 43 43 43 43 44 0 99 15 17 0 20 0 99 0 99 0 99 0 99 0 99
17 0 99 0 99 0 99 0 99 0 99 22 0 15 17 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 0 99 15 17 0 20 0 99 0 99 0 99 0 99 0 99
18 0 99 0 99 0 99 0 99 0 99 22 0 15 17 0 99 4 5 5 5 5 5 5 6 0 99 15 17 0 20 0 99 0 99 0 99 0 99 0 99
19 1 32 32 32 32 33 0 26 28 0 99 26 27 27 7 8 27 27 28 0 99 26 28 0 31 2 2 2 2 3
20 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
21 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
22 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