Don't reverse ghosts immediately, wait until they've reached the next tile
Also fix index out of bounds in retrieving next scatterChaseTimer value, and retrieving an offset-by-1 value (due to increasing scatterChaseTransition after retrieving the next timer value). Closes #9
This commit is contained in:
parent
fb3e26da35
commit
b770c2e40d
@ -38,6 +38,10 @@ public class Ghost extends MovableEntity {
|
|||||||
|
|
||||||
public int pelletCounter;
|
public int pelletCounter;
|
||||||
|
|
||||||
|
public boolean reverse;
|
||||||
|
private int prevTileX;
|
||||||
|
private int prevTileY;
|
||||||
|
|
||||||
public Ghost(PlayState state, Vector2 pos, Direction direction, int spriteIndex,
|
public Ghost(PlayState state, Vector2 pos, Direction direction, int spriteIndex,
|
||||||
Behaviour chaseBehaviour, Behaviour scatterBehaviour, boolean inHouse) {
|
Behaviour chaseBehaviour, Behaviour scatterBehaviour, boolean inHouse) {
|
||||||
super(state, pos.x, pos.y, Modifiers.getGhostSpeed(0), true, direction, 0.1f);
|
super(state, pos.x, pos.y, Modifiers.getGhostSpeed(0), true, direction, 0.1f);
|
||||||
@ -48,6 +52,7 @@ public class Ghost extends MovableEntity {
|
|||||||
this.frightBehaviour = new FrightenedBehaviour(state);
|
this.frightBehaviour = new FrightenedBehaviour(state);
|
||||||
this.inHouse = inHouse;
|
this.inHouse = inHouse;
|
||||||
this.caught = false;
|
this.caught = false;
|
||||||
|
this.reverse = false;
|
||||||
sprite = state.getGame().assets.ghosts;
|
sprite = state.getGame().assets.ghosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +88,11 @@ public class Ghost extends MovableEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dt) {
|
public void update(float dt) {
|
||||||
LevelTile currentTile = state.level.getTile(pos);
|
if (age % 15 == 0) {
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelTile currentTile = state.level.getTile(pos);
|
||||||
if (currentTile == null || currentTile == LevelTile.TUNNEL) {
|
if (currentTile == null || currentTile == LevelTile.TUNNEL) {
|
||||||
speed = Modifiers.getGhostTunnelSpeed(state.round);
|
speed = Modifiers.getGhostTunnelSpeed(state.round);
|
||||||
} else if (currentBehaviour instanceof FrightenedBehaviour) {
|
} else if (currentBehaviour instanceof FrightenedBehaviour) {
|
||||||
@ -97,11 +105,16 @@ public class Ghost extends MovableEntity {
|
|||||||
speed = getNormalSpeed();
|
speed = getNormalSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.update(dt);
|
int tileX = (int) pos.x;
|
||||||
|
int tileY = (int) pos.y;
|
||||||
if (age % 15 == 0) {
|
if (reverse && (tileX != prevTileX || tileY != prevTileY)) {
|
||||||
counter++;
|
setNextDirection(currDirection.getOpposite());
|
||||||
|
reverse = false;
|
||||||
}
|
}
|
||||||
|
prevTileX = tileX;
|
||||||
|
prevTileY = tileY;
|
||||||
|
|
||||||
|
super.update(dt);
|
||||||
|
|
||||||
if (currentPath != null) {
|
if (currentPath != null) {
|
||||||
if (!currentPath.finished()) {
|
if (!currentPath.finished()) {
|
||||||
@ -123,11 +136,9 @@ public class Ghost extends MovableEntity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentBehaviour == chaseBehaviour && state.scatter) {
|
if ((currentBehaviour == chaseBehaviour && state.scatter)
|
||||||
setNextDirection(currDirection.getOpposite());
|
|| (currentBehaviour == scatterBehaviour && !state.scatter)) {
|
||||||
updateBehaviour();
|
reverse = true;
|
||||||
} else if (currentBehaviour == scatterBehaviour && !state.scatter) {
|
|
||||||
setNextDirection(currDirection.getOpposite());
|
|
||||||
updateBehaviour();
|
updateBehaviour();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ public class PlayState extends LevelState {
|
|||||||
if (ghost.currentBehaviour instanceof ReturnToBase) continue;
|
if (ghost.currentBehaviour instanceof ReturnToBase) continue;
|
||||||
ghost.caught = false;
|
ghost.caught = false;
|
||||||
ghost.currentBehaviour = ghost.frightBehaviour;
|
ghost.currentBehaviour = ghost.frightBehaviour;
|
||||||
ghost.currDirection = ghost.currDirection.getOpposite();
|
ghost.reverse = true;
|
||||||
}
|
}
|
||||||
frightTimer = Modifiers.getFrightTime(round);
|
frightTimer = Modifiers.getFrightTime(round);
|
||||||
ghostsCaught = 0;
|
ghostsCaught = 0;
|
||||||
@ -365,13 +365,12 @@ public class PlayState extends LevelState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateScatterTimer(float dt) {
|
private void updateScatterTimer(float dt) {
|
||||||
if (scatterChaseTransition < 7) {
|
if (scatterChaseTransition < 6) {
|
||||||
// only update scatter timer if we're currently in scatter or if we've yet to enter scatter 4 times
|
|
||||||
scatterChaseTimer -= dt;
|
scatterChaseTimer -= dt;
|
||||||
if (scatterChaseTimer <= 0) {
|
if (scatterChaseTimer <= 0) {
|
||||||
scatter = !scatter;
|
scatter = !scatter;
|
||||||
scatterChaseTimer = Modifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
|
||||||
scatterChaseTransition++;
|
scatterChaseTransition++;
|
||||||
|
scatterChaseTimer = Modifiers.getScatterChaseTimer(round, scatterChaseTransition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user