Hello All,
I am working on my very first game for the iOS platform. Trying to make a SHMUP style game where I am getting to the point on spawning enemies(monsters) to shoot at. The issue that I am having is that the code on spawning every single enemy is getting very lengthy. As the code gets very redundant and repetitive. As in alot of SHMUP games you have multiple of the same type of enemies following each other in a pattern around the screen. For an example this is the code I use to spawn and move a enemy below:
_monsters = [[Monsters alloc] initWithMonsterType:MonsterTypeFlury];
_monsters.position = CGPointMake(self.size.width + _monsters.size.width/2, self.size.height-45);
[_monsters straightLine];
[_fgLayer addChild:_monsters];
This will spawn a enemy and move it in a straight line from the right side of the screen to the left. Now if I wanted another enemy to come out and follow him I would right that same code again but tell it to wait an additional second or two. I tried using an array format listed below:
#define Num_Monsters 5;
NSMutableArray *monsters = [NSMutableArray arrayWithCapacity:Num_Monsters];
for (int i = 0; i < Num_Monsters; ++i) {
_monsters = [[Monsters alloc]initWithMonsterType:MonsterTypeFlury];
_monsters.position = CGPointMake(self.size.width + _monsters.size.width/2, self.size.height-45);
[_monsters straightLine];
[monsters addObject:_monsters];
[_fgLayer addChild:_monsters];
}
But this would spawn the same monster type 5 times at the same exact time so there kinda piled on top of each other... Any help would be great where I don't want to write 4-5 lines of block code for every single enemy that needs to spawn.
Thank you!