add open animation for chest
This commit is contained in:
parent
7429b1ae6d
commit
c0d79755eb
18
js/main.js
18
js/main.js
@ -19,7 +19,16 @@ socket.on('getmap', function (conent) {
|
|||||||
cssMap = conent["cssMap"];
|
cssMap = conent["cssMap"];
|
||||||
$("#main").append('<div style="position:absolute; top:0px;left:0px; width:'+cssMap.length*32+'px; height:'+cssMap[0].length*32+'px"></div>');
|
$("#main").append('<div style="position:absolute; top:0px;left:0px; width:'+cssMap.length*32+'px; height:'+cssMap[0].length*32+'px"></div>');
|
||||||
utilMap = conent["utilMap"];
|
utilMap = conent["utilMap"];
|
||||||
//console.log(map);
|
var chestCoords = [0,0];
|
||||||
|
for (var w = 0; w < utilMap.length; w++) { //get chest coords
|
||||||
|
for (var h = 0; h < utilMap[w].length; h++) {
|
||||||
|
if(utilMap[w][h]=="treasure-closed") {
|
||||||
|
chestCoords = [w,h];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(chestCoords);
|
||||||
|
//console.log(cssMap);
|
||||||
domMap = $("#map");
|
domMap = $("#map");
|
||||||
|
|
||||||
domMap.empty();
|
domMap.empty();
|
||||||
@ -63,6 +72,11 @@ socket.on('removeUtil', function (obj) {
|
|||||||
$("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).remove();
|
$("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('replaceUtil', function (obj) {
|
||||||
|
console.log(obj);
|
||||||
|
$("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).removeClass(obj["name"]).addClass(obj["newName"]);
|
||||||
|
});
|
||||||
|
|
||||||
function addNewPlayer(player, id) {
|
function addNewPlayer(player, id) {
|
||||||
if($("#"+id).length==0) {
|
if($("#"+id).length==0) {
|
||||||
var modeClass = "default_ship";
|
var modeClass = "default_ship";
|
||||||
@ -215,7 +229,7 @@ $(document).ready(function() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
var key = event.which;
|
var key = event.which;
|
||||||
console.log(key);
|
//console.log(key);
|
||||||
if(key==37||key==38||key==39||key==40)
|
if(key==37||key==38||key==39||key==40)
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if(!keys[key]) {
|
if(!keys[key]) {
|
||||||
|
10
s_map.js
10
s_map.js
@ -138,9 +138,14 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var treasureSet = false;
|
var treasureSet = false;
|
||||||
while (!treasureSet) {
|
var foundLand = true;
|
||||||
for (var w = 0; w < width; w++) { //fill forest
|
while (!treasureSet && foundLand) {
|
||||||
|
foundLand = false;
|
||||||
|
for (var w = 0; w < width; w++) { //add chest
|
||||||
for (var h = 0; h < height; h++) {
|
for (var h = 0; h < height; h++) {
|
||||||
|
if(map[w][h] == "6") {
|
||||||
|
foundLand = true;
|
||||||
|
}
|
||||||
if (map[w][h] == "6" && Math.random() < 0.00001 && !treasureSet) {
|
if (map[w][h] == "6" && Math.random() < 0.00001 && !treasureSet) {
|
||||||
treasureSet = true;
|
treasureSet = true;
|
||||||
utilMap[w][h] = "treasure-closed";
|
utilMap[w][h] = "treasure-closed";
|
||||||
@ -150,7 +155,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var g = [6, 5, 4, 3, 2];
|
var g = [6, 5, 4, 3, 2];
|
||||||
for (var k = 0; k < g.length; k++) {
|
for (var k = 0; k < g.length; k++) {
|
||||||
var i = g[k] + "";
|
var i = g[k] + "";
|
||||||
|
@ -95,7 +95,14 @@ io.on('connection', function(socket){
|
|||||||
playerActionTimer = setTimeout(function() {
|
playerActionTimer = setTimeout(function() {
|
||||||
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
utilMap[obj["mapY"]][obj["mapX"]] = "";
|
||||||
io.sockets.emit("removeUtil", obj);
|
io.sockets.emit("removeUtil", obj);
|
||||||
console.log("REMOVEEEEE", obj);
|
socket.emit("stopAnimation", 2000);
|
||||||
|
}, 2000); //2 Secs
|
||||||
|
socket.emit("animation", 2000);
|
||||||
|
} else if(obj["name"] == "treasure-closed") {
|
||||||
|
playerActionTimer = setTimeout(function() {
|
||||||
|
utilMap[obj["mapY"]][obj["mapX"]] = "treasure-open";
|
||||||
|
obj["newName"] = "treasure-open";
|
||||||
|
io.sockets.emit("replaceUtil", obj);
|
||||||
socket.emit("stopAnimation", 2000);
|
socket.emit("stopAnimation", 2000);
|
||||||
}, 2000); //2 Secs
|
}, 2000); //2 Secs
|
||||||
socket.emit("animation", 2000);
|
socket.emit("animation", 2000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user