Game Development Reference
In-Depth Information
The runSpiderMoveSequence method keeps track of the number of dropped
spiders. Every eighth spider, the spiderMoveDuration decreases, and thus any
spider's speed increases. In case you're wondering about the % operator, it's called the
modulo operator. The result is the remainder of the division operation, meaning that if
numSpidersMoved is divisible by 8, the result of the modulo operation will be 0.
The action sequence consists only of a CCMoveTo action and a CCCallBlock ac-
tion. You could improve it to let spiders drop down a bit, wait, and then drop all the
way, as evil six-legged man-spiders would normally do. I leave this improvement to
you, and you can find an example implementation in the final DoodleDrop project.
For now it's only important to know that I chose to reset the spider's position in a block
function passed to the CCCallBlock action. The block function can simply use the
same spider variable passed to the runSpiderMoveSequence method. The
block is called after the spider's movement is done, meaning it dropped past the player
character. Thanks to the block you don't have to jump through hoops to find the right
spider. The spider's position is then reset to just above the top of the screen. Listing
4-12 shows the same block from Listing 4-11 again, in isolation.
Listing 4-12 . Resetting the Spider Position So It Can Fall Back Down Again is done in
a CCCallBlock block
CCCallBlock* callDidDrop = [CCCallBlock actionWithBlock:^void(){
// move the droppedSpider back up outside the top of the screen
CGPoint pos = spider.position;
CGSize screenSize = [CCDirector sharedDirector].winSize;
pos.y = screenSize.height + spider.texture.contentSize.height;
spider.position = pos;
So far, so good. You may want to build and run the game now and play it a little. I
think you'll quickly notice what's still missing. Hint: read the next headline.
Collision Detection
You may be surprised to see that collision detection can be as simple as Listing 4-13 .
Admittedly, this only checks the distance between the player and all spiders, which
Search Nedrilad ::

Custom Search