Game Development Reference
In-Depth Information
if if(world.gameOver) {
Settings. addScore (world.score);
Settings. save (game.getFileIO());
}
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
Finally, there's one last vital method, pause() , which gets called when the activity is paused or
the game screen is replaced by another screen. That's the perfect place to save our settings.
First, we set the state of the game to paused. If the paused() method gets called due to the
activity being paused, this will guarantee that the user will be asked to resume the game when
he or she returns to it. That's good behavior, as it would be stressful to pick up immediately from
where one left the game. Next, we check whether the game screen is in a game-over state. If
that's the case, we add the score the player achieved to the high scores (or not, depending on
its value) and save all the settings to the external storage.
And that's it. We've written a full-fledged game for Android from scratch! You can be proud of
yourself, as you've conquered all the necessary topics to create almost any game you like. From
here on, it's mostly just cosmetics.
Summary
In this chapter, we implemented a complete game on top of our framework with all the bells and
whistles (minus music). You learned why it makes sense to separate the model from the view
and the controller, and you learned that you don't need to define your game world in terms of
pixels. We could take this code and replace the rendering portions with OpenGL ES, making
Mr. Nom go 3D. We could also spice up the current renderer by adding animations to Mr. Nom,
adding in some color, adding new game mechanics, and so on. We have just scratched the
surface of the possibilities, however.
Before continuing with the topic, we suggest taking the game code and playing around with it.
Add some new game modes, power-ups, and enemies—anything you can think of.
Once you come back, in the next chapter, you'll beef up your knowledge of graphics
programming to make your games look a bit fancier, and you'll also take your first steps into the
third dimension!
 
Search WWH ::




Custom Search