Guest User

Untitled

a guest
Nov 25th, 2015
179
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculateArrow(x1, x2, y1, y2) {
  2.   var deg = -90;
  3.   var dist_x = x1 - x2;
  4.   var dist_y = Math.abs(y1 - y2);
  5.   if (dist_y != 0) {
  6.     deg = Math.atan(dist_x / dist_y);
  7.   }
  8.   if (y2 < y1) {
  9.     deg = -1 * ((deg + Math.PI) % (2 * Math.PI));
  10.   }
  11.   return deg * 360 / (2 * Math.PI);
  12. }
  13.  
  14. function renderRadar() {
  15.     var mindist = 10000000000;
  16.     var closest;
  17.     var remainingFound = false;
  18.     for (var S = 0; S < explorer.objects.length; S++) {
  19.         var I = explorer.objects[S];
  20.         if (!I.got) {
  21.             remainingFound = true;
  22.             var dist = distance(explorer.pos.x, explorer.pos.y, I.x1, I.y1);
  23.             if (dist < mindist) {
  24.                 mindist = dist;
  25.                 closest = I;
  26.             }
  27.         }
  28.     }
  29.     if (!remainingFound) {
  30.         document.getElementById("radar").innerHTML = "You found all coins!";
  31.         return;
  32.     }
  33.     var indicator = "";
  34.     var deg = calculateArrow(closest.x1, explorer.pos.x, closest.y1, explorer.pos.y);
  35.     var dist_x = Math.abs(closest.x1 - explorer.pos.x);
  36.     var dist_y = Math.abs(closest.y1 - explorer.pos.y);
  37.     if (closest.x1 < explorer.pos.x) {
  38.         indicator += ((dist_x < 500)?"slightly ":"") + "left";
  39.     }
  40.     if (closest.x1 > explorer.pos.x) {
  41.         indicator += ((dist_x < 500)?"slightly ":"") + "right";
  42.     }
  43.     if (closest.y1 < explorer.pos.y) {
  44.         indicator += ((dist_y < 500)?"slightly ":"") + " up";
  45.     }
  46.     if (closest.y1 > explorer.pos.y) {
  47.         indicator += ((dist_y < 500)?"slightly ":"") + " down";
  48.     }
  49.     document.getElementById("radar").innerHTML = "Distance: " + mindist.toFixed(1).toString() + "<br/><div id=\"indic\" style=\"transform: rotate(" + deg + "deg)\" title=\"indicator\">&#8593;</div>";
  50. }
  51. setInterval(renderRadar, 100);
RAW Paste Data