Monday 9 December 2013

Bullet Devil: Attack of the Elements' Enemies

I wanted to take a small break for this blog and talk about my groups game instead of lecture content. Specifically, I wanted to talk about our enemies and a lot of the cool stuff we do with them. 

We control everything our enemies to with a singleton class that has several data members. We call it the enemy manager. We also have a main array in it that is used to represent each wave of enemies. We also include the state of each enemy, whether hey are alive or not alive, the number of enemies currently in the "game world" and a timer to delay certain actions.

The main point of our enemy manager is to keep track of the enemies, spawning, despawning, and the overall management of our games' enemies. It also deals with the ammo and powerups that our enemies drop when they die.

We have a really unique way of dealing with enemies when they die in our game. Instead of deleting them we put them in a space we call "the graveyard". The graveyard is a box underneath the main game world. We didn't want to flat out delete our enemies because we were afraid it could cause memory leaks that could cause the game to crash after X amount of enemies had been killed. The main purpose of the graveyard is so we can reuse the enemies instead of constantly respawning them. We also copy the powerups they would have originally had as well. When an enemy is killed it is sent to the graveyard out of the players sight. When our game requires an enemy with the same attributes as a graveyard enemy it will bring it back to the main game world with all its properties. When in the graveyard, our enemies lose their physics, collisions, etc. in order to save on memory.

*
A pic of the graveyard underneath our level




Our original idea was to stop drawing them and remove their rigid body functionality completely, but Havok's rigid body functionality caused problems when we tried to disable it, like causing the game to crash. To work around this, we simply made the dead enemy box deep enough so that the enemies could not pop back out of it, and the level big enough so that the dead enemy box could not be seen during normal gameplay. Thus, the graveyard was created.

Here's a picture of our enemy manager and what causes our enemies to despawn

When the enemies health drop to 0 their living variable is set to false. This means they are dead and sent to the middle of the graveyard with no velocity. The despawn function also handles what to do with the copied powerup or ammo that I mentioned above. 

          The despawn function also handles the point at which a new copy of the original powerup is created, with the powerup being spawned directly where the enemy died. The variable which keeps track of the number of enemies is being decreased by 1, so that it can be used to more easily determine when all the enemies have died without having to iterate through a loop to check whether all of the elements in the array that keeps track of whether an enemy is alive or not are set to the "dead" value. This is used to automatically respawn the enemies based on their original positions, or their spawn points, which are being loaded in from locators placed within a model of the level in Maya

So essentially, our enemies have all of their variables reset to the state they would be in after initially loading them and have their position set back to the position that we defined as an enemy's initial spawn point. When the function is called, all our enemies get respawned regardless of whether they are dead or not. This allows them to be respawned via a trigger that would force the player to restart their current wave.

I hope this sheds some light on some of the cool things we use in our engine when dealing with our enemies. For a more in depth rundown, check out or Game Engines report.

No comments:

Post a Comment