Minor fixes
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package se.urmo.game.entities.ghost;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import se.urmo.game.collision.GhostCollisionChecker;
|
||||
import se.urmo.game.entities.BaseAnimated;
|
||||
@ -39,6 +40,7 @@ public class Ghost extends BaseAnimated {
|
||||
private final LevelManager levelManager;
|
||||
private static final BufferedImage[] eatenAnimation = SpriteSheetManager.get(SpriteLocation.GHOST).getAnimation(9);
|
||||
private double speed;
|
||||
@Getter
|
||||
private MyPoint position;
|
||||
|
||||
private final GhostStrategy scaterStrategy;
|
||||
@ -236,10 +238,6 @@ public class Ghost extends BaseAnimated {
|
||||
this.speed = BASE_SPEED * levelManager.getGhostSpeed();
|
||||
}
|
||||
|
||||
public Point getPosition() {
|
||||
return new Point((int) position.x, (int) position.y);
|
||||
}
|
||||
|
||||
public boolean isEaten() {
|
||||
return mode == GhostMode.EATEN;
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package se.urmo.game.entities.ghost.strategy;
|
||||
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.entities.ghost.Ghost;
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.map.GameMap;
|
||||
|
||||
import java.awt.Point;
|
||||
@ -10,7 +10,7 @@ public class ClydeStrategy implements GhostStrategy {
|
||||
@Override
|
||||
public Point chooseTarget(Ghost clyde, PacMan pacman, GameMap map) {
|
||||
Point pacTile = pacman.getPosition();
|
||||
Point clydeTile = clyde.getPosition(); // ghost’s current tile
|
||||
Point clydeTile = clyde.getPosition().asPoint(); // ghost’s current tile
|
||||
|
||||
double distance = pacTile.distance(clydeTile);
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package se.urmo.game.entities.ghost.strategy;
|
||||
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.entities.ghost.Ghost;
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.map.GameMap;
|
||||
import se.urmo.game.util.Direction;
|
||||
|
||||
@ -16,18 +16,18 @@ public class FearStrategy implements GhostStrategy {
|
||||
public Point chooseTarget(Ghost ghost, PacMan pacman, GameMap map) {
|
||||
// Frightened ghosts do not target Pacman.
|
||||
// Instead, they pick a random adjacent valid tile.
|
||||
Point ghostPos = ghost.getPosition();
|
||||
Point ghostPos = ghost.getPosition().asPoint();
|
||||
List<Direction> neighbors = map.directionAlternatives(ghostPos.x, ghostPos.y);
|
||||
|
||||
if (neighbors.isEmpty()) {
|
||||
return ghost.getPosition(); // stuck
|
||||
return ghost.getPosition().asPoint(); // stuck
|
||||
}
|
||||
|
||||
//Transform directions to actual Points
|
||||
List<Point> potentialTargets = neighbors.stream()
|
||||
.map(d -> new Point(
|
||||
ghost.getPosition().x + d.dx * GameMap.MAP_TILESIZE,
|
||||
ghost.getPosition().y + d.dy * GameMap.MAP_TILESIZE)).toList();
|
||||
(int) (ghost.getPosition().x + d.dx * GameMap.MAP_TILESIZE),
|
||||
(int) (ghost.getPosition().y + d.dy * GameMap.MAP_TILESIZE))).toList();
|
||||
|
||||
// Pick a random valid neighbor
|
||||
return potentialTargets.get(random.nextInt(neighbors.size()));
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package se.urmo.game.entities.ghost.strategy;
|
||||
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.entities.ghost.Ghost;
|
||||
import se.urmo.game.entities.pacman.PacMan;
|
||||
import se.urmo.game.map.GameMap;
|
||||
import se.urmo.game.util.Direction;
|
||||
|
||||
@ -27,7 +27,7 @@ public class InkyStrategy implements GhostStrategy {
|
||||
};
|
||||
|
||||
// 2. Vector from blinky to that tile
|
||||
Point blinkyPos = blinky.getPosition();
|
||||
Point blinkyPos = blinky.getPosition().asPoint();
|
||||
int vx = ahead.x - blinkyPos.x;
|
||||
int vy = ahead.y - blinkyPos.y;
|
||||
|
||||
|
||||
@ -44,7 +44,6 @@ public class PacMan extends BaseAnimated {
|
||||
private BufferedImage[] deathFrames; // working copy
|
||||
private long lastChangeNs;
|
||||
// animation state
|
||||
@Setter
|
||||
private PacmanState state = PacmanState.ALIVE;
|
||||
private int deathFrameIdx = 0;
|
||||
private double speed;
|
||||
|
||||
@ -211,7 +211,7 @@ public class PlayingState implements GameState {
|
||||
for (Ghost ghost : ghostManager.getGhosts()) {
|
||||
if (deathInProgress) return; // guard
|
||||
//if(overlap(pacman, ghost)
|
||||
double dist = pacman.distanceTo(ghost.getPosition());
|
||||
double dist = pacman.distanceTo(ghost.getPosition().asPoint());
|
||||
if (dist < GameMap.MAP_TILESIZE / 2.0) {
|
||||
if (ghost.isEaten()) return;
|
||||
if (ghost.isFrightened()) {
|
||||
|
||||
Reference in New Issue
Block a user