Spawning monsters

A place for people with an interest in developing new shmups.
Post Reply
marth617
Posts: 4
Joined: Sat Jan 04, 2014 12:23 am

Spawning monsters

Post by marth617 »

Hello All,

I am trying to create my first game for the iOS platform and I am thinking of making a SHMUP type game. I am getting to the point of spawning monsters. The issue that I am having is the code is getting very lengthy when it comes to spawning every single monster.. I don't know if anyone has any other type of method for spawning multiple enemies using fewer lines of code? Any help would be amazing!

Thank you
User avatar
Dave_K.
Posts: 4570
Joined: Wed Jan 26, 2005 5:43 am
Location: SF Bay Area
Contact:

Re: Spawning monsters

Post by Dave_K. »

Hi Marth, welcome to the shmups forum.

Monsters you say? This sounds like an interesting shmup. To your question, I believe most folks here keep some kind of list of enemy (monster) spawn locations and actions in a list or array, and loop through that list spawning enemies based on the game's frame number/timestamp. Does that help?
marth617
Posts: 4
Joined: Sat Jan 04, 2014 12:23 am

Re: Spawning monsters

Post by marth617 »

Yeah enemies sorry used the wrong term there, but what I've been doing to spawn enemies for example is below:

_monsters = [[Monsters alloc] initWithMonsterType:MonsterTypeFlury];
_monsters.position = CGPointMake(self.size.width + _monsters.size.width/2, self.size.height-45);
[_fgLayer addChild:_monsters];

This would spawn this type of enemy and then place on the right hand side of the screen and a little lowering then the top right of the y-axis. Then I could call what kind of action I want this enemy to do. But the issue that I am having is when I need to spawn multiple of them using this block of code gets very lengthy. Another example I have with an array is below:

#define Num_Monsters 5;
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];
}

This would cast 5 of the same Monster types in the same exact order over each other which is not useful at all. I read that alot of people use XML files to spawn enemies(monsters), but I am not sure where to start for that...

Thank you
User avatar
Dave_K.
Posts: 4570
Joined: Wed Jan 26, 2005 5:43 am
Location: SF Bay Area
Contact:

Re: Spawning monsters

Post by Dave_K. »

Jumping into an XML scene description/parser may be a little too complex at this point for your first shump. Why not simply store your level events in an array or list, and then iterate over that list based on the game clock to know when to spawn the enemy and at what location.

Here is a similar thread where this question was asked.
marth617
Posts: 4
Joined: Sat Jan 04, 2014 12:23 am

Re: Spawning monsters

Post by marth617 »

Yeah I will try to make a plist file to store the enemies and there spawn times and locations in their. Just very new to programming so getting everything down pact is very overwhelming at first lol. But the only way to get better is keep asking questions and keep at it! Thanks!
User avatar
Ghost Crab Games
Posts: 8
Joined: Sat Jan 11, 2014 4:51 am
Location: Philadelphia, PA
Contact:

Re: Spawning monsters

Post by Ghost Crab Games »

For our game the level spawns are simply saved in a flat file that's read line-by-line and then parsed. The only thing that's stored is what's to be spawned and at what time. Where it spawns and how it behaves is all taken care of in-code. For example, part of the first level of my game starts like this:

Code: Select all

2,novawasp
2,novawasp
5,slime
10,slime
10,slime
14,novawasp
14,novawasp
14,novawasp
20,slime
22,slime
23,buzz
26,novawasp
26,novawasp
28,buzz
28,buzz
30,novawasp
30,novawasp
30,novawasp
30,medipus
32,slime
Powerups are handled in a similar fashion:

Code: Select all

25,0,missile|plasma
50,0,spread
The pipe character there between missile and plasma denotes that it's random which spawns. The zeros denote the container type in case the powerup needs to be shot open before the player can get to what's inside.

We went this method so that our designer can change and balance levels without ever having to touch code and it's proven to be pretty effective and easy to manage and it's certainly easily human readable. Hope this helps and gives you some ideas!
Developer of vehicle-based twin-stick shmup Drive to Hell! Check us out and vote on Steam Greenlight!
Post Reply