Implement pause

This commit is contained in:
Matt Low 2019-12-25 17:50:52 +04:00
parent 437ae39a9e
commit 7bece08683

View File

@ -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);
}