Game Development Reference
In-Depth Information
The main game loop
When the race begins, the RaceTrack class is where all the action begins. It adds
the ship of the player and lays the items along the racetrack. Most importantly, the
racetrack is at the top level because it contains the game loop. As with most game
implementations, the game loop continuously does the following:
1.
Reads the user input.
2.
Processes user input.
3.
Calls update on all the objects.
4.
Handles any network events.
As we explore each class, we will see what each object does during it's update call.
For example, depending on the speed, the ship moves a certain distance, the radar
object updates its display, and so on.
The spaceship class
We will start with the spaceship class. The spaceship is what we race with in this
game. The class inherits from the Sprite class, so it can draw itself. There would be at
least one instance of this class created for the player's own ship and one for the other
player's ship that is part of the race.
Controlling movement
We will use arrow keys to control its movement. The ship may move in three
directions—forward, up, and down—by pressing the right, up, and down arrow
keys respectively. The left arrow may be used to slow down the speed of the ship,
but not move backwards. In appendix 2, we explore one way to handle arrow keys
that allows players to press more than one key at a time and not stall when the
player furiously switches between keys.
 
Search WWH ::




Custom Search