diff --git a/core/src/com/me/pacman/Assets.java b/core/src/com/me/pacman/Assets.java index c301ec6..75c05a6 100644 --- a/core/src/com/me/pacman/Assets.java +++ b/core/src/com/me/pacman/Assets.java @@ -3,6 +3,7 @@ package com.me.pacman; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.loaders.FileHandleResolver; import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; +import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -25,6 +26,8 @@ public class Assets { public Sound chomp_1; public Sound chomp_2; + public Sound siren; + public Sound beginning; public Assets() { this.manager = new AssetManager(); @@ -44,6 +47,8 @@ public class Assets { manager.load("sounds/chomp_1.wav", Sound.class); manager.load("sounds/chomp_2.wav", Sound.class); + manager.load("sounds/siren.wav", Sound.class); + manager.load("sounds/beginning.wav", Sound.class); // Yayyy! all of this to load a font FileHandleResolver resolver = new InternalFileHandleResolver(); @@ -70,6 +75,8 @@ public class Assets { // all our sounds chomp_1 = manager.get("sounds/chomp_1.wav", Sound.class); 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); } public Texture getLevelBackground() { diff --git a/core/src/com/me/pacman/entity/Pacman.java b/core/src/com/me/pacman/entity/Pacman.java index d8169d4..e75a86f 100644 --- a/core/src/com/me/pacman/entity/Pacman.java +++ b/core/src/com/me/pacman/entity/Pacman.java @@ -13,14 +13,18 @@ public class Pacman extends MovableEntity { private int freezeFrames = 0; - public Pacman(PlayState state) { - super(state, 14, 7.5f, 7.5f, true, Direction.EAST, 0.3f); + public Pacman(PlayState state, boolean moving) { + super(state, 14, 7.5f, 7.5f, moving, Direction.EAST, 0.3f); this.state = state; sprite = state.getGame().assets.pacman; } @Override public TextureRegion getSprite() { + if (!moving) { + return sprite[0][0]; + } + int spriteDir; switch(currDirection) { case NORTH: @@ -36,7 +40,7 @@ public class Pacman extends MovableEntity { spriteDir = 3; break; } - return sprite[spriteDir][canMove && moving? counter % 3 : 1]; + return sprite[spriteDir][canMove ? counter % 3 : 1]; } @Override diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index b36a367..f8caf35 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -3,8 +3,10 @@ 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; import com.me.pacman.PacDude; import com.me.pacman.entity.MovableEntity; import com.me.pacman.entity.Pacman; @@ -19,8 +21,13 @@ public class PlayState extends LevelState { private int pelletCount = 0; private int pelletEatenCount = 0; private int score = 0; - + private int lives = 3; public boolean paused = false; + public boolean started = false; + + private float waitTimer; + + private TextureRegion lifeSprite; private Pacman pacman; @@ -32,13 +39,14 @@ public class PlayState extends LevelState { public void setup() { levelBackground = game.assets.getLevelBackground(); font = game.assets.getFont(); + lifeSprite = game.assets.pacman[2][1]; level = new Level(game,"level"); pelletCount = level.getTileCount(LevelTile.PELLET); - pacman = new Pacman(this); - Gdx.input.setInputProcessor(new Controller()); + + newGame(); } @Override @@ -48,17 +56,38 @@ public class PlayState extends LevelState { pacman.render(game.batch, 0, 16); - game.assets.getFont().draw(game.batch, "" + score, 25, 276); + for (int i = 0; i < lives; i++) { + game.batch.draw(lifeSprite, i * 16, 0); + } + + game.assets.getFont().draw(game.batch, "" + score, 40, 279); } @Override public void update(float dt) { + if (waitTimer > 0) { + waitTimer -= dt; + if (waitTimer <= 0) { + startGame(); + } else { + return; + } + } + pacman.update(dt); } - @Override - public void dispose() { - Gdx.input.setInputProcessor(null); + public void newGame() { + waitTimer = 4.3f; + game.assets.beginning.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--; } public void eatPellet(float x, float y) { @@ -73,6 +102,11 @@ public class PlayState extends LevelState { score += 10; } + @Override + public void dispose() { + Gdx.input.setInputProcessor(null); + } + private final class Controller extends InputAdapter { @Override