Skip to content

Commit

Permalink
Pause with controls hint
Browse files Browse the repository at this point in the history
  • Loading branch information
TEXH4Pb committed Nov 11, 2021
1 parent 1750bb1 commit 1ab665e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/src/com/mygdx/game/MyGdxGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MyGdxGame extends ApplicationAdapter {
ArrayList<Entity> entities;
Box2DDebugRenderer debugRenderer;
boolean debugMode = false;
boolean pauseMode = false;

@Override
public void create () {
Expand Down Expand Up @@ -107,12 +108,22 @@ public void render () {
batch.begin();
font.draw(batch, "SCORE: " + player.getScore(), 0 + screenWidth * 0.02f, screenHeight * 0.95f);
font.draw(batch, "LIFES: " + player.getLifes(), screenWidth - 150, screenHeight * 0.95f);
if(pauseMode)
showHint();
else if(player.getLifes() <= 0)
font.draw(batch, "GAME OVER!", screenWidth * 0.5f - 70, screenHeight * 0.5f);
if(debugMode)
font.draw(batch, "FPS " + Gdx.graphics.getFramesPerSecond(), 0 + screenWidth * 0.05f, screenHeight * 0.05f);
if(player.getLifes() <= 0)
font.draw(batch, "GAME OVER!", screenWidth * 0.5f - 70, screenHeight * 0.5f);
batch.end();
}

private void showHint() {
String text = "W - Fly towards cursor\nA/D - Strafe left/right\nLMB - Fire" +
"\nF1 - Help\nF5 - Restart\nF6 - Spawn extra asteroid" +
"\nF7 - Debug mode\nF11 - Toggle fullscreen\n\nGOOD LUCK!";
font.draw(batch, text, 0 + screenWidth * 0.05f, screenHeight * 0.9f);
}

@Override
public void resize(int width, int height) {
screenWidth = Gdx.graphics.getWidth();
Expand All @@ -132,7 +143,7 @@ public void dispose () {
private void updateGame()
{
systemKeysHandling();//mostly for debug purposes
if(player.getLifes() <= 0)
if(player.getLifes() <= 0 || pauseMode)
return;

world.step(STEP_TIME, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
Expand Down Expand Up @@ -209,6 +220,8 @@ else if(!Gdx.input.isKeyPressed(Input.Keys.A) && Gdx.input.isKeyPressed(Input.Ke
}

private void systemKeysHandling() {
if(Gdx.input.isKeyJustPressed(Input.Keys.F1))
pauseMode = !pauseMode;
if(Gdx.input.isKeyJustPressed(Input.Keys.F5))
restartGame(false);
if(Gdx.input.isKeyJustPressed(Input.Keys.F6))
Expand Down

0 comments on commit 1ab665e

Please sign in to comment.