Add chase/scatter alternation
This commit is contained in:
parent
0d42aac28d
commit
dd9bdac33d
@ -105,14 +105,17 @@ public class Ghost extends MovableEntity {
|
|||||||
} else if (pos.y <= 16) {
|
} else if (pos.y <= 16) {
|
||||||
currDirection = Direction.UP;
|
currDirection = Direction.UP;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (currentBehaviour == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction nextDirection = getNextDirection();
|
if (!(currentBehaviour instanceof FrightenedBehaviour || currentBehaviour instanceof ReturnToBase)) {
|
||||||
|
if ((currentBehaviour == chaseBehaviour && !state.chase) || (currentBehaviour == scatterBehaviour && state.chase)) {
|
||||||
|
setNextDirection(currDirection.getOpposite());
|
||||||
|
}
|
||||||
|
currentBehaviour = state.chase? chaseBehaviour : scatterBehaviour;
|
||||||
|
}
|
||||||
|
|
||||||
|
Direction nextDirection = getNextDirection();
|
||||||
if (!canMove) {
|
if (!canMove) {
|
||||||
// we're stuck somewhere, let's change directions to a new valid direction
|
// we're stuck somewhere, let's change directions to a new valid direction
|
||||||
// check if we already have a nextDirection which will get us unstuck
|
// check if we already have a nextDirection which will get us unstuck
|
||||||
|
@ -47,6 +47,12 @@ public class PlayState extends LevelState {
|
|||||||
private float pointsTimer;
|
private float pointsTimer;
|
||||||
public float frightTimer;
|
public float frightTimer;
|
||||||
|
|
||||||
|
private float chaseTimer;
|
||||||
|
private float scatterTimer;
|
||||||
|
private int scatterCount;
|
||||||
|
|
||||||
|
public boolean chase;
|
||||||
|
|
||||||
private boolean pacmanCaught;
|
private boolean pacmanCaught;
|
||||||
private int ghostsCaught;
|
private int ghostsCaught;
|
||||||
private Ghost lastGhostCaptured;
|
private Ghost lastGhostCaptured;
|
||||||
@ -161,6 +167,24 @@ public class PlayState extends LevelState {
|
|||||||
ghost.speed = Ghost.GHOST_SPEED;
|
ghost.speed = Ghost.GHOST_SPEED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// pause chase/scatter timer when frightened
|
||||||
|
if (scatterTimer > 0) {
|
||||||
|
scatterTimer -= dt;
|
||||||
|
if (scatterTimer <= 0) {
|
||||||
|
chase = true;
|
||||||
|
if (scatterCount < 4) {
|
||||||
|
chaseTimer = 20f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (chaseTimer > 0) {
|
||||||
|
chaseTimer -= dt;
|
||||||
|
if (chaseTimer <= 0) {
|
||||||
|
chase = false;
|
||||||
|
scatterTimer = 7f;
|
||||||
|
scatterCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pacmanCaught) {
|
if (!pacmanCaught) {
|
||||||
@ -208,6 +232,12 @@ public class PlayState extends LevelState {
|
|||||||
ghostsCaught = 0;
|
ghostsCaught = 0;
|
||||||
lastGhostCaptured = null;
|
lastGhostCaptured = null;
|
||||||
|
|
||||||
|
if (chase) {
|
||||||
|
chaseTimer = 20f;
|
||||||
|
} else {
|
||||||
|
scatterTimer = 7f;
|
||||||
|
}
|
||||||
|
|
||||||
random = new Random(897198256012865L);
|
random = new Random(897198256012865L);
|
||||||
ghosts = new Ghost[4];
|
ghosts = new Ghost[4];
|
||||||
pacman = new Pacman(this, false);
|
pacman = new Pacman(this, false);
|
||||||
@ -237,6 +267,9 @@ public class PlayState extends LevelState {
|
|||||||
spawnGhosts();
|
spawnGhosts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chase = false;
|
||||||
|
scatterCount = 1;
|
||||||
|
|
||||||
game.assets.siren.stop(sirenId);
|
game.assets.siren.stop(sirenId);
|
||||||
if (round == 1) {
|
if (round == 1) {
|
||||||
readyTimer = 4.2f;
|
readyTimer = 4.2f;
|
||||||
@ -260,7 +293,7 @@ public class PlayState extends LevelState {
|
|||||||
ghosts[3] = new Ghost(this, 16f, 16.5f, Direction.UP, 3, new ClydeChaseBehaviour(this), new StaticTargetBehaviour(this, CLYDE_SCATTER_TARGET), true);
|
ghosts[3] = new Ghost(this, 16f, 16.5f, Direction.UP, 3, new ClydeChaseBehaviour(this), new StaticTargetBehaviour(this, CLYDE_SCATTER_TARGET), true);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
ghosts[i].currentBehaviour = ghosts[i].chaseBehaviour;
|
ghosts[i].currentBehaviour = ghosts[i].scatterBehaviour;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user