diff --git a/js/main.js b/js/main.js index 724dbb7..e4ac7dd 100644 --- a/js/main.js +++ b/js/main.js @@ -24,21 +24,6 @@ socket.on('getmap', function (conent) { domMap.empty(); - // for(var w=0;w'); - // } - // } - - // for(var w=0;w'); - // } - // } - // } - var allPlayers = conent["allPlayers"]; console.log(allPlayers); for(var id in allPlayers) { @@ -46,6 +31,20 @@ socket.on('getmap', function (conent) { } }); +socket.on('objAction', function (obj) { + console.log(obj); + var mapX = obj["mapX"]*32; + var mapY = obj["mapY"]*32; + $(".overlay").remove(); + $("#main").append('
'); + +}); + +socket.on('removeUtil', function (obj) { + console.log(obj); + $("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).remove(); +}); + function addNewPlayer(player, id) { if($("#"+id).length==0) { var modeClass = "default_ship"; @@ -112,7 +111,7 @@ socket.on('setpos', function (allPlayers) { domMap.append(''); var utilTitle = utilMap[y][x]; if(utilTitle!="") { - domMap.append(''); + domMap.append(''); } if(!visibleMap[x]) { visibleMap[x] = []; @@ -198,6 +197,7 @@ $(document).ready(function() { event.preventDefault(); } var key = event.which; + console.log(key); if(key==37||key==38||key==39||key==40) event.preventDefault(); if(!keys[key]) { @@ -214,6 +214,9 @@ $(document).ready(function() { $( document ).keyup(function( event ) { var key = event.which; socket.emit("keyUp", key ); + if(key==32) { + $(".overlay").remove(); + } keys[key] = false; }); diff --git a/s_map.js b/s_map.js index 67b52eb..1c9a65e 100644 --- a/s_map.js +++ b/s_map.js @@ -24,7 +24,7 @@ module.exports = { for(var h=0;h6 && rX<26) { //He stands in the middle of the field (left-><-right) + if(rY<16) { //go Up + sY = -1; + } else { //go Down + sY = 1; + } + } else if(rY>6 && rY<26) { //He stands in the middle of the field (up-><-down) + if(rX<16) { //go left + sX = -1; + } else { //go right + sX = 1; + } + } + + if(utilMap[mapY+sY][mapX+sX]!="") { + obj = { + mapY : mapY+sY, + mapX : mapX+sX, + name : utilMap[mapY+sY][mapX+sX] + } + } + } + + return obj; + +} setInterval(function() { for(var id in allPlayers) { @@ -99,14 +165,16 @@ setInterval(function() { ty = mvnt; } - var newX = player["x"]+tx; - var newY = player["y"]+ty; - - var groundUnderPlayer = getGroundUnderPlayer(newX, newY); - if(checkPlayerPosition(newX, newY, groundUnderPlayer, player)) { - player["x"] = newX; - player["y"] = newY; - player["mvnt"] = getPlayerMvnt(player, groundUnderPlayer); + if(!player["action"]) { + var newX = player["x"]+tx; + var newY = player["y"]+ty; + + var groundUnderPlayer = getGroundUnderPlayer(newX, newY); + if(checkPlayerPosition(newX, newY, groundUnderPlayer, player)) { + player["x"] = newX; + player["y"] = newY; + player["mvnt"] = getPlayerMvnt(player, groundUnderPlayer); + } } } }