Finishing map-graphics
This commit is contained in:
@ -14,7 +14,9 @@ import java.util.Arrays;
|
||||
|
||||
|
||||
public class PacMan {
|
||||
public static final int PACMAN_SIZE = GamePanel.TILE_SIZE;
|
||||
public static final int PACMAN_SIZE = 32;
|
||||
private static final int COLLISION_BOX_SIZE = 8;
|
||||
private static final int COLLISION_BOX_OFFSET = (PACMAN_SIZE - COLLISION_BOX_SIZE) / 2;
|
||||
private final Game game;
|
||||
private int aniTick = 0;
|
||||
private int aniIndex = 0;
|
||||
@ -22,9 +24,8 @@ public class PacMan {
|
||||
private int speed = 1;
|
||||
private boolean moving;
|
||||
private final BufferedImage[][] movmentImages = new BufferedImage[4][4];
|
||||
//private int xPos = 14 * 16 + 8, yPos = 29 * 16; // top left of object
|
||||
private Point position;
|
||||
private static final BufferedImage innerBox = MiscUtil.createOutlinedBox(8, 8, Color.yellow, 2);
|
||||
private static final BufferedImage COLLISION_BOX = MiscUtil.createOutlinedBox(COLLISION_BOX_SIZE, COLLISION_BOX_SIZE, Color.yellow, 2);
|
||||
private CollisionChecker collisionChecker;
|
||||
private Direction direction = Direction.NONE;
|
||||
|
||||
@ -58,10 +59,13 @@ public class PacMan {
|
||||
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.drawImage(innerBox, position.x, position.y, PACMAN_SIZE, PACMAN_SIZE, null);
|
||||
//g.setColor(Color.RED);
|
||||
//g.drawLine(xPos, yPos, xPos, yPos);
|
||||
//g.drawImage(movmentImages[direction][aniIndex], xPos, yPos, PACMAN_SIZE, PACMAN_SIZE, null);
|
||||
g.drawImage(
|
||||
movmentImages[direction==Direction.NONE?0:direction.ordinal()][aniIndex],
|
||||
position.x - COLLISION_BOX_OFFSET,
|
||||
position.y - COLLISION_BOX_OFFSET,
|
||||
PACMAN_SIZE,
|
||||
PACMAN_SIZE, null);
|
||||
g.drawImage(COLLISION_BOX, position.x, position.y, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE, null);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
@ -76,7 +80,7 @@ public class PacMan {
|
||||
default -> throw new IllegalStateException("Unexpected value: " + direction);
|
||||
};
|
||||
|
||||
Point destination = collisionChecker.getValidDestination(direction, newPosition, PACMAN_SIZE, PACMAN_SIZE);
|
||||
Point destination = collisionChecker.getValidDestination(direction, newPosition, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE);
|
||||
|
||||
if(destination != null) {
|
||||
position = destination;
|
||||
@ -104,7 +108,6 @@ public class PacMan {
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.moving = true;
|
||||
this.direction = direction;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user