@Override public void draw(Graphics2D g) { g.setColor(Color.white); g.drawString("Score: " + SCORE, 5, 15); g.setColor(Color.red); g.drawString("Health: " + player.getHealth(), 5, 35); blocks.draw(g); player.draw(g); level.draw(g); if (level.isGameOver()) { g.setColor(Color.red); g.setFont(gameScreen); String gameOver = "GAME OVER!"; int gameOverWidth = g.getFontMetrics().stringWidth(gameOver); g.drawString(gameOver, (Display.WIDTH / 2) - (gameOverWidth / 2), Display.HEIGHT / 2); } if (level.isComplete()) { g.setColor(Color.green); g.setFont(gameScreen); String complete = "LEVEL COMPLETE!"; int completeWidth = g.getFontMetrics().stringWidth(complete); g.drawString(complete, (Display.WIDTH / 2) - (completeWidth / 2), Display.HEIGHT / 2); } }
@Override public void update(double delta) { player.update(delta); level.update(delta, blocks); if (level.isGameOver()) { gameOverTimer.tick(delta); if (gameOverTimer.isEventReady()) { level.reset(); blocks.reset(); getStateMachine().setState((byte) 0); SCORE = 0; } } if (level.isComplete()) { completeTimer.tick(delta); if (completeTimer.isEventReady()) { level.reset(); } } }