Game Development Reference
In-Depth Information
What just happened?
So in
resetGame
we set the timers, and we update them in the
update
method. We use
these timers to add meteors and health packs to the screen by grabbing the next available
one from their respective pool, and then we proceed to run collisions between an exploding
bomb and these falling objects.
Notice that in both
resetMeteor
and
resetHealth
we don't add new sprites if too
many are on screen already:
if (_fallingObjects->size() > 30) return;
This way the game does not get ridiculously hard, and we never run out of unused objects
in our pools.
And the very last bit of logic in our game is our
fallingObjectDone
callback, called
when either a meteor or a health pack has reached the ground, at which point it awards or
punishes the player for letting sprites through.
When you take a look at that method inside
GameLayer.cpp
, you will notice how we
use
->getTag()
to quickly ascertain which type of sprite we are dealing with (the one
calling the method):
if (pSender->getTag() == kSpriteMeteor) {
If it's a meteor, we decrease energy from the player, play a sound effect, and run the explo-
sion animation; an autorelease copy of the
_groundHit
action we retained earlier, so we
don't need to repeat all that logic every time we need to run this action.
If the item is a health pack, we increase the energy or give the player some points, play a
nice sound effect, and hide the sprite.