Basic score count working
update takes movement into account
This commit is contained in:
@ -7,6 +7,6 @@ import java.awt.Point;
|
||||
public class BlinkyStrategy implements GhostStrategy {
|
||||
@Override
|
||||
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
|
||||
return pacman.getTilePosition();
|
||||
return pacman.getPosition();
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import java.awt.Point;
|
||||
public class ClydeStrategy implements GhostStrategy {
|
||||
@Override
|
||||
public Point chooseTarget(Ghost clyde, PacMan pacman, GameMap map) {
|
||||
Point pacTile = pacman.getTilePosition();
|
||||
Point pacTile = pacman.getPosition();
|
||||
Point clydeTile = clyde.getPosition(); // ghost’s current tile
|
||||
|
||||
double distance = pacTile.distance(clydeTile);
|
||||
|
||||
@ -96,7 +96,7 @@ public class Ghost {
|
||||
Point point = new Point(
|
||||
position.x + direction.dx,
|
||||
position.y + direction.dy);
|
||||
log.debug("Next position {}", point);
|
||||
//log.debug("Next position {}", point);
|
||||
return point;
|
||||
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ public class InkyStrategy implements GhostStrategy {
|
||||
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
|
||||
// 1. Two tiles ahead of pacman
|
||||
Direction pacmanDir = pacman.getDirection();
|
||||
Point pacmanPos = pacman.getTilePosition();
|
||||
Point pacmanPos = pacman.getPosition();
|
||||
Point ahead = switch (pacmanDir){
|
||||
case RIGHT -> new Point(pacmanPos.x + 8 * GameMap.MAP_TILESIZE, pacmanPos.y);
|
||||
case LEFT -> new Point(pacmanPos.x - 8 * GameMap.MAP_TILESIZE, pacmanPos.y);
|
||||
|
||||
@ -30,6 +30,7 @@ public class PacMan {
|
||||
@Setter
|
||||
private boolean moving;
|
||||
private final BufferedImage[][] movmentImages = new BufferedImage[4][4];
|
||||
@Getter
|
||||
private Point position;
|
||||
private static final BufferedImage COLLISION_BOX = MiscUtil.createOutlinedBox(COLLISION_BOX_SIZE, COLLISION_BOX_SIZE, Color.yellow, 2);
|
||||
private final CollisionChecker collisionChecker;
|
||||
@ -82,21 +83,21 @@ public class PacMan {
|
||||
|
||||
public void update() {
|
||||
updateAnimationTick();
|
||||
if(direction == Direction.NONE) return;
|
||||
//if(direction == Direction.NONE) return;
|
||||
if(moving) {
|
||||
Point newPosition = switch (direction) {
|
||||
case RIGHT -> new Point(position.x + speed, position.y);
|
||||
case LEFT -> new Point(position.x - speed, position.y);
|
||||
case UP -> new Point(position.x, position.y - speed);
|
||||
case DOWN -> new Point(position.x, position.y + speed);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + direction);
|
||||
};
|
||||
log.debug("At: {},trying to move {} to {}", position, direction.name(), newPosition);
|
||||
Point destination = collisionChecker.getValidDestination(direction, newPosition, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE);
|
||||
|
||||
Point newPosition = switch (direction){
|
||||
case RIGHT -> new Point(position.x + speed, position.y);
|
||||
case LEFT -> new Point(position.x - speed, position.y);
|
||||
case UP -> new Point(position.x , position.y - speed);
|
||||
case DOWN -> new Point(position.x, position.y + speed);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + direction);
|
||||
};
|
||||
log.debug("At: {},trying to move {} to {}", position, direction.name(), newPosition);
|
||||
Point destination = collisionChecker.getValidDestination(direction, newPosition, COLLISION_BOX_SIZE, COLLISION_BOX_SIZE);
|
||||
|
||||
if(destination != null) {
|
||||
collisionChecker.removeTile(destination);
|
||||
position = destination;
|
||||
if (destination != null) {
|
||||
position = destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,10 +115,6 @@ public class PacMan {
|
||||
}
|
||||
}
|
||||
|
||||
public Point getTilePosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public double distanceTo(Point point) {
|
||||
return position.distance(point);
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ public class PinkyStrategy implements GhostStrategy{
|
||||
@Override
|
||||
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
|
||||
Direction pacmanDir = pacman.getDirection();
|
||||
Point pacmanPos = pacman.getTilePosition();
|
||||
Point pacmanPos = pacman.getPosition();
|
||||
return switch (pacmanDir){
|
||||
case RIGHT -> new Point(pacmanPos.x + 8 * GameMap.MAP_TILESIZE, pacmanPos.y);
|
||||
case LEFT -> new Point(pacmanPos.x - 8 * GameMap.MAP_TILESIZE, pacmanPos.y);
|
||||
|
||||
Reference in New Issue
Block a user