Game Development Reference
In-Depth Information
All the update function does in Ship is move the ship vertically toward the tar-
get point, which is the point where the left thumb of the player is. As the player
moves his thumb, the target point changes, which in turn causes the ship to move
toward the target point. The movement to the thumb is not instant so as to prevent
teleporting. But at the same time it's fast enough that the player should feel that
the controls are responsive.
Projectiles
The Projectile class inherits from CCSprite and is the base class used for
both the ship's lasers as well as the enemy's projectiles. The update function for
Projectile is extremely simple. First, it updates the position of the projectile
using Euler integration (which was discussed in Chapter 7 , “ Physics ). Then, it
checks to see whether or not the projectile has moved outside the bounds of the
screen. Once a projectile moves outside the bounds, its despawn function is
called.
Two classes inherit from Projectile : The first is Laser (which is the ship's
laser) and the second is EnemyProj (which is an enemy projectile). These in-
herited classes only have to do two things: set the correct sprite and overload the
despawn function that removes the particular projectile from the ObjectLay-
er .
Enemy
The Enemy class is the most complex of the object classes. Right now, the enemy
supports two different types of behaviors: a figure-eight path (which is performed
by the larger, yellow flying saucers) and a “post” route (which the regular blue en-
emies use). The two functions that set up these paths are setupFigure8Route
and setupPostRoute .
Notethatforbothroutes,Iutilizeactionstosetuptheentirepath.Whenan Enemy
is spawned by ObjectLayer , it sets up the correct route for the enemy and then
the actions will dictate what it does. In the case of the post route, the enemies will
move toward the middle of the screen and then exit from either the top or the bot-
tom. In the case of the figure eight, the enemy will endlessly perform the figure
eight until it's finally defeated.
The firing patterns of the two types of enemies are also different. The post route
enemy will only fire once in the negative x-direction, whereas the figure-eight en-
emy will fire a projectile at the position of the player. This behavior is contained in
Search WWH ::




Custom Search