Java Reference
In-Depth Information
original location is somewhere below the bottom of the screen. Since we will be moving bonusBalloon
around the screen and we want to know if the Node flyingNode intercepts it, it makes sense to normalize
both the coordinates of the bonusBalloon and the flyingClown Nodes .
Main.offsetFromZero from Listing 11-1 performs this function by wrapping each Node in a new Group
and adjusting the translateX and translateY values of the Group and the Node so that the Node stays in
the same visual location on the screen. But the returned Group's translateX and translateY values
reflect its position relative to the upper left of the screen.
The function initScreen is called by the init function of the class GameModel . If we look at the
function startGame from Listing 11-1, we see that the GameModel is constructed before the transition
FlipReplace is called. Recall from Chapter 3 that each transition allows the caller to specify a function
that should be called when the transition is complete. When the FlipReplace is done it calls the function
GameModel.startingAnimationOver , which actually gets the GameModel ready to start playing the game.
Figure 11-8 shows how the game state is managed by the class GameModel .
In Figure 11-9 we see that the function startingAnimationOver gets the ball rolling by calling
startRound after the instructions fade out. The function startRound readies the game by resetting the
angle of the cannon, setting the number of clowns to five, and randomly distributing the pegs.
Figure 11-9. Game state
In Listing 11-3 we can see that the function startRound adds a Body to a World object. Both Body and
World are classes from Phys2d and are used to do our physics simulation. Chapter 6 describes how this
works. But be reminded that by adding Bodies to a World you can then use the World object to calculate
the location of the clown and the pegs as the game plays out. We can see that the function startRound
calls readyLaunch , which resets the location of the Node balloonNode , resets the location of the Node
 
Search WWH ::




Custom Search