From fbd7715b5a0c81879e472c83d2af5831de3370bd Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 25 Dec 2019 01:56:05 +0400 Subject: [PATCH] Reset on win, play the alternate music. --- core/src/com/me/pacman/Assets.java | 7 +-- core/src/com/me/pacman/state/PlayState.java | 50 +++++++++++++++------ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/core/src/com/me/pacman/Assets.java b/core/src/com/me/pacman/Assets.java index 75c05a6..4526496 100644 --- a/core/src/com/me/pacman/Assets.java +++ b/core/src/com/me/pacman/Assets.java @@ -24,10 +24,9 @@ public class Assets { public TextureRegion[][] points; public TextureRegion[][] volume; - public Sound chomp_1; - public Sound chomp_2; + public Sound chomp_1, chomp_2; public Sound siren; - public Sound beginning; + public Sound beginning, beginning_alt; public Assets() { this.manager = new AssetManager(); @@ -49,6 +48,7 @@ public class Assets { manager.load("sounds/chomp_2.wav", Sound.class); manager.load("sounds/siren.wav", Sound.class); manager.load("sounds/beginning.wav", Sound.class); + manager.load("sounds/beginning_alt.wav", Sound.class); // Yayyy! all of this to load a font FileHandleResolver resolver = new InternalFileHandleResolver(); @@ -77,6 +77,7 @@ public class Assets { chomp_2 = manager.get("sounds/chomp_2.wav", Sound.class); siren = manager.get("sounds/siren.wav", Sound.class); beginning = manager.get("sounds/beginning.wav", Sound.class); + beginning_alt = manager.get("sounds/beginning_alt.wav", Sound.class); } public Texture getLevelBackground() { diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index abfeaed..5e4a58b 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -3,7 +3,6 @@ package com.me.pacman.state; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -18,13 +17,16 @@ public class PlayState extends LevelState { private Texture levelBackground; private BitmapFont font; - private int pelletCount = 0; - private int pelletEatenCount = 0; - private int score = 0; - private int lives = 3; + private int pelletCount; + private int pelletEatenCount; + private int score; + private int lives; + private int round; public boolean paused = false; public boolean started = false; + private long sirenId; + private float waitTimer; private TextureRegion lifeSprite; @@ -40,12 +42,14 @@ public class PlayState extends LevelState { levelBackground = game.assets.getLevelBackground(); font = game.assets.getFont(); lifeSprite = game.assets.pacman[2][1]; - - level = new Level(game,"level"); - pelletCount = level.getTileCount(LevelTile.PELLET); - Gdx.input.setInputProcessor(new Controller()); + pelletCount = 0; + pelletEatenCount = 0; + score = 0; + lives = 3; + round = 0; + newGame(); } @@ -78,16 +82,32 @@ public class PlayState extends LevelState { } public void newGame() { - waitTimer = 4.3f; - game.assets.beginning.play(1.0f); + round++; + game.assets.siren.stop(sirenId); + + level = new Level(game,"level"); + pelletCount = level.getTileCount(LevelTile.PELLET); + pelletCount += level.getTileCount(LevelTile.POWER_PELLET); + + if (round == 1) { + waitTimer = 4.3f; + game.assets.beginning.play(1.0f); + } else { + waitTimer = 4.2f; + game.assets.beginning_alt.play(1.0f); + } + pacman = new Pacman(this, false); } public void startGame() { pacman.moving = true; game.assets.beginning.stop(); - game.assets.siren.loop(1.0f); - lives--; + game.assets.beginning_alt.stop(); + sirenId = game.assets.siren.loop(1.0f); + if (round == 1) { + lives--; + } } private void pelletEaten(float x, float y) { @@ -99,6 +119,10 @@ public class PlayState extends LevelState { } pelletEatenCount++; pelletCount--; + + if (pelletCount == 0) { + newGame(); + } } public void eatPellet(float x, float y) {