|
This weeks blog post will be about my ongoing work on implementing a sort of decent AI for our Tower defense game. The way I am implementing AI does not use A*star since the enemies will not be hindered by moving. They will just follow a path and attack the closest tower, if it intersects their aggro range. And if not they follow the original path to their final goal, the tree which you are supposed to protect.
Their movement is currently designed in such a way that when they spawn they search through a vector of nodes. They find the node of type “Node1” which is declared in the constructor of each node.
In the Update function of the enemy monsters, they check if their position is less or higher then the current node they are walking to. At least when their enum is set to move towards destination. The enemies currently hold two different enums. These are, isAttacking and currentDesination.
IsAttacking determines if a timer is run. The timer determines if the enemy can attack the object which it is colliding with, at this current point in time they only collide into the plants(the towers).
The enum IsAttacking also hinders the movement of the enemies while they are attacking, since they were acting strange when the movement was not hindered. CurrentDestination does not update while IsAttacking is Attack.
Improvement on the behavior is needed at this point because they need some sort of priority, and at the current point they prioritize the enemy that is the most newly placed. This is because each tower is pushed into a vector, and the enemies check the vector from the first to the last. So they automatically target the last tower placed that they can reach.
Each node has a collision box which the enemies collide into. If they collide into a node with the type “Node1” they will go towards the node type with the name “Node2” and so on, there is only one of each node.
This is a bad way to handle rally point movement since collision is a resource heavy way of handling things. If the game would turn out to slow down when we implement additional resources and AI. I will change the movement system to a dynamic list of nodes with only its coordinates. This will probably be designed so that each enemy has a pointer to the current node. And the current node is changed to the next one when the enemy’s position is equal or close to the node.
Also I received a tip to make the list or a class of the list into a singleton, though right now I do not know what that is, except that it can be reached from all classes.
About Gabriel Ajuwa
2014 Programming
|