diff --git a/img/kompass.psd b/img/kompass.psd new file mode 100644 index 0000000..6661bc4 Binary files /dev/null and b/img/kompass.psd differ diff --git a/img/kompassPfeil.png b/img/kompassPfeil.png new file mode 100644 index 0000000..b9c6fc9 Binary files /dev/null and b/img/kompassPfeil.png differ diff --git a/img/kompassPfeilGold.png b/img/kompassPfeilGold.png new file mode 100644 index 0000000..b90e016 Binary files /dev/null and b/img/kompassPfeilGold.png differ diff --git a/img/kompassRing.png b/img/kompassRing.png new file mode 100644 index 0000000..8b8e32d Binary files /dev/null and b/img/kompassRing.png differ diff --git a/index.html b/index.html index e8b8e50..d5fa359 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,10 @@
diff --git a/js/main.js b/js/main.js index bdc0c2e..9db54ca 100644 --- a/js/main.js +++ b/js/main.js @@ -178,10 +178,25 @@ var oldmapY = null; var picStep = 0; var cnt = 0; let g_allPlayers = {}; +let schatzCoords = {}; + +socket.on('setSchatzCoords', function (setSchatzCoordsNew) { + schatzCoords = setSchatzCoordsNew["schatzcoords"]; +}); socket.on('setpos', function (allPlayers) { window.requestAnimationFrame(function () { g_allPlayers = allPlayers; for (var id in allPlayers) { + if(id == socket.id) { + let x = schatzCoords["x"]*32-allPlayers[id]["x"]+16; + let y = schatzCoords["y"]*32-allPlayers[id]["y"]+16; + console.log(schatzCoords["x"]*32, schatzCoords["y"]*32) + console.log(allPlayers[id]["x"], allPlayers[id]["y"]) + + let angle = calcAngleDegrees(x, y); + $("#kompoassnadel").css("transform", "rotate(" + (angle+90) + "deg)"); + //console.log("angle", angle) + } var player = allPlayers[id]; var playerElement = $("#" + id); var playerImg = playerElement.find("img"); @@ -410,4 +425,8 @@ $(document).ready(function () { }); -}); \ No newline at end of file +}); + +function calcAngleDegrees(x, y) { + return (Math.atan2(y, x) * 180) / Math.PI; + } \ No newline at end of file diff --git a/server.js b/server.js index 8785102..cbced31 100644 --- a/server.js +++ b/server.js @@ -24,7 +24,7 @@ let schatzcoords = { x: 0, y: 0 }; while (!schatzversteckt) { for (var line = 0; line < newmap.map.length; line++) { for (var column = 0; column < newmap.map[line].length; column++) { - if (newmap.map[line][column] == 4 || newmap.map[line][column] == 10) { + if (newmap.map[line][column] == 4 || newmap.map[line][column] == 10) { //TODO schatz nicht im Wasser Spawnen! if (Math.random() < 0.1 && !schatzversteckt) { //console.log("versteckt", line, column) schatzcoords = { x: line, y: column }; @@ -238,6 +238,10 @@ io.on('connection', function (socket) { player: allPlayers[socket.id], id: socket.id }); + + io.sockets.emit("setSchatzCoords", { + schatzcoords: schatzcoords, + }); socket.on('disconnect', function () { for (var i in player.slots) { |