Reset on win, play the alternate music.

This commit is contained in:
Matt Low 2019-12-25 01:56:05 +04:00
parent fd30774746
commit fbd7715b5a
2 changed files with 41 additions and 16 deletions

View File

@ -24,10 +24,9 @@ public class Assets {
public TextureRegion[][] points; public TextureRegion[][] points;
public TextureRegion[][] volume; public TextureRegion[][] volume;
public Sound chomp_1; public Sound chomp_1, chomp_2;
public Sound chomp_2;
public Sound siren; public Sound siren;
public Sound beginning; public Sound beginning, beginning_alt;
public Assets() { public Assets() {
this.manager = new AssetManager(); this.manager = new AssetManager();
@ -49,6 +48,7 @@ public class Assets {
manager.load("sounds/chomp_2.wav", Sound.class); manager.load("sounds/chomp_2.wav", Sound.class);
manager.load("sounds/siren.wav", Sound.class); manager.load("sounds/siren.wav", Sound.class);
manager.load("sounds/beginning.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 // Yayyy! all of this to load a font
FileHandleResolver resolver = new InternalFileHandleResolver(); FileHandleResolver resolver = new InternalFileHandleResolver();
@ -77,6 +77,7 @@ public class Assets {
chomp_2 = manager.get("sounds/chomp_2.wav", Sound.class); chomp_2 = manager.get("sounds/chomp_2.wav", Sound.class);
siren = manager.get("sounds/siren.wav", Sound.class); siren = manager.get("sounds/siren.wav", Sound.class);
beginning = manager.get("sounds/beginning.wav", Sound.class); beginning = manager.get("sounds/beginning.wav", Sound.class);
beginning_alt = manager.get("sounds/beginning_alt.wav", Sound.class);
} }
public Texture getLevelBackground() { public Texture getLevelBackground() {

View File

@ -3,7 +3,6 @@ package com.me.pacman.state;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
@ -18,13 +17,16 @@ public class PlayState extends LevelState {
private Texture levelBackground; private Texture levelBackground;
private BitmapFont font; private BitmapFont font;
private int pelletCount = 0; private int pelletCount;
private int pelletEatenCount = 0; private int pelletEatenCount;
private int score = 0; private int score;
private int lives = 3; private int lives;
private int round;
public boolean paused = false; public boolean paused = false;
public boolean started = false; public boolean started = false;
private long sirenId;
private float waitTimer; private float waitTimer;
private TextureRegion lifeSprite; private TextureRegion lifeSprite;
@ -40,12 +42,14 @@ public class PlayState extends LevelState {
levelBackground = game.assets.getLevelBackground(); levelBackground = game.assets.getLevelBackground();
font = game.assets.getFont(); font = game.assets.getFont();
lifeSprite = game.assets.pacman[2][1]; lifeSprite = game.assets.pacman[2][1];
level = new Level(game,"level");
pelletCount = level.getTileCount(LevelTile.PELLET);
Gdx.input.setInputProcessor(new Controller()); Gdx.input.setInputProcessor(new Controller());
pelletCount = 0;
pelletEatenCount = 0;
score = 0;
lives = 3;
round = 0;
newGame(); newGame();
} }
@ -78,16 +82,32 @@ public class PlayState extends LevelState {
} }
public void newGame() { public void newGame() {
waitTimer = 4.3f; round++;
game.assets.beginning.play(1.0f); 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); pacman = new Pacman(this, false);
} }
public void startGame() { public void startGame() {
pacman.moving = true; pacman.moving = true;
game.assets.beginning.stop(); game.assets.beginning.stop();
game.assets.siren.loop(1.0f); game.assets.beginning_alt.stop();
lives--; sirenId = game.assets.siren.loop(1.0f);
if (round == 1) {
lives--;
}
} }
private void pelletEaten(float x, float y) { private void pelletEaten(float x, float y) {
@ -99,6 +119,10 @@ public class PlayState extends LevelState {
} }
pelletEatenCount++; pelletEatenCount++;
pelletCount--; pelletCount--;
if (pelletCount == 0) {
newGame();
}
} }
public void eatPellet(float x, float y) { public void eatPellet(float x, float y) {