Game Development Reference
In-Depth Information
Testing out the game
Just to recap, we created four new functions: newLevel() , mouseMoveListener , shootListener ,
and placeShips() . If you compile and run the game right now, you will see something similar to
Figure 5-3. If you click the mouse button, you will hear the sound of the shots firing, but no shots
will fly because we have not coded that part of the game yet. You can also move the crosshairs
with the mouse. When you are done, move onto the next section, so we can create a new level
and finish the game.
Figure 5-3. The crosshairs on the playfield while testing
Creating the game loop
Finally, it is time talk about the game itself. Like newGame() and newLevel() , runGame() is called by
Main as part of the game framework's optimized game loop. The beauty of the game framework
is that we do not have to worry about how or when runGame() gets called. We only need to know
what do when it is called. We will discuss each of the function calls listed in the code for
runGame() in detail. First, let's take a look at how the function is constructed.
override public function runGame():void {
checkEnemies();
checkBonusPlane();
update();
checkCollisions();
render();
checkforEndLevel();
checkforEndGame();
}
Pretty simple, huh? Well, it's simple because all it does is call a bunch of functions we still need to
define, but it was easy to write anyway. In the next sections, we will describe all of these functions
and how they work together to create the Flak Cannon game.
Search WWH ::




Custom Search