Added HOUSE mode

This commit is contained in:
Urban Modig
2025-09-06 00:12:08 +02:00
parent d551b464b1
commit e299a4173e
6 changed files with 46 additions and 18 deletions

View File

@ -11,11 +11,10 @@ import se.urmo.game.entities.ghost.mode.FrightenedGhostMode;
import se.urmo.game.entities.ghost.mode.FrozenGhostMode;
import se.urmo.game.entities.ghost.mode.GhostMode;
import se.urmo.game.entities.ghost.mode.GhostState;
import se.urmo.game.entities.ghost.mode.HouseGhostMode;
import se.urmo.game.entities.ghost.mode.ScatterGhostMode;
import se.urmo.game.entities.ghost.strategy.GhostStrategy;
import se.urmo.game.entities.pacman.PacMan;
import se.urmo.game.graphics.SpriteLocation;
import se.urmo.game.graphics.SpriteSheetManager;
import se.urmo.game.main.GhostManager;
import se.urmo.game.main.LevelManager;
import se.urmo.game.map.GameMap;
@ -23,7 +22,6 @@ import se.urmo.game.util.Direction;
import se.urmo.game.util.MyPoint;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.EnumMap;
import java.util.Map;
@ -36,8 +34,6 @@ public class Ghost extends BaseAnimated {
@Getter
private final GhostCollisionChecker collisionChecker;
@Getter
private final BufferedImage[] baseAnimation;
@Getter
private final int animation;
@Getter
private final LevelManager levelManager;
@ -61,29 +57,24 @@ public class Ghost extends BaseAnimated {
@Getter
private static final MyPoint startPosition = new MyPoint(
GameMap.colToScreen(13) + ((double) GameMap.MAP_TILESIZE / 2),
GameMap.rowToScreen(4) + ((double) GameMap.MAP_TILESIZE / 2));
;
GameMap.rowToScreen(12) + ((double) GameMap.MAP_TILESIZE / 2));
public Ghost(GhostCollisionChecker collisionChecker, GhostStrategy chaseStrategy, GhostStrategy scaterStrategy, int animation, LevelManager levelManager) {
super(ANIMATION_UPDATE_FREQUENCY, GhostManager.MAX_SPRITE_FRAMES);
this.collisionChecker = collisionChecker;
this.scaterStrategy = scaterStrategy;
this.baseAnimation = SpriteSheetManager.get(SpriteLocation.GHOST).getAnimation(animation);
this.animation = animation;
this.levelManager = levelManager;
this.position = startPosition;
states.put(GhostMode.CHASE, new ChaseGhostMode(this, chaseStrategy));
states.put(GhostMode.SCATTER, new ScatterGhostMode(this, scaterStrategy));
states.put(GhostMode.FRIGHTENED, new FrightenedGhostMode(this));
states.put(GhostMode.EATEN, new EatenGhostMode(this));
states.put(GhostMode.FROZEN, new FrozenGhostMode(this));
reset();
states.put(GhostMode.HOUSE, new HouseGhostMode(this));
}
public void draw(Graphics g) {
MyPoint position = currentState.getPosition();
g.drawImage(
currentState.getAnimation()[aniIndex],
(int) position.x - GHOST_SIZE / 2,
@ -98,7 +89,6 @@ public class Ghost extends BaseAnimated {
public void setMode(GhostMode mode) {
currentState = states.get(mode);
//currentState.enter(this);
}
public boolean isFrightened() {
@ -111,7 +101,6 @@ public class Ghost extends BaseAnimated {
public void reset() {
currentState = states.get(GhostMode.CHASE);
//currentState.enter(this);
((ChaseGhostMode) currentState).resetPosition();
}
}