From 906ef93a11e7c3f4cf1086ebc8e7e3d9719c1b8e Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sat, 28 Dec 2019 13:32:23 +0400 Subject: [PATCH] Initialize all state vars in intializeField before new game Fixed ghosts remaining frightened at the start of a new round Fixed ghosts staying slow after being frightened Reduce wait time after death to 2 seconds --- core/src/com/me/pacman/state/PlayState.java | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index ebc6cbb..d839cbf 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -158,6 +158,7 @@ public class PlayState extends LevelState { if (ghost == null || ghost.currentBehaviour instanceof ReturnToBase) continue; ghost.caught = false; ghost.currentBehaviour = ghost.chaseBehaviour; + ghost.speed = Ghost.GHOST_SPEED; } } } @@ -188,7 +189,7 @@ public class PlayState extends LevelState { if (pacman.deathFrame == 13) { if (lives > 0) { setupGame(); - readyTimer = 3f; + readyTimer = 2f; } else { gameOverTimer = 2f; } @@ -200,6 +201,18 @@ public class PlayState extends LevelState { pacman.update(dt); } + public void initializeField() { + frightTimer = 0f; + deathTimer = 0f; + pacmanCaught = false; + ghostsCaught = 0; + lastGhostCaptured = null; + + random = new Random(897198256012865L); + ghosts = new Ghost[4]; + pacman = new Pacman(this, false); + } + public void newGame() { pelletCount = 0; pelletEatenCount = 0; @@ -207,31 +220,24 @@ public class PlayState extends LevelState { lives = 3; round = 0; - pacmanCaught = false; - deathTimer = 0f; - newGameTimer = 2.3f; - ghosts = new Ghost[4]; - pacman = new Pacman(this, false); - newRound(); } public void newRound() { round++; - level = new Level(game,"level"); - pacman = new Pacman(this, false); + level = new Level(game,"level"); + pelletCount = level.getTileCount(LevelTile.PELLET); + pelletCount += level.getTileCount(LevelTile.POWER_PELLET); + + initializeField(); if (newGameTimer <= 0) { spawnGhosts(); } game.assets.siren.stop(sirenId); - - pelletCount = level.getTileCount(LevelTile.PELLET); - pelletCount += level.getTileCount(LevelTile.POWER_PELLET); - if (round == 1) { readyTimer = 4.2f; game.assets.beginning_alt.play(1.0f); @@ -243,13 +249,7 @@ public class PlayState extends LevelState { public void setupGame() { lives--; - pacmanCaught = false; - - frightTimer = 0f; - - random = new Random(897198256012865L); - - pacman = new Pacman(this, false); + initializeField(); spawnGhosts(); }