• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
marth617

Assistance on spawning enemies for a SHMUP game

5 posts in this topic

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!

0

Share this post


Link to post
Share on other sites

Well, there a lot of ways to slice this problem. You maintain a list of monsters that are "waiting to be spawned", which would contain the parameters necessary to spawn a monster as well as a time delay for when that monster should spawn. Every frame you can decrement the timer on each item of the list, and if the timer is less than zero you spawn a monster with the parameters specified.

 

Or you could just spawn all five monsters at once, like you're currently doing, but put the monsters that you want to spawn later further back in the world so they don't show up at the same time, even though they were spawned at the same time.

 

Or you could just simply spawn the monsters at different times. If you want to spawn five monsters at separate times, you could spawn the first monster, then wait until a second has passed before spawning the second, etc. This is similar to the first solution.

 

My suggestions are kind of vague, but I think you are probably able to fill in most of the details on your own.

1

Share this post


Link to post
Share on other sites
It could make your life easier to have a single class that interprets a list of events for generating enemies, instead of you having to hard code the events yourself.
This event list could be a plain text file, with each level having a different one.
Then you parse each event described in the file and store them in an array, sorted by spawning distance so they're easier to use when in-game.
 
// Enemy spawn script file example.
//
//
// (Enemy Class), (Behavior), (Spawn Distance)

scout, scout_01, 500
scout, scout_01, 510
scout, scout_01, 520
scout, scout_01, 530
scout, scout_01, 540
scout, scout_01, 550 // A series of equally-behavioured enemies a few steps apart, so that they look like an organized line.

cthulhu, cthulhu_01, 700
scout, scout_02, 800
scout, scout_03, 800
interceptor, interceptor_01, 900

...
Similar to how a soft subtitle file works.

- Instead of time-based spawning you can use the "distance travelled" in the level as the reference for spawning the enemies, as it's a simpler logic: An enemy only appears when you've reached a certain point in the level, and this is unrelated to time or framerate.

- The "behaviour" parameter is the choreography that the enemy will perform. It is another script file that defines a catmull-rom spline or similar that describes the path that the enemy will travel, including events such as firing, dropping bombs, how it enters and leaves the screen (position and orientation) etc.
If you design your paths on an abstract 16:9 screen, you can normalize the coordinates and it should work with any screen resolution that you would use with this ratio.

- You can use that script for more than just enemies, like powerups, messages and other types of event. Edited by Kryzon
1

Share this post


Link to post
Share on other sites

Yeah currently I do have the monsters spawn over a time period, just a lot of the spawning code gets very redundant. I will have to learn and look into making a script (maybe a plist file) for my monsters on when to spawn and maybe use some sort of behavior on each spawn as well. Kyzon thank you for the example as well I will try to put something together similar. 

0

Share this post


Link to post
Share on other sites

It seems the issue is simply you're not reusing your code, but rather writing the same lines over and over.  Use functions.  Maybe you need to do some more reading in your language of choice and get a better understanding of it.

 

I don't know what language you are using, but in pseudo code it would be kind of like this:

 

while the game is running:
  loop through the monsterList:
    if monsterList[i] release time is at or past current time:
      SpawnMonster([[Monsters alloc] initWithMonsterType:MonsterTypeFlury], monsterList[i].positionX, monsterList[i].positionY)
 
# SpawnMonster takes a monster and a location to be spawned
SpawnMonster(monster, x, y):
  monster.position = CGPointMake(x, y);
  [monster straightLine];
  [_fgLayer addChild:monster];
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0