Most efficient way of coding 2d space shooter levels

I struggled with the title for this post but I didnt really need to ask “how to” code enemies for a 2d space shooter because I could in theory… instantiate prefabs all day long and apply ‘types’ of enemy logic to them. But my question in detail is this:

What would you consider the most efficient way of making structured levels for a space shooter… with enemy groups/types with unique movement patterns. So say after the first 10 meters traveled you get 3 of the same enemy on the screen from the right… but two of them move in a wave pattern… while 1 continues straight… and then a group of 6 enemies appear but they follow a circular path while other enemies pass with different movements.

Its not so much HOW to produce these movements… its where/how should i store this information and apply it, and what would be the best way of saying “after 10 meters do this” or would it best to set up colliders that check how far ive progressed. That sort of thing… had anybody had experience in designing this type of game that could help?

Thanks in advance for any answers :slight_smile:

Not sure it’s the best way, but hear is how I did it on one of my games.

I created a Wave object. Each wave contained a start time, a enemy type, number of enemies, and some information about the enemy movement pattern.

Then I simply exposed a list of waves in on a GameObject in the inspector. I dragged and dropped in a bunch of prefabs, added their times and patterns and job done.

At runtime I’d regularly check the list to see if the next wave should spawn.

It’s pretty crude. But effective.

1 Like

That sounds good! So you serialize the Wave class so you can add all that stuff in the inspector? As far as the enemy movement goes I wonder what the best way of implementing a fully customisable engine for it… so maybe you want enemies to come in one after another and travel diagonally across the screen then follow a pattern and leave on the left. This kind of thing couldnt be done useing just natural physics so each kind of movement would have to have a script if some sort… or take a list of parameters that gets converted into movement data.

It makes me wonder what methods the old school games used as far back as the NES, it sounds quite complicated but back then… half the consoles library were space shooters so there must of been a common practice!?

Your on to it with serialisation.

With the paths you could take several approaches. You could give each enemy type its own path, stored on the prefab.

Or you could provide a List as part of the wave and just send the enemies through each point in turn.

Wow when you say it like that it seems so obvious :stuck_out_tongue: I guess I could make a dictionary style class of <float, Vector3>, this way I could use the float to say how long to travel between each Vector3. Thank you for your help I should of figured that out really it makes a lot of sense :slight_smile:

I made a tool based on Behaviour Tree, which can be appropriately used to define your waves rather easily.
Let’s say you have a method used to spawn enemies at a given 2D locations and you want to spawn enemies coming from the left and the right at the same time: two enemies from the right on three on the left at 2 second interval. You would write a BT script like the following:

tree "Root"
    parallel
        sequence // spawn from right
            SpawnEnemy(1.0, 0.0)
            Wait(2.0)
            SpawnEnemy(1.0, 0.0)
            Wait(2.0)
        sequence // spawn from left
            SpawnEnemy(-1, 0.0)
            Wait(2.0)
            SpawnEnemy(-1, 0.0)
            Wait(2.0)
            SpawnEnemy(-1, 0.0)
            Wait(2.0)

You can have more information here: http://www.pandabehaviour.com.
If that’s look interesting to you, I’d be glad to answer your questions.

Hi @Zephni ,

Did you have chance to have a look at this tool?