Dots and eating works
This commit is contained in:
@ -57,4 +57,8 @@ public class CollisionChecker {
|
||||
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public void removeTile(Point destination) {
|
||||
map.removeTileImage(destination);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user