Core Engine
01-08-2016 Filed in: Zen BWV
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
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.
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.
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.
When you spam a scene with Enemy Spawners, you have a level!
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).
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.
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.
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.
When you spam a scene with Enemy Spawners, you have a level!
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).