Keeping the distance

There has been a long weekend but I have implemented a distance check. This will also be the firing range later on. It was really simple. It is an new integer member of tank’s base class Agent. I call it distanceUnits. I just assign it the number two for now. When I search the path from the behavior tree, I also fill the tank’s path list. The path finding algorithm fills its own path list by adding the goal node and its parents all the way back to the starting node. I add these nodes’ positions to the tank’s path list backwards from the end of the first path list to the front of it and I simply stop the loop before the tank gets the position of the goal node. Since the distanceUnits variable equals two, the tank’s path list stops three squares from the goal. (Of course, the 0-th index in any list is the first element which means it naturally stops three elements from the start element if I let the loop stop when “i” is not greater than two).

AgentDistance.PNG

As seen in the picture, the two blue squares (tanks) have stopped before they have arrived at the enemy bases (red and green squares).

in code it looks like this(read the comments in the code):

https://pastebin.com/2Y6b8SLR

Just a quick post this time. Next up will be the bases and then I will probably need to discuss what to do with them and the tanks to have the tanks destroy the bases. After that I’d probably also want to start adding new types of units. Should be relatively straight forward.

As always, take care of yourself, aaaaaand each other!

(if you know where this expression comes from, comment 🙂 )

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s