Devlog #10

Attacking Enemies

Posted October 20, 2023

Firing The Weapon

With the weapon sprite looking in the correct direction, it now needs to fire a projectile in that direction. Remembering that I had a working bullet scene from my original game idea, I could repurpose it for this.

I created a new function that would be called once the sprite looks towards an enemy. In this function, an instance of the bullet would be created and propelled in whatever direction it was facing. I did have to tinker with the bullet's movement, as the original scene only accounts for the y-axis. Eventually, I was able to get the following working:

The bullet sprite wasn't facing the correct direction so I rotated it 90 degrees. I also fixed the number of hframes the bullet sprite had, since I only wanted one arrow. Each hframe is a column in the sprite sheet. Instead of showing the entire spritesheet, this way I'm able to use whatever part I need.

After I fixed that, I noticed when there were several enemies to fire at, the bullet wasn't behaving properly. Visually it seemed to be spawning other bullets out of already fired bullets. I believe this bug was occurring due to how the bullet was being instantiated. Instead of the instance being a child in the main scene, it was a child of itself. Thankfully I was able to find a guide to shooting projectiles on KidsCanCode.org.

With this guide, I was able to add a child to the root of the scene tree, instead of the current scene. Thankfully, this fixed the bug.


Enemy #2

During the time I spent implementing weapon shooting, I also attempted to add a second enemy to the spawn pool. This proved to be tricky since the spawning system only accommodated for a single enemy type. To my surprise, I was able to "add" another enemy type, but that started to cause some issues.

Enemy #1
Forest
Enemy #2


The second enemy uses the same spawn system and can damage the tower, but that's all it can do. In comparison, upon being killed enemy #1 emits a signal. This signal is responsible for incrementing a variable that keeps track of enemies killed in a wave. That data is then being used to determine when to spawn the next wave.

With an an additional enemy spawning, the amount of expected enemies killed in a wave will double. This would break the spawning system completely. To prevent the system from breaking, enemy #2 does not emit any signals.

Soon I'll have to implement a better solution, maybe research inheritance and make a base enemy class. Or revamp the spawning system altogether.

Next Devlog: #10.5 ›