Game Development Reference
In-Depth Information
this function checks whether the touch is on the left or the right part of the screen.
A touch event on the left part of the screen is saved into m_MoveTouch , because
it's a touch that's trying to control ship movement. A touch on the right part of the
screen is instead saved into m_FireTouch .
We save these off because the same touch object will be used as the player moves
his finger across the screen. Every time an active touch has its position changed,
the ccMoveTouch function gets called. Notice how the code in this function
checks to see if the touch that moved is the one that controls the ship move-
ment—if the position of m_MoveTouch changes, that should modify the target
position of the ship, as well. All other touches are ignored because we don't care
about the positional change of any touch that's not the one tied to player move-
ment.
0nce the player lifts his finger and the touch is no longer active, ccTouchEnded
is called. In the case of ObjectLayer , all that it does is check to see whether
it was the m_MoveTouch or m_FireTouch that ended and clear out that touch
object reference, as appropriate.
Finally, there are functions in ObjectLayer whose purpose is to track the state
of the game. These include functions that grant the player points for killing en-
emies as well as keeping track of the number of lives the player has. If the player's
life total hits zero, the game ends and a “game over” menu is displayed.
Exercises
Now that you've taken a look at the code, here are a couple features that could be
added to this game:
1. More Enemy Types
Having only two types of enemies makes the game fairly repetitive. The
simplest way to add more enemy types would be to add an additional
route function to the Enemy class. Then this route could be activated
based on a variety of conditions. You could add more enemy images by
dropping the files into Resources/sprites and then loading the space.tps
file into TexturePacker. From TexturePacker, you can then click “publish”
to generate new sprite sheets.
2. Have Structured Waves
If you play a classic wave-based shoot-'em-up game such as 1942 , you
will notice set wave patterns where different types of enemies approach at
Search WWH ::




Custom Search