Day 8 - An Orc Massacre

Today was an important day in history. No, it wasn’t due to the hours lost in bugs or vector maths. It was the addition of a self defence system to the base! The turret mechanics has begun, and it was quite fun!

The day started through adapting the Enemy Manager class. If I was to implement a turret, I needed the enemy manager to have a way to order it’s several lists of enemies based on proximity. This would give the turret some data to use when performing it’s "AI" and targetting enemies.

I decided to go with the idea of everytime a shot was fired, the enemy lists would be re-ordered. Despite not having many items in the lists (10-20 max), I think it would have been detrimental to performance should I have sorted the 16 enemy lists at every iteration! The enemy lists were stored in a dictionary, with a custom key made up of the enemy type and the lane direction (NESW). The value of the dictionary would then be the list. There were some issues trying to order these lists while iterating through with a foreach loop, some error about the dictionary not keeping in sync. A solution to this was to create a list of all the keys, and use this to iterate through the dictionary.

Once we had this in place, it opened up the ability to code some simple AI states for our turrets. There is one that will choose a lane at random and then shoot the closest enemy. There is one that scans all lanes for the closest enemy. There is one that focuses fire only on one lane. There is one that prioritises high ranked enemies only. When ranged units are added to the game, I will implement a AI state that the turret can follow in order to target those. A quick interface was drawn up, and then I got to enjoy the Massacre! To test this out, required many deaths to sacrifice their lives. It turned into a bit of a blood bath.,. but hey it’s not real… it’s okay…!

I added some cannon sprites, some scrolling text when enemies are damaged, and the blood pools also help identify where was shot. Of course the visuals will make it more clear, but it’s perfect for a prototype.

I worked on the enemy AI for some time too, but I use the term AI very loosely!! The enemies needed a change so that they get to the castle wall before attacking, rather than starting to attack the moment they get within "range of attack", as they were previously leaving a gap between the castle and the orcs! The Grunt AI also needed a way to stop them all shoving towards the front and constantly trying to move forward. So I added ray casting to the grunts that check if they will bump into other enemies, and some very basic avoidance to avoid single lanes of traffic backing up. The great unexpected thing about this, was that the Chieftains were not modified in the same way, and they now run into battle and shove the Grunts out of the way! Accidental but great result!

The AI stuff was where the vector maths delay session came into the equasion. I am very thankful for having helpful and knowledgable people in stream who could help me remember the maths of 13 years ago :D My ray casting bug was due to me using a positional vector instead of a directional vector. Was a painful few hours but I’m glad I’ve learned from it! Here’s some silly doodles made when trying to understand it :D

Finally I worked on developing the Special Ability manager and the UI Interface when you click to use an ability. The interfaces work, tomorrow I will need to implement the ability affects, such as placing down an ice wall, damaging cloud of poison and so on!

Get Honest Dan's Last Stand

Download NowName your own price

Leave a comment

Log in with to leave a comment.