add open animation for chest

This commit is contained in:
cracker0dks 2019-05-18 18:09:25 +02:00
parent 7429b1ae6d
commit c0d79755eb
3 changed files with 31 additions and 6 deletions

View File

@ -19,7 +19,16 @@ socket.on('getmap', function (conent) {
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>');
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.empty();
@ -63,6 +72,11 @@ socket.on('removeUtil', function (obj) {
$("."+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) {
if($("#"+id).length==0) {
var modeClass = "default_ship";
@ -215,7 +229,7 @@ $(document).ready(function() {
event.preventDefault();
}
var key = event.which;
console.log(key);
//console.log(key);
if(key==37||key==38||key==39||key==40)
event.preventDefault();
if(!keys[key]) {

View File

@ -138,9 +138,14 @@ module.exports = {
}
var treasureSet = false;
while (!treasureSet) {
for (var w = 0; w < width; w++) { //fill forest
var foundLand = true;
while (!treasureSet && foundLand) {
foundLand = false;
for (var w = 0; w < width; w++) { //add chest
for (var h = 0; h < height; h++) {
if(map[w][h] == "6") {
foundLand = true;
}
if (map[w][h] == "6" && Math.random() < 0.00001 && !treasureSet) {
treasureSet = true;
utilMap[w][h] = "treasure-closed";
@ -150,7 +155,6 @@ module.exports = {
}
}
var g = [6, 5, 4, 3, 2];
for (var k = 0; k < g.length; k++) {
var i = g[k] + "";

View File

@ -95,7 +95,14 @@ io.on('connection', function(socket){
playerActionTimer = setTimeout(function() {
utilMap[obj["mapY"]][obj["mapX"]] = "";
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);
}, 2000); //2 Secs
socket.emit("animation", 2000);