The idea of power-ups is core to the modern brick breaking experience. For our game, we will be implementing three types of power-ups: paddle expanding, paddle contracting, and multiball. As we just saw, when a brick is destroyed another method gets called to handle the power-ups.
-(void) checkForRandomPowerupFromPosition:(CGPoint)brickPos { NSInteger rnd = arc4random() % 100; if (rnd < 25) { // 25 % CHANCE [self buildPowerupAtPosition:brickPos]; } }
In this method we randomize a number. If it is below 25 percent, we call another method to actually build a power-up. It is important to point out that in the spriteDestroy
method, we must call this method before we removeFromParentAndCleanup
because we will need to use the position of the brick that is being destroyed here. This allows the power-up to drop from "inside" the brick that was just destroyed.
As we follow this code path, we now reach the point...