5.5. Mobile Game: UFO Zapper
The concluding example of this chapter is a game. In contrast to the Hangman server that was presented in Section 4.5, this is a classic single-player action game with stunning graphics – just see Figure 5.9. Your job is to save the world from a squadron of invading UFOs with a moving pad that shoots laser beams (ahem).
Figure 5-9. UFO Zapper
You must shoot down as many UFOs as possible within a given time limit. You get points for each hit: the smaller the UFO you hit the more points you get. Try to beat our highest score of 2304 points!
5.5.1. Structure of a Game Application
The example presents several useful concepts that are often used in game applications:
an event loop to control the application
dynamic time
double buffering
module random.
Using an event loop to control an application
At the beginning of Chapter 4, we noted that we have to use the e32.Ao_lock object to stop the execution and start waiting for the user input. However, in an action game something should be happening all the time, even if the user does nothing. Thus, instead of a lock, the game application is controlled by an event loop.
An event loop is typically a simple while loop which takes care of advancing time step by step. Like Ao_lock, the loop prevents the application from exiting instantly.
Whereas an animation proceeds from start to end without any user interaction, ...
Get Mobile Python: Rapid Prototyping of Applications on the Mobile Platform now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.