We have seen where we set game over conditions, so let's look at the actual game over method. It's pretty basic, but it serves its purpose.
Filename: TDPlayfieldLayer.m
-(void) gameOver { [self unscheduleUpdate]; NSString *msg = @"You win!"; if (heroHealth <= 0) { msg = @"You died."; } [hudLayer showGameOver:msg]; CCDelayTime *delay = [CCDelayTime actionWithDuration:3.0]; CCCallBlock *allowExit = [CCCallBlock actionWithBlock:^{ preventTouches = NO; }]; [self runAction:[CCSequence actions: delay, allowExit, nil]]; }
The first thing we do at game over is to unschedule the update so the enemies stop moving. As you may recall, when we have been setting the isGameOver
variable, we have also been setting preventTouches
to YES
. That flag will stop any input from being accepted (as we saw in the update
method of the
TDControlLayer
class), so here we just need to stop everything...