This is the manhattan distance, which creates diamond shaped areas
rather than circular shaped ones, for a given range. It is useful
mainly for tile-based engines. If that is not the case, I think the
euclidian distance (dx**2 + dy**2 <= r**2) will work much better.

On Wed, Nov 4, 2009 at 15:23, Kris Schnee <ksch...@xepher.net> wrote:
> On Wed, 4 Nov 2009 09:21:58 -0800, James Paige <b...@hamsterrepublic.com>
> wrote:
>> A quick test with the timeit module suggest that the ** operator is not
>> slower.
>
>> Here is how I would write the distance check:
>>
>> def is_in_range(enemy, tower):
>>   return (enemy.x-tower.x)**2 + (enemy.y-tower.y)**2 <= tower.range**2
>
> If speed is important, how about trying a cruder orthogonal method?
>
> def IsInRange(enemy,tower):
>    return (enemy.x-tower.x) + (enemy.y-tower.y) <= tower.range
>
>

Reply via email to