Enemy Waves — first attempt

KT
2 min readDec 17, 2020

Today I did a lot of white boarding on the tasks for Phase II. Here is the basic logic for the next 3 tasks:

Aggressive Enemies

Once this type of enemy comes within a certain close distance to the player, this enemy attempts to “ram” the player.

Pseudo code:

  • if distance between enemy and player is x
  • move towards player

Powerup Enemies

If a powerup is in front of one of these enemies, this enemy will shoot and destroy the powerup.

Pseudo code:

  • if powerup is in front of enemy (same x value)
  • shoot to destroy powerup

Enemy Wave System

Spawn enemies in waves, with each wave spawning more enemies than the prior.

Pseudo code:

  • initiate spawning after asteroid is hit
  • display wave count across screen via UI
  • spawn x number of enemies
  • pause spawning
  • display wave count across screen via UI
  • unpause spawning
  • spawn x++ number of enemies
  • pause spawning
  • display wave count across screen…
  • etc. (LOOP)

After getting this all out of my head and down on paper, I felt organized enough to start tackling the wave spawning system. I started by adding a wave manager to the Hierarchy and attached a wave manager script. I determined the most efficient way to accomplish this task would be to loop through the same loop while resetting the number of enemies spawned as well as incrementing the threshold of number of enemies spawned to advance to the next wave. I’d also need to “announce” the upcoming wave of enemies via the UI (almost to act like different levels and give the player a sense of advancement).

I then had to modify my Asteroid code. Instead of telling the spawning manager to start spawning immediately after the asteroid is hit with a laser, I call a method on my new wave manager script to initialize spawning. I also had to add a spawned-enemy counter to my enemy script in order to keep track of how many enemies are spawned. Once this count reaches a certain threshold, the player advances to the next wave of enemies.

Check out what I have so far. As you can see, there are TONS of enemies and TONS of powerups leading me to believe that I’m not stopping and restarting spawning correctly. At first glance it seems that there may be multiple instances of the same spawning script running at the same time. Stay tuned for the actual diagnosis and solution!

Way too many enemies and powerups for this to be running correctly!

--

--