Files
PacMan/src/main/java/se/urmo/game/entities/InkyStrategy.java
2025-08-20 15:26:06 +02:00

43 lines
1.4 KiB
Java

package se.urmo.game.entities;
import se.urmo.game.map.GameMap;
import se.urmo.game.util.Direction;
import java.awt.Point;
public class InkyStrategy implements GhostStrategy {
private final Ghost blinky;
public InkyStrategy(Ghost blinky) {
this.blinky = blinky;
}
@Override
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
// 1. Two tiles ahead of pacman
Direction pacmanDir = pacman.getDirection();
Point pacmanPos = pacman.getTilePosition();
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);
case DOWN -> new Point(pacmanPos.x, pacmanPos.y + 8 * GameMap.MAP_TILESIZE);
case UP -> new Point(pacmanPos.x, pacmanPos.y - 8 * GameMap.MAP_TILESIZE);
case NONE -> pacmanPos;
};
// 2. Vector from blinky to that tile
Point blinkyPos = blinky.getPosition();
int vx = ahead.x - blinkyPos.x;
int vy = ahead.y - blinkyPos.y;
// 3. Double the vector
Point target = new Point(
blinkyPos.x + 2 * vx,
blinkyPos.y + 2 * vy
);
return target;
// (Optional: clamp inside map boundaries)
//return map.clampToBounds(target);
}
}