From 7bece086838092038b21c86f98a86fe9a006232d Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 25 Dec 2019 17:50:52 +0400 Subject: [PATCH] Implement pause --- core/src/com/me/pacman/state/PlayState.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index 5e4a58b..03c97af 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -3,6 +3,7 @@ package com.me.pacman.state; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -23,7 +24,6 @@ public class PlayState extends LevelState { private int lives; private int round; public boolean paused = false; - public boolean started = false; private long sirenId; @@ -58,17 +58,27 @@ public class PlayState extends LevelState { game.batch.draw(levelBackground, 0, 16); level.render(0, 16); - pacman.render(game.batch, 0, 16); - + game.assets.getFont().setColor(Color.WHITE); + game.assets.getFont().draw(game.batch, "" + score, 40, 279); for (int i = 0; i < lives; i++) { game.batch.draw(lifeSprite, i * 16, 0); } - game.assets.getFont().draw(game.batch, "" + score, 40, 279); + pacman.render(game.batch, 0, 16); + + if (paused) { + game.assets.getFont().setColor(Color.YELLOW); + game.assets.getFont().draw(game.batch, "paused", 90, 151); + return; + } } @Override public void update(float dt) { + if (paused) { + return; + } + if (waitTimer > 0) { waitTimer -= dt; if (waitTimer <= 0) { @@ -158,6 +168,9 @@ public class PlayState extends LevelState { case Input.Keys.RIGHT: pacman.nextDirection = MovableEntity.Direction.EAST; break; + case Input.Keys.P: + paused = !paused; + break; } return super.keyDown(keycode); }