More sounds! Closes #4
This commit is contained in:
		| @ -54,20 +54,25 @@ public class Sound { | |||||||
|         return id; |         return id; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public boolean isLooping(Effect effect) { | ||||||
|  |         return playing[effect.ordinal()] > -1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void stop(Effect effect) { |     public void stop(Effect effect) { | ||||||
|         long id = playing[effect.ordinal()]; |  | ||||||
|         com.badlogic.gdx.audio.Sound sound = getSound(effect); |         com.badlogic.gdx.audio.Sound sound = getSound(effect); | ||||||
|  |         long id = playing[effect.ordinal()]; | ||||||
|  |         if (id > -1) { | ||||||
|             sound.stop(id); |             sound.stop(id); | ||||||
|             playing[effect.ordinal()] = -1; |             playing[effect.ordinal()] = -1; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void stopAll() { |     public void stopAll() { | ||||||
|         for (int i = 0; i < playing.length; i++) { |         for (int i = 0; i < playing.length; i++) { | ||||||
|             if (playing[i] < 0) { |             if (playing[i] < 0) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|             getSound(Effect.values()[i]).stop(playing[i]); |             stop(Effect.values()[i]); | ||||||
|             playing[i] = -1; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -123,6 +123,7 @@ public class Ghost extends MovableEntity { | |||||||
|  |  | ||||||
|             if (currentPath instanceof EnterGhostHousePath) { |             if (currentPath instanceof EnterGhostHousePath) { | ||||||
|                 inHouse = true; |                 inHouse = true; | ||||||
|  |                 state.updateBackgroundAudio(); | ||||||
|             } |             } | ||||||
|             currentPath = null; |             currentPath = null; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -12,6 +12,7 @@ import com.me.pacman.PacDude; | |||||||
| import com.me.pacman.Sound; | import com.me.pacman.Sound; | ||||||
| import com.me.pacman.entity.*; | import com.me.pacman.entity.*; | ||||||
| import com.me.pacman.entity.ai.ReturnToBase; | import com.me.pacman.entity.ai.ReturnToBase; | ||||||
|  | import com.me.pacman.entity.path.EnterGhostHousePath; | ||||||
| import com.me.pacman.level.Level; | import com.me.pacman.level.Level; | ||||||
| import com.me.pacman.level.LevelTile; | import com.me.pacman.level.LevelTile; | ||||||
| import com.me.pacman.level.Modifiers; | import com.me.pacman.level.Modifiers; | ||||||
| @ -98,6 +99,32 @@ public class PlayState extends LevelState { | |||||||
|         super(game); |         super(game); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void updateBackgroundAudio() { | ||||||
|  |         for (Ghost ghost : ghosts) { | ||||||
|  |             if ((ghost.currentBehaviour instanceof ReturnToBase | ||||||
|  |                     || ghost.currentPath instanceof EnterGhostHousePath) && !ghost.inHouse) { | ||||||
|  |                 if (!game.sound.isLooping(Sound.Effect.RETURN_BASE)) { | ||||||
|  |                     game.sound.stopAll(); | ||||||
|  |                     game.sound.loop(Sound.Effect.RETURN_BASE); | ||||||
|  |                 } | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (frightTimer > 0) { | ||||||
|  |             if (!game.sound.isLooping(Sound.Effect.FRIGHT)) { | ||||||
|  |                 game.sound.stopAll(); | ||||||
|  |                 game.sound.loop(Sound.Effect.FRIGHT); | ||||||
|  |             } | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!game.sound.isLooping(Sound.Effect.SIREN)) { | ||||||
|  |             game.sound.stopAll(); | ||||||
|  |             game.sound.loop(Sound.Effect.SIREN); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private void setGameState(GameState state) { |     private void setGameState(GameState state) { | ||||||
|         this.state = state; |         this.state = state; | ||||||
|         this.stateTimer = state.timer; |         this.stateTimer = state.timer; | ||||||
| @ -162,6 +189,7 @@ public class PlayState extends LevelState { | |||||||
|  |  | ||||||
|         initializeLevel(); |         initializeLevel(); | ||||||
|  |  | ||||||
|  |         game.sound.stopAll(); | ||||||
|         game.sound.play(Sound.Effect.BEGINNING); |         game.sound.play(Sound.Effect.BEGINNING); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -199,38 +227,33 @@ public class PlayState extends LevelState { | |||||||
|         setGameState(GameState.PRE_NEW_GAME); |         setGameState(GameState.PRE_NEW_GAME); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void stateTransition() { |     public GameState stateTransition() { | ||||||
|         switch (state) { |         switch (state) { | ||||||
|             // The state we're transitioning /from/ |             // The state we're transitioning /from/ | ||||||
|             case PRE_NEW_GAME: |             case PRE_NEW_GAME: | ||||||
|                 newGame(); |                 newGame(); | ||||||
|                 setGameState(GameState.START_ROUND_WAIT); |                 return GameState.START_ROUND_WAIT; | ||||||
|                 break; |  | ||||||
|             case START_ROUND_WAIT: |             case START_ROUND_WAIT: | ||||||
|             case NEW_ROUND_WAIT: |             case NEW_ROUND_WAIT: | ||||||
|                 startGame(); |                 startGame(); | ||||||
|                 setGameState(GameState.PLAYING); |                 return GameState.PLAYING; | ||||||
|                 break; |  | ||||||
|             case ROUND_WON_WAIT: |             case ROUND_WON_WAIT: | ||||||
|                 setGameState(GameState.ROUND_WON); |                 return GameState.ROUND_WON; | ||||||
|                 break; |  | ||||||
|             case ROUND_WON: |             case ROUND_WON: | ||||||
|                 newRound(); |                 newRound(); | ||||||
|                 setGameState(GameState.NEW_ROUND_WAIT); |                 return GameState.NEW_ROUND_WAIT; | ||||||
|                 break; |  | ||||||
|             case GAME_OVER: |             case GAME_OVER: | ||||||
|                 preNewGame(); |                 preNewGame(); | ||||||
|                 setGameState(GameState.PRE_NEW_GAME); |                 return GameState.PRE_NEW_GAME; | ||||||
|                 break; |  | ||||||
|             case GHOST_CAUGHT_POINTS_WAIT: |             case GHOST_CAUGHT_POINTS_WAIT: | ||||||
|                 setGameState(GameState.PLAYING); |                 updateBackgroundAudio(); | ||||||
|                 break; |                 return GameState.PLAYING; | ||||||
|             case PACMAN_CAUGHT_WAIT: |             case PACMAN_CAUGHT_WAIT: | ||||||
|                 game.sound.play(Sound.Effect.DEATH); |                 game.sound.play(Sound.Effect.DEATH); | ||||||
|                 pacman.alive = false; |                 pacman.alive = false; | ||||||
|                 setGameState(GameState.PACMAN_CAUGHT); |                 return GameState.PACMAN_CAUGHT; | ||||||
|                 break; |  | ||||||
|         } |         } | ||||||
|  |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @ -337,6 +360,8 @@ public class PlayState extends LevelState { | |||||||
|         frightTimer = Modifiers.getFrightTime(round); |         frightTimer = Modifiers.getFrightTime(round); | ||||||
|         ghostsCaught = 0; |         ghostsCaught = 0; | ||||||
|         score += 50; |         score += 50; | ||||||
|  |  | ||||||
|  |         updateBackgroundAudio(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void pacmanCaught() { |     private void pacmanCaught() { | ||||||
| @ -357,6 +382,7 @@ public class PlayState extends LevelState { | |||||||
|         ghostsCaught++; |         ghostsCaught++; | ||||||
|         score += ghostsCaught * 200; |         score += ghostsCaught * 200; | ||||||
|  |  | ||||||
|  |         game.sound.play(Sound.Effect.EAT_GHOST); | ||||||
|         setGameState(GameState.GHOST_CAUGHT_POINTS_WAIT); |         setGameState(GameState.GHOST_CAUGHT_POINTS_WAIT); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -379,6 +405,8 @@ public class PlayState extends LevelState { | |||||||
|                 ghost.caught = false; |                 ghost.caught = false; | ||||||
|                 ghost.currentBehaviour = ghost.chaseBehaviour; |                 ghost.currentBehaviour = ghost.chaseBehaviour; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             updateBackgroundAudio(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -464,7 +492,7 @@ public class PlayState extends LevelState { | |||||||
|         if (state.timer > 0) { |         if (state.timer > 0) { | ||||||
|             stateTimer -= dt; |             stateTimer -= dt; | ||||||
|             if (stateTimer <= 0) { |             if (stateTimer <= 0) { | ||||||
|                 stateTransition(); |                 setGameState(stateTransition()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user