Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Sort list on x axis, h = 10px interaction radius
  2.  
  3. var b1:Ball = head;
  4. while (b1 != null) {
  5.     var b2 = b1.next;
  6.     while (b2 != null && b1.x+h > b2.x-h) {
  7.         var dy = b2.y-b1.y;
  8.         if (dy > h || dy < -h) {
  9.             b2 = b2.next;
  10.             continue;
  11.         }
  12.  
  13.         var dx = b2.x-b1.x;
  14.         var d = dx*dx+dy*dy;
  15.         if (d < h*h) {
  16.             // colliding
  17.         }
  18.        
  19.         b2 = b2.next;
  20.     }
  21.     b1 = b1.next;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement