Day 15 — On to core programming

Benjamin Lihn
3 min readDec 9, 2020

--

Tomorrow, I’ll actually move on to the core programming section. Because this morning, I noticed that I had to implement one more feature to complete the framework matrix with enough points. So I dove into implementing a secondary fire powerup. It needed to replace standard fire for five seconds and spawn its powerup rarely.

I decided on a “clearing” horizontal laser powerup. When the player collects the powerup, it gets a single shot (on the next fire) of the special variety. The clearing laser spans the width of the game screen, and traverses vertically, eliminating all enemies in its path. Also, during its required cooldown of five seconds, the player cannot fire regular lasers. However, the special clearing laser reappears at the bottom of the screen and travels vertically (repeatedly) until the five seconds are up. Here’s a clip of the code:

By utilizing the tag feature in Unity, I indicated that this prefab would be “ClearingLaser.” This allowed me to have this prefab behave differently than the typical player laser, which is also acted upon by the laser script and MoveLaserUp method above. This solution was much easier to implement and felt less burdensome than creating another script for this simple action.

I had to get creative for a quick fix on disabling the player from firing regular lasers during the clearing lasers five second life. I made this work by utilizing the coroutine referenced above. I set a (basically temporary) variable equal to the grab of the player’s ammo count, then set the player’s ammo count to zero (cannot fire), waited five seconds, then reset the player’s ammo count to it’s previous integer (the temporary variable). This is all happening while the clearing laser is circling the y axis destroying all enemies and protecting the player.

kaboom

I also rearranged the matrices of the powerups in my spawn manager script. To make the clearing laser powerup less frequent, I doubled the number of instances of each of the other powerups integers in the matrices.

My biggest challenge of the day came from a strange behavior by the prefab for the clearing laser. After being instantiated, it traveled up the y-axis as planned, but also drifted toward -x while it moved. With some help from fellow GameDevHQ intern Aaron, I diagnosed that the parent’s transform was not fading, but the child’s transform was decreasing on the x-value. This was remedied by removing the script component from the child object, and leaving it only on the parent. I wrapped up the day by debugging a few other small items that were on my list. Tomorrow — for real this time — I’ll be starting Core Programming!

--

--

Benjamin Lihn

Coding my future as a software developer; // if (attitude > 0) {progress ++;}