Tuesday, November 22, 2011

Radar

Just thought I'd share an update with the new Radar.  It's in the top left corner where the momentum-meter is.


Notice the little red dots?  Simple but effective.

I thought about the best way to approach this.  First thought was to have the game go through all of the enemy, get their distance from the player (their location - player's location) and those that are within a certain range would add themselves to a list.  That list is cleared() every single frame, so only enemies that are close would be in it.

After thinking that through, it definitely didn't seem like it was the most efficient way.  Then I remembered that the AI is always checking its distance from the player anyway.  After realizing that, it was a very simple if statement to see if the enemy is in range and it added itself to the list.

That seems simple enough and takes up a very small amount of extra CPU (just an if statement and List<> insert).  Sounds like a good solution to me.

No comments: