diff --git a/index.html b/index.html
index b992530..e8b8e50 100644
--- a/index.html
+++ b/index.html
@@ -15,8 +15,7 @@
Pirate!!!
+
diff --git a/js/main.js b/js/main.js
index 75e393e..b47dd63 100644
--- a/js/main.js
+++ b/js/main.js
@@ -38,8 +38,8 @@ var tooltiptexts = {
"item_weapon_sword3": "Schwert: Schaden erhöht 400",
"item_weapon_sword4": "Schwert: Schaden erhöht 500",
"item_weapon_sword5": "Schwert: Schaden erhöht 600",
- "item_weapon_stick1": "Stock: Schaden erhöht 50",
- "item_item_bone1": "Mach nix, ehöht aber dein Level um 1",
+ "item_weapon_stick1": "Stock: Schaden +20",
+ "item_item_bone1": "Knochen: Schaden +5",
"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!",
@@ -120,6 +120,21 @@ socket.on('replaceUtil', function (obj) {
utilMap[obj["mapY"]][obj["mapX"]] = obj["newName"];
});
+socket.on('hpChange', function (obj) {
+ console.log(obj);
+ $(".hpBar").css({"width" : obj+"px"});
+});
+
+socket.on('newPlayerHp', function (obj) {
+ console.log(obj)
+ if(obj.socketId == socket.id) {
+ $(".hpBar").css({"width" : obj["hp"]+"px"});
+ }
+
+
+});
+
+
socket.on('dropItem', function (obj) {
console.log(obj);
var utilTitle = tooltiptexts[obj["newName"]] ? tooltiptexts[obj["newName"]] : "";
diff --git a/server.js b/server.js
index 02398fe..918e749 100644
--- a/server.js
+++ b/server.js
@@ -150,6 +150,7 @@ var itemAttrs = {
},
"item_item_bone1": {
lvl: 1,
+ dmg: 5
},
"item_consumable_fish1": {
lvl: 3,
@@ -196,11 +197,12 @@ io.on('connection', function (socket) {
chest: null,
legs: null,
boots: null,
- weapon: 'item_weapon_sword2',
+ weapon: null,
tool: null,
item: null
},
- hp : 100
+ hp : 80,
+ socketId : socket.id
};
var player = allPlayers[socket.id];
io.sockets.emit("newPlayer", {
@@ -251,7 +253,7 @@ io.on('connection', function (socket) {
socket.on('keyDown', function (key) {
allPlayers[socket.id]["keys"][key] = true;
- if(key == 32) { //Space HIT SOMEONE
+ if(key == 32 && allPlayers[socket.id]["mode"] != 0) { //Space HIT SOMEONE
//if(allPlayers[socket.id]["mode"] == 1) { // On land
if(!allPlayers[socket.id]["hitPending"]) {
io.sockets.emit("showHitAnimation", socket.id);
@@ -376,7 +378,15 @@ io.on('connection', function (socket) {
if(slotArt == "consumable") {
let hp = itemAttrs[obj["name"]]["hp"];
allPlayers[socket.id]["hp"] += hp;
- socket.emit("displayMsg", "Lebenspunkte +"+hp);
+ let toMutch = 0;
+ if(allPlayers[socket.id]["hp"]>100) {
+ toMutch = allPlayers[socket.id]["hp"]-100;
+ }
+ if(allPlayers[socket.id]["hp"] > 100) {
+ allPlayers[socket.id]["hp"] = 100;
+ }
+ socket.emit("displayMsg", "Lebenspunkte +"+(hp-toMutch));
+ socket.emit("hpChange", allPlayers[socket.id]["hp"]);
} else {
allPlayers[socket.id]["slots"][slotArt] = itemName;
socket.emit("addItemToInventar", itemName);
@@ -419,11 +429,17 @@ function calcDmgAndHitPlayer(player1, player2) {
}
let hitDmg = dmg * (armor/100) * 100
player2["hp"] -= hitDmg;
+ if(player2["hp"] < 0) {
+ player2["hp"] = 0;
+ }
+
+ io.sockets.emit("newPlayerHp", { socketId : player2["socketId"], hp : player2["hp"]})
console.log(hitDmg, dmg, armor, player1, player2)
}
function getRandomItem(minLvl, maxLvl) {
//console.log("rnd", items.length, getRandomNumber(0, items.length), items)
+ //return items[32] //fish
while (1) {
let item = items[getRandomNumber(0, items.length)];
console.log(item)
@@ -480,7 +496,8 @@ setInterval(function () {
for (var id in allPlayers) {
var player = allPlayers[id];
for (var key in player["keys"]) {
- if (player["keys"][key]) { //if key is pressed
+ if (player["keys"][key] && player["hp"] >0) { //if key is pressed
+
var tx = 0;
var ty = 0;