Development Blog (semi)random.thoughts()

Core Engine

Let’s talk about what makes the main game loop work. As a refresher: the main game loop is move forward, dodge projectiles, shoot incoming starships, watch explosion, rinse/repeat.

As a basis, I use the setup as illustrated in the Cooking With Unity 2D Shoot-em-up series
Let’s talk about what makes the main game loop work. As a refresher: the main game loop is move forward, dodge projectiles, shoot incoming starships, watch explosion, rinse/repeat.

As a basis, I use the setup as illustrated in the Cooking With Unity 2D Shoot-em-up series

The idea is this. We have GameObjects in the scene that contain a “SpawnEnemyWave” script. The main purpose of this script is spawn a wave of enemies, once enabled. The scrips start out disabled.

inspector_spawner

The SpawnEnemyWave script takes the direction its facing into account when spawning enemies. This adds some variation in the directions enemy waves are moving.

So how do we enable the script?

For this we use the Playfield. This object contains the player ship, background effects and some other assorted objects.

hierarchy_playfield_player

The Playfield also has a Collider and Trigger and a script that ActivateScriptsOnTriggerEnter. This enables the SpawnEnemyWave script once the Playfield (and thus Player) come close enough.

sceneview_playarea_collider
inspector_playfield

When you spam a scene with Enemy Spawners, you have a level!

sceneview_spawners

Of course there are many more ways of doing this. I settled for this option because it seemed simple in the aforementioned tutorials. But there is no reason why spawning could not have been triggered from within the SpawnEnemyWave script itself for instance.

Stay tuned for next time, when we talk about enemy AI (yeah, these ships are really smart).

We value your privacy. This site collects only information required to provide you this Service. For more information, read our privacy policy.