View Single Post
Old 07-03-2012, 01:51 AM   #41
swampdog
Member
 
Join Date: Jul 2010
Posts: 31
swampdog is on a distinguished road
Re: Can MUDs implement range/distance?

Haha well since you bumped it, not only are trees a cool thing to learn but the math for co-ordinate grids is very simple. And even if you are finding paths or distances all the way across your 100x100 grid the math executes very quickly - this pseudocode finds the distance between any 2 points basically instantly and it doesn't matter how far apart the locations are:

return square((x2 - x1) ^ 2) + ((y2 - y1) ^ 2)

Where, x1 and y1 are the co-ordinates of your starting point and x2 and y2 are the co-ords of your ending point, and this applies to all handling of the grids. You can use (fast) elementary math to crunch the numbers, and then figure out what your grids are representing, which could be a projectile in flight (which you would then poll, updating the X, Y positions of all flying arrows on a regular basis), or the types of resources available at any X, Y point on a map.

Last edited by swampdog : 07-03-2012 at 02:59 AM.
swampdog is offline   Reply With Quote