Game Development Reference
In-Depth Information
private void updateGameOver(List < TouchEvent > touchEvents) {
int len = touchEvents.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type == TouchEvent. TOUCH_UP ) {
if (event.x >= 128 && event.x <= 192 &&
event.y >= 200 && event.y <= 264) {
if (Settings. soundEnabled )
Assets. click .play(1);
game.setScreen( new MainMenuScreen(game));
return ;
}
}
}
}
The updateGameOver() method also checks if the button in the middle of the screen was pressed.
If it has been pressed, then we initiate a screen transition back to the main menu screen.
@Override
public void present( float deltaTime) {
Graphics g = game.getGraphics();
g.drawPixmap(Assets. background , 0, 0);
drawWorld(world);
if (state == GameState. Ready )
drawReadyUI();
if (state == GameState. Running )
drawRunningUI();
if (state == GameState. Paused )
drawPausedUI();
if (state == GameState. GameOver )
drawGameOverUI();
drawText(g, score, g.getWidth() / 2 - score.length()*20 / 2, g.getHeight() - 42);
}
Next up are the rendering methods. The present() method first draws the background image, as
that is needed in all states. Next, it calls the respective drawing method for the state we are in.
Finally, it renders Mr. Nom's world and draws the score at the bottom-center of the screen.
private void drawWorld(World world) {
Graphics g = game.getGraphics();
Snake snake = world.snake;
SnakePart head = snake.parts.get(0);
Stain stain = world.stain;
Pixmap stainPixmap = null ;
if (stain.type == Stain. TYPE_1 )
stainPixmap = Assets. stain1 ;
 
Search WWH ::




Custom Search