Created
August 25, 2011 10:11
-
-
Save NHQ/1170374 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // shortest distance to checking all relative distances | |
| // because with an array of game objects, we don't need to check | |
| // each object's distance to all other objects | |
| // That would duplicate work (don't want to check one against another | |
| // and the other against the one). So each one needs only be checked | |
| // against objects to right of it | |
| objects = [a,b,c,d,e,f,g] // each letter represents a game object (or comprises the object whole) ie {_id:"1234567", coord:[x,y], radius: 50} | |
| function checkDistance(obj, target){ | |
| // use coord's to check distance using distance formula | |
| // react accordingly | |
| } | |
| function crowFlies (obs, index){ | |
| if (index == "undefined") //if the index doesn't exist, start the function over from 0 index | |
| crowFlies(objects,0) // could be setTimeout, depends... | |
| } | |
| else | |
| { | |
| for (x = obs.length; x > index; --x) //for all objects to the right of this one | |
| { | |
| checkDistance(obs[index], obs[x]); // check distance | |
| crowFlies(objects, index+1) // continue with next index | |
| } | |
| } | |
| }crowflies(objects,0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment