SHOW:
|
|
- or go back to the newest paste.
| 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 | for (var S = 0; S < explorer.objects.length; S++) {
| |
| 18 | var I = explorer.objects[S]; | |
| 19 | if (!I.got) {
| |
| 20 | var dist = distance(explorer.pos.x, explorer.pos.y, I.x1, I.y1); | |
| 21 | if (dist < mindist) {
| |
| 22 | mindist = dist; | |
| 23 | closest = I; | |
| 24 | } | |
| 25 | } | |
| 26 | } | |
| 27 | var indicator = ""; | |
| 28 | var deg = calculateArrow(closest.x1, explorer.pos.x, closest.y1, explorer.pos.y); | |
| 29 | var dist_x = Math.abs(closest.x1 - explorer.pos.x); | |
| 30 | var dist_y = Math.abs(closest.y1 - explorer.pos.y); | |
| 31 | if (closest.x1 < explorer.pos.x) {
| |
| 32 | indicator += ((dist_x < 500)?"slightly ":"") + "left"; | |
| 33 | } | |
| 34 | if (closest.x1 > explorer.pos.x) {
| |
| 35 | indicator += ((dist_x < 500)?"slightly ":"") + "right"; | |
| 36 | } | |
| 37 | if (closest.y1 < explorer.pos.y) {
| |
| 38 | indicator += ((dist_y < 500)?"slightly ":"") + " up"; | |
| 39 | } | |
| 40 | if (closest.y1 > explorer.pos.y) {
| |
| 41 | indicator += ((dist_y < 500)?"slightly ":"") + " down"; | |
| 42 | } | |
| 43 | document.getElementById("radar").innerHTML = "Distance: " + mindist.toFixed(1).toString() + "<br/><div id=\"indic\" style=\"transform: rotate(" + deg + "deg)\" title=\"indicator\">↑</div>";
| |
| 44 | - | } |
| 44 | + | |
| 45 | ||
| 46 | setInterval(renderRadar, 100); |