Game Development Reference
In-Depth Information
-(void) gotHit
{
hitPoints--;
if (hitPoints < = 0)
{
self.visible = NO;
}
}
Consider it an exercise for you to implement the player's ship being hit by enemy bul-
lets. You'll have to schedule an update method in Ship and then implement the
checkForBulletCollisions method and call it from the update method.
You'll have to change the call to isPlayerBulletCollidingWithRect to
isEnemyBulletCollidingWithRect and decide how you want to react to be-
ing hit by a bullet—for example, by playing a sound effect and maybe displaying a
“game over” message.
A Healthbar for the Boss
The boss monster isn't an easy, one-hit kill. It should give the player visual feedback
about its health by displaying a healthbar that decreases with each hit. The first step to-
ward a healthbar is utilizing the hitPoints member variable of the Enemy class,
which tells you how many hits the enemy can take before being destroyed. The ini-
tialHitPoints variable stores the maximum hit points, because after an enemy
gets killed you need to be able to restore the original hit points. You're going to need
both.
To display the healthbar, another component class is ideal because it provides a plug-
and-play solution and can be re-used for other enemies if needed. The header file for
the HealthbarComponent proves to be highly unspectacular:
#import < Foundation/Foundation.h>
#import "cocos2d.h"
@interface HealthbarComponent : CCSprite
{
Search Nedrilad ::




Custom Search