Behind the Scenes
On paper, it doesn’t look like I accomplished anything today. My checklist in the Phase II: Core Programming area, went visibly neglected, but I promise I did make some strides in that area. I will start with the morning bug report.
I had some amazing help and inspiration this morning from one of my colleagues here at GameDevHQ. I had a few small issues that were resolved, one of them potentially game breaking later on, so it feels good to have those items now properly addressed and functional. I was told the other day that red stop sign looking errors can devastate a build later on, and so they need to be sorted out now. I had an issue where if the player only had 1 life left, and took 2 damage from an enemy laser, my life counter would error at -1, being the image used to show player lives, didn’t know what to show for -1 life. I thought that I had addressed this issue through code adding an argument stating, “if _lives <= 0, _lives = 0. I was half right. It was pointed out to me that the aforementioned bit of code, was in my heal method, which only adds life and only gets called when I heal. Basically, it was doing nothing. My colleague, let’s just call him Ryan for now, said to me, “Where does it make sense to make this argument? What is removing lives to -1?” That made the fix painfully obvious. I moved the same code from my heal method to my damage method, and the problem was fixed! No more game breaking errors. No more negative life count. I was also encouraged to clean up my player script, and so I did. I ended up finding a few redundancies as well as places that could simply be more optimal. I now only have three methods being called (FireLaser, Thrusters and Calculate Movement), in my void update, and I feel pretty good about that. I also got some help from Ryan to troubleshoot another bug I had discovered. I could fire in all directions but one. When I press up and left simultaneously on the arrow keys, all forms of firepower for the player become disabled. I was advised to try using the default A/S/D/W keys for player movement to see if the problem persisted, and it did not. After this discovery as well as confirming that I wasn’t calling any function to these arrow keys in my codebase, we began to assume that maybe it is a Unity bug. That would be a relief being I was assuming it was a user error, with the user being me obviously. Either way, cleaning up the player code was important for troubleshooting the issue, so I am happy that is now optimized. I now also see how I can clean up my enemy code in similar fashion.
Now for the fun stuff. Looking ahead at the checklist for Phase II shows me that I will need to make a new variety of enemy types. I had the thought before I dove into making new enemy scripts for new behaviors, that maybe I could do it all on one script. When making our powerups, we utilized an array/ switch statement to handle the variety of powerup prefabs being spawned in, and I was hoping for a similar implementation for randomly spawning enemy types. The main difference that was getting to me was that the powerups spawn completely different object with different logic. I wanted to use the same enemy ship, only with a different behavior. Really, I was overthinking it. That didn’t however stop my heart from pounding nor my adrenaline from pumping as I was making what could be code breaking changes. Even though I was taking safety measures like commenting out the code that I know works, rather than deleting it, I still had to tell myself to calm my nerves as I got closer to trying it all out. In the end, it worked! I have an array consisting of one enemy. On the surface, nothing about my game has changed, but behind the curtains, things are looking tidy and clean, efficient and ready for more functions. My goal now is to start adding a variety of enemy types to my array and assigning them new behaviors. I can do this all in one enemy script, and I feel confident that I only need to adjust behavior, and the random spawning will be easily updated in the switch statement function. I hope this enables me to move quickly thought the new enemy types that I need to create, knowing that the spawning and collisions are taken care of. I just need to focus on the new logic.