Added remaining ghosts incl. movment-strategies
This commit is contained in:
42
src/main/java/se/urmo/game/entities/InkyStrategy.java
Normal file
42
src/main/java/se/urmo/game/entities/InkyStrategy.java
Normal file
@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user