Game Development Reference
In-Depth Information
// Create the game logic components
[self addChild:[StandardMoveComponent node]];
StandardShootComponent* shootComponent = [StandardShootComponent node];
shootComponent.shootFrequency = shootFrequency;
shootComponent.bulletFrameName = bulletFrameName;
[self addChild:shootComponent];
if (type == EnemyTypeBoss)
{
HealthbarComponent* healthbar = [HealthbarComponent •
spriteWithSpriteFrameName:@"healthbar.png"];
[self addChild:healthbar];
}
In addition, the spawn method has been extended to include resetting the hit points to
their initial values and calling the reset method of any possible HealthbarCom-
ponent added to the enemy. I omitted the explicit check if the enemy is a boss type
here simply because the HealthbarComponent is universal and could be used by
any type of enemy.
-(void) spawn
{
// Select a spawn location just outside the right side of the screen
CGSize screenSize = [CCDirector sharedDirector].winSize;
CGSize spriteSize = self.contentSize;
float xPos = screenSize.width + spriteSize.width * 0.5f;
float yPos = CCRANDOM_0_1() * (screenSize.height - spriteSize.height) + ←
spriteSize.height * 0.5f;
self.position = CGPointMake(xPos, yPos);
// reset health
hitPoints = initialHitPoints;
// Finally set yourself to be visible, this also f lag the enemy as "in use"
self.visible = YES;
// reset certain components
Search Nedrilad ::




Custom Search