The last thing we need to finish this beat 'em up game is to implement a way to know whether the game is over or whether the stage has been cleared of enemies. It's pretty simple: add the following lines at the beginning of the update
method:
// Check game over or stage cleared if (_zombie.lifePoints <= 0){ [self gameOverWithSuccess:FALSE]; } else if (_arrayOfHumans.count == 0) { [self gameOverWithSuccess:TRUE]; }
These lines check whether the zombie has been killed (life points are equal or less than zero) or whether the stage has been cleared (the number of humans is zero). Both cases call a new method with a different input value. Let's implement this method to know what it does:
-(void) gameOverWithSuccess:(BOOL)success{ // Initializing the label CCLabelTTF *label; // Stop interaction and running actions self.paused = TRUE; _gamePad.userInteractionEnabled = FALSE; if (!success) { // Create the game over label ...