How are enemies handled in a top down scrolling shooter?

Hi all,

Working on a top down, shooter. (think skyshark, 19xx) My question is how are off screen enemies handled? I have a scrolling background. I got this idea from the simple 2D shooter tutorials. In the video, they just had enemies on screen with the player.

Should I create a bounding box around that player that is slowly moving forward? If I do it this way, my theory is the enemies can be stationary, and activate when the player is close by.

I am also thinking of attaching triggers to the scrolling background. The triggers would force the player to collide with them, when he does, it will spawn enemies.

Not sure how this is usually handled in a scrolling progression games. Can anyone enlighten me? Thanks in advance.

If they background scrolls at a constant pace, which is normal, you can just spawn them on a timer.

I would create a 2D grid of the game world. Each cell in the grid determines the type of enemy (if any) that’s located there. You then scan a row of cells that are just off the edge of the screen and spawn any enemy that’s present into your game world as the player approaches.

This method is super fast as it means your code will only need to scan something like 16 cells every update.

But you’ll also need to remove any enemy that have gone past the player and off screen without being killed. But that can be handled by a simple timer. You shouldn’t even need to check if they’re visible because if they’re moving then you can assume after a 30 seconds or so that they’re probably off screen and no longer visible.

Mapping things like this is easier to get your head around and gives you a sense that the enemy do exist in the world at a specific location. Whereas using timers and similar methods can become confusing and difficult to manage/debug. Also, using timers makes it difficult to synchronize the enemy with the background. For example you might want some enemy objects to come from out of base or from some trees etc.

Unified, that’s a great idea, should the player still be unable to move vertically through the scene? In other words should all forward movement be handled via the scrolling background?

That is pretty smart for the enemies to come out of a hangar or something. Also for stuff bound to the ground, I never really thought about it.

That’s entirely down to you to decide, as there’s no technical limitation with the method I proposed that would prevent you from letting the player move their ship around the screen. It’s the camera’s position that should ultimately determine which cells in the enemy grid you scan, and not the player’s position.

Thanks for the insight guys. I can’t wait until I have something to share.