added schatz

This commit is contained in:
Raphael 2024-11-14 17:37:13 +01:00
parent 67ea082795
commit 00da94c4a1
3 changed files with 76 additions and 13 deletions

View File

@ -19,9 +19,18 @@
width: 32px; width: 32px;
height: 32px; height: 32px;
background: url(../img/objectlayer.png) 125px -29px; 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 { .tree1 {
width: 60px; width: 60px;
height: 60px; height: 60px;
@ -542,6 +551,14 @@
background: url(../img/ground_tiles.png) 192px 254px; 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 { .water_1 {
background: url(../img/ground_tiles.png) -1px -1px; background: url(../img/ground_tiles.png) -1px -1px;
} }

View File

@ -42,6 +42,7 @@ var tooltiptexts = {
"item_item_bone0": "Ganz toller Knochen!", "item_item_bone0": "Ganz toller Knochen!",
"item_item_seemen0": "Super Radieschen!", "item_item_seemen0": "Super Radieschen!",
"item_item_spaten3": "Spaten: Schneller graben", "item_item_spaten3": "Spaten: Schneller graben",
"item_item_schatz": "Super toller Schatz",
"item_consumable_fish1": "Erhöht deine Lebenspunkte um 20", "item_consumable_fish1": "Erhöht deine Lebenspunkte um 20",
"item_consumable_fish2": "Erhöht deine Lebenspunkte um 10", "item_consumable_fish2": "Erhöht deine Lebenspunkte um 10",
"item_item_dimond1": "Verkaufe den Diamand für 10 Siegpunkte! Bewegungsgeschwindigkeit verlangsamt!", "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) { socket.on('stopAnimation', function (timer) {
$("#animationDiv").remove(); $("#animationDiv").remove();
}); });

View File

@ -18,6 +18,27 @@ var map = require("./s_map.js");
var maxX = mapWidth * 32; var maxX = mapWidth * 32;
var maxY = mapHeight * 32; var maxY = mapHeight * 32;
var newmap = map.generateMap(mapWidth, mapHeight); 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 cssMap = newmap["cssMap"];
var map = newmap["map"]; var map = newmap["map"];
var utilMap = newmap["utilMap"]; var utilMap = newmap["utilMap"];
@ -157,6 +178,9 @@ var itemAttrs = {
"item_item_spaten3": { "item_item_spaten3": {
lvl: 1, lvl: 1,
}, },
"item_item_schatz": {
lvl: -1,
},
"item_consumable_fish1": { "item_consumable_fish1": {
lvl: 3, lvl: 3,
hp: 30, hp: 30,
@ -267,7 +291,7 @@ io.on('connection', function (socket) {
for (var i = 0; i < allPlayersWithCollision.length; i++) { for (var i = 0; i < allPlayersWithCollision.length; i++) {
calcDmgAndHitPlayer(allPlayers[socket.id], allPlayers[allPlayersWithCollision[i]]) calcDmgAndHitPlayer(allPlayers[socket.id], allPlayers[allPlayersWithCollision[i]])
} }
console.log(allPlayersWithCollision); //console.log(allPlayersWithCollision);
setTimeout(function () { setTimeout(function () {
allPlayers[socket.id]["hitPending"] = false; allPlayers[socket.id]["hitPending"] = false;
@ -276,21 +300,27 @@ io.on('connection', function (socket) {
//} //}
} else if (key == 71) { // Taste G } else if (key == 71) { // Taste G
var groundUnder = getGroundUnderPlayer(player["x"], player["y"]); 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 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; cutTime = 2000;
} }
if (playerActionTimer) { if (playerActionTimer) {
clearTimeout(playerActionTimer); clearTimeout(playerActionTimer);
playerActionTimer = null; playerActionTimer = null;
} }
playerActionTimer = setTimeout(function () { playerActionTimer = setTimeout(function () {
//Drop a random Item let randomItem = getRandomItem(0, 0); //Drop a random Item
let randomItem = getRandomItem(0, 0); 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)); let nearFieldCoords = getNearEmptyField(Math.floor(player["x"] / 32), Math.floor(player["y"] / 32));
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem; utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
@ -301,6 +331,15 @@ io.on('connection', function (socket) {
} }
io.sockets.emit("dropItem", newObj); 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); socket.emit("stopAnimation", cutTime);
allPlayers[socket.id]["action"] = false; 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("drop", newObj)
} }
console.log(slotArt)
if (slotArt == "consumable") { if (slotArt == "consumable") {
let hp = itemAttrs[obj["name"]]["hp"]; let hp = itemAttrs[obj["name"]]["hp"];
allPlayers[socket.id]["hp"] += hp; allPlayers[socket.id]["hp"] += hp;
@ -479,7 +517,7 @@ function calcDmgAndHitPlayer(player1, player2) {
} }
io.sockets.emit("newPlayerHp", { socketId: player2["socketId"], hp: player2["hp"] }) 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) { function getRandomItem(minLvl, maxLvl) {
@ -488,7 +526,7 @@ function getRandomItem(minLvl, maxLvl) {
// return items[32] //fish // return items[32] //fish
while (1) { while (1) {
let item = items[getRandomNumber(0, items.length)]; 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))) { if (item && (typeof (maxLvl) == "undefined" || typeof (minLvl) == "undefined" || (itemAttrs[item]["lvl"] >= minLvl && itemAttrs[item]["lvl"] <= maxLvl))) {
return item; return item;
@ -671,7 +709,7 @@ function checkHitWithOtherPlayers(socketId) {
//console.log(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8) //console.log(mainPlayer.x, mainPlayer.y, 28, targetPlayer.x, targetPlayer.y, 8)
if (isCircleCircleCollision(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; 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) { if (mainPlayer.lookingLeft == 1 && mainPlayer.x >= targetPlayer.x) {
hit = true; hit = true;
} else if (mainPlayer.lookingLeft == -1 && mainPlayer.x <= targetPlayer.x) { } else if (mainPlayer.lookingLeft == -1 && mainPlayer.x <= targetPlayer.x) {