In the third semester, we had the task to build a 2.5 D shoot em up game within three weeks. This game should be made with object oriented programming, state machines, pathfinding and networking. We had the freedom to use any graphics pack we wanted as long as it is on the unity asset store. Only the code had to be done by us.
I decided to have three enemy types: close, ranged and the boss. Also there are power-ups that allow the player to have different kind of shots, regain health or add some points to the score.
Enemy Types and Behaviours
Both normal enemies basically have the same behaviour. They wait for the player to come near them and then attack him. This can be a ranged, or a close combat attack. If the player is too far away, the enemy looses track and goes back into the patroll state, or waits, if he has no waypoint.
Flowchart of the enemy state machine.
The different enemy classes where realised with polymorphism. The long ranged combat class derives from the close combat class and overrides the attack function, as well as the health this enemy has. The effects and range are overwritten and replaced with a spell the enemy casts.
To save some resources, the enemies are spawned and de-spawned in chunks. This means, that as soon as a player is leaving the spawn area, the enemies are de-spawned and the next section of the level is loaded.
Spawn points within the Unity editor.
The boss at the end of the stage functions a bit differntly than the rest of the games enemies. This boss has three phases he does in a particular order. The first phase is jumping towards the player, trying to crush him. As soon, as the health reaches a certain threshold the bunny begins to spawn exploding bunnies over the head of the player. These fall until another health-threshold is reached. Then, the bunny jumps again.
The game has three kinds of powerups, which all inherit their behaviour from something called collectable. Two of the items only have very simple functionality like adding to the score or give the player some health. Interesting is only the book which unlocks a new spell for a certain number of shots. It overrides the behaviour of the shots and resets itself as soon as the player has used up all spells. There are two spells. One is a kind of mortar shot that casts a huge fireball that can even roll on the ground and the other one is a fast shot where the name says it all.
The player has the mortar shot power up.
Network Movement and Shooting
The player, the spells and the enemies have a network component. This component sends a message when anything is about to happen (e.g. someone dies, a spell is casted, someone has a powerup etc.). The server then calls a function on the clients. Also every few milliseconds the position of every moving object is updated. The updates are not all at once, so the computer does not have too big of a workload. Since the velocity of the objects is also updated by that, the lag in movement is reduced to a minimum.