From 00da94c4a11caa55163079c77da74f009952b14e Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 14 Nov 2024 17:37:13 +0100 Subject: [PATCH] added schatz --- css/main.css | 19 +++++++++++++++- js/main.js | 8 +++++++ server.js | 62 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/css/main.css b/css/main.css index c865ae4..d65d1ee 100644 --- a/css/main.css +++ b/css/main.css @@ -19,9 +19,18 @@ width: 32px; height: 32px; background: url(../img/objectlayer.png) 125px -29px; - ; } +.item_item_schatz { + background: url(../img/items.png) -220px -91px; + width: 30px; + background-size: 500px; + margin-left: 5px; + margin-top: 5px; +} + + + .tree1 { width: 60px; height: 60px; @@ -542,6 +551,14 @@ background: url(../img/ground_tiles.png) 192px 254px; } +.sandhaufen { + background: url(../img/ground_tiles.png) 173px -11px; +} + +.erdhaufen { + background: url(../img/ground_tiles.png) 173px -11px; +} + .water_1 { background: url(../img/ground_tiles.png) -1px -1px; } diff --git a/js/main.js b/js/main.js index 5d601a8..76bad1e 100644 --- a/js/main.js +++ b/js/main.js @@ -42,6 +42,7 @@ var tooltiptexts = { "item_item_bone0": "Ganz toller Knochen!", "item_item_seemen0": "Super Radieschen!", "item_item_spaten3": "Spaten: Schneller graben", + "item_item_schatz": "Super toller Schatz", "item_consumable_fish1": "Erhöht deine Lebenspunkte um 20", "item_consumable_fish2": "Erhöht deine Lebenspunkte um 10", "item_item_dimond1": "Verkaufe den Diamand für 10 Siegpunkte! Bewegungsgeschwindigkeit verlangsamt!", @@ -93,6 +94,13 @@ socket.on('animation', function (timer) { }); + +socket.on('replaceFloor', function (content) { + $("." + content["y"] + '-' + content["x"]+'.sprite').removeClass("ground").addClass(content["newFloor"]); + cssMap[content["y"]][content["x"]] = content["newFloor"]; + console.log(content) +}); + socket.on('stopAnimation', function (timer) { $("#animationDiv").remove(); }); diff --git a/server.js b/server.js index fac46ad..cf24b6b 100644 --- a/server.js +++ b/server.js @@ -18,6 +18,27 @@ var map = require("./s_map.js"); var maxX = mapWidth * 32; var maxY = mapHeight * 32; var newmap = map.generateMap(mapWidth, mapHeight); + +let schatzversteckt = false; +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 (Math.random() < 0.1 && !schatzversteckt) { + //console.log("versteckt", line, column) + schatzcoords = { x: line, y: column }; + //newmap.utilMap[line][column] = "item_item_schatz"; + schatzversteckt = true + console.log(schatzcoords) + } + + } + } + } + +} +//console.log(newmap.map) var cssMap = newmap["cssMap"]; var map = newmap["map"]; var utilMap = newmap["utilMap"]; @@ -157,6 +178,9 @@ var itemAttrs = { "item_item_spaten3": { lvl: 1, }, + "item_item_schatz": { + lvl: -1, + }, "item_consumable_fish1": { lvl: 3, hp: 30, @@ -267,7 +291,7 @@ io.on('connection', function (socket) { for (var i = 0; i < allPlayersWithCollision.length; i++) { calcDmgAndHitPlayer(allPlayers[socket.id], allPlayers[allPlayersWithCollision[i]]) } - console.log(allPlayersWithCollision); + //console.log(allPlayersWithCollision); setTimeout(function () { allPlayers[socket.id]["hitPending"] = false; @@ -276,21 +300,27 @@ io.on('connection', function (socket) { //} } else if (key == 71) { // Taste G var groundUnder = getGroundUnderPlayer(player["x"], player["y"]); - if (groundUnder == 10) { //its land + let x = Math.floor(player["x"] / 32); + let y = Math.round(player["y"] / 32); + console.log("soso", map[y][x], y, x) + if (map[y][x] == 6 || map[y][x] == 4 || map[y][x] == 5) { //its land let cutTime = 6000; //6 Secs - console.log(player) - if(player["slots"] && player["slots"]["item"] && player["slots"]["item"] == "item_item_spaten3") { + if (player["slots"] && player["slots"]["item"] && player["slots"]["item"] == "item_item_spaten3") { cutTime = 2000; } if (playerActionTimer) { clearTimeout(playerActionTimer); playerActionTimer = null; } - + playerActionTimer = setTimeout(function () { - //Drop a random Item - let randomItem = getRandomItem(0, 0); + let randomItem = getRandomItem(0, 0); //Drop a random Item + if(schatzcoords["y"] == x && schatzcoords["x"] == y) { + randomItem = "item_item_schatz" + console.log("schatz!"); + } + let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32)); utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem; @@ -301,6 +331,15 @@ io.on('connection', function (socket) { } io.sockets.emit("dropItem", newObj); + io.sockets.emit("replaceFloor", { + x: x, + y: y, + newFloor: "sandhaufen" + }); + + cssMap[y][x] = "sandhaufen"; + map[y][x] = 100; + socket.emit("stopAnimation", cutTime); allPlayers[socket.id]["action"] = false; @@ -310,7 +349,7 @@ io.on('connection', function (socket) { } - console.log(groundUnder) + //console.log(groundUnder) } }); @@ -418,7 +457,6 @@ io.on('connection', function (socket) { //console.log("drop", newObj) } - console.log(slotArt) if (slotArt == "consumable") { let hp = itemAttrs[obj["name"]]["hp"]; allPlayers[socket.id]["hp"] += hp; @@ -479,7 +517,7 @@ function calcDmgAndHitPlayer(player1, player2) { } io.sockets.emit("newPlayerHp", { socketId: player2["socketId"], hp: player2["hp"] }) - console.log(hitDmg, dmg, armor, player1, player2) + //console.log(hitDmg, dmg, armor, player1, player2) } function getRandomItem(minLvl, maxLvl) { @@ -488,7 +526,7 @@ function getRandomItem(minLvl, maxLvl) { // return items[32] //fish while (1) { let item = items[getRandomNumber(0, items.length)]; - console.log(item) + //console.log(item) if (item && (typeof (maxLvl) == "undefined" || typeof (minLvl) == "undefined" || (itemAttrs[item]["lvl"] >= minLvl && itemAttrs[item]["lvl"] <= maxLvl))) { return item; @@ -671,7 +709,7 @@ function checkHitWithOtherPlayers(socketId) { //console.log(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8) if (isCircleCircleCollision(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)) { let hit = false; - console.log(mainPlayer.lookingLeft, mainPlayer.lookingUp, mainPlayer.x, mainPlayer.y, targetPlayer.x, targetPlayer.y) + //console.log(mainPlayer.lookingLeft, mainPlayer.lookingUp, mainPlayer.x, mainPlayer.y, targetPlayer.x, targetPlayer.y) if (mainPlayer.lookingLeft == 1 && mainPlayer.x >= targetPlayer.x) { hit = true; } else if (mainPlayer.lookingLeft == -1 && mainPlayer.x <= targetPlayer.x) {