I'm not getting the attachment but this might help.

If your doing range as a circle with radius = r then:

if ((enemy.x-tower.x)**2+ (enemy.y-tower.y)**2)**0.5<=r: attack!!!

basically, you'd be using Pythagorean theorem to find the distance to check
if it attacks or not.

Checking distances for every tower and every unit could become a bottle neck
but would work.

If you have performance problems you could also incorporate a grid.
When every unit moves it can do a check to see in what section of the map it
is found in (ie, grid could have 10x10 tiles in each square) and you would
only check the distance of creeps in the grids that are in range of the
tower.

One thing to keep in mind would be that in some cases you may be able to
stop the iteration as soon as you find someone who is attackable (if the
tower attacks random creeps) otherwise you just compare the distances of the
creeps and sort.

You may want to google for circle collision detection


-- Maranatha!
---------------------------------
PFC aka Fezzik aka GAB


On Tue, Nov 3, 2009 at 8:27 PM, Yanom Mobis <ya...@rocketmail.com> wrote:

> so, I wrote this tower defense game (zip archive attached) and I was
> wondering how I should go about implementing limited range (each tower can
> only shoot so far) in the code.
>
>

Reply via email to