Game Development Reference
In-Depth Information
world.update(deltaTime);
if if(world.gameOver) {
if (Settings. soundEnabled )
Assets. bitten .play(1);
state = GameState. GameOver ;
}
if if(oldScore != world.score) {
oldScore = world.score;
score = "" + oldScore;
if (Settings. soundEnabled )
Assets. eat .play(1);
}
}
The updateRunning() method first checks whether the pause button in the top-left corner of the
screen was pressed. If that's the case, it sets the state to paused. It then checks whether one
of the controller buttons at the bottom of the screen was pressed. Note that we don't check for
touch-up events here, but for touch-down events. If either of the buttons was pressed, we tell
the Snake instance of the World to turn left or right. That's right, the updateRunning() method
contains the controller code of our MVC schema! After all the touch events have been checked,
we tell the world to update itself with the given delta time. If the World signals that the game is
over, we change the state accordingly and also play the bitten.ogg sound. Next, we check if the
old score we have cached is different from the score that the World stores. If it is, then we know
two things: Mr. Nom has eaten a stain, and the score string must be changed. In that case, we
play the eat.ogg sound. And that's all there is to the running state update.
private void updatePaused(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 > 80 && event.x <= 240) {
if (event.y > 100 && event.y <= 148) {
if (Settings. soundEnabled )
Assets. click .play(1);
state = GameState. Running ;
return ;
}
if (event.y > 148 && event.y < 196) {
if (Settings. soundEnabled )
Assets. click .play(1);
game.setScreen( new MainMenuScreen(game));
return ;
}
}
}
}
}
The updatePaused() method just checks whether one of the menu options was touched and
changes the state accordingly.
 
Search WWH ::




Custom Search