add function to drop items from crates
This commit is contained in:
parent
c0d79755eb
commit
c409b5e5e9
42
css/main.css
42
css/main.css
@ -54,6 +54,48 @@
|
||||
transform-origin: 0;
|
||||
}
|
||||
|
||||
/* Items */
|
||||
.boots1 {
|
||||
background: url(../img/items.png) 0px -95px;
|
||||
width: 30px;
|
||||
background-size: 500px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.boots2 {
|
||||
background: url(../img/items.png) -32px -95px;
|
||||
width: 30px;
|
||||
background-size: 500px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.boots3 {
|
||||
background: url(../img/items.png) -64px -95px;
|
||||
width: 30px;
|
||||
background-size: 500px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.boots4 {
|
||||
background: url(../img/items.png) -96px -95px;
|
||||
width: 30px;
|
||||
background-size: 500px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.boots5 {
|
||||
background: url(../img/items.png) -128px -95px;
|
||||
width: 30px;
|
||||
background-size: 500px;
|
||||
margin-left: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* Guy */
|
||||
.guy1-0-0 {
|
||||
background: url(../img/guy_sprite.png) 0px 0px;
|
||||
}
|
||||
|
BIN
img/items.png
Normal file
BIN
img/items.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 662 KiB |
@ -77,6 +77,11 @@ socket.on('replaceUtil', function (obj) {
|
||||
$("."+obj["mapY"]+'-'+obj["mapX"]+'.'+obj["name"]).removeClass(obj["name"]).addClass(obj["newName"]);
|
||||
});
|
||||
|
||||
socket.on('dropItem', function (obj) {
|
||||
console.log(obj);
|
||||
domMap.append('<img style="top:'+((obj["mapY"]*32))+'px; left:'+((obj["mapX"]*32))+'px; z-index:3; position:absolute;" src="./img/plain.png" i="'+obj["newName"]+'" class="'+obj["mapY"]+'-'+obj["mapX"]+' spriteItem spriteUtils '+obj["newName"]+'">');
|
||||
});
|
||||
|
||||
function addNewPlayer(player, id) {
|
||||
if($("#"+id).length==0) {
|
||||
var modeClass = "default_ship";
|
||||
|
8
s_map.js
8
s_map.js
@ -137,17 +137,17 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
var treasureSet = false;
|
||||
var treasureCnt = 5;
|
||||
var foundLand = true;
|
||||
while (!treasureSet && foundLand) {
|
||||
while (treasureCnt>0 && 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;
|
||||
if (map[w][h] == "6" && Math.random() < 0.00001 && treasureCnt>0) {
|
||||
treasureCnt--;
|
||||
utilMap[w][h] = "treasure-closed";
|
||||
console.log(w, h, "treasure")
|
||||
}
|
||||
|
89
server.js
89
server.js
@ -11,8 +11,8 @@ app.use(express.static(__dirname + '/'));
|
||||
var server = require('http').Server(app);
|
||||
var io = require('socket.io')(server);
|
||||
var map = require("./s_map.js");
|
||||
var mapWidth = 100;
|
||||
var mapHeight = 100;
|
||||
var mapWidth = 20;
|
||||
var mapHeight = 20;
|
||||
var maxX = mapWidth * 32;
|
||||
var maxY = mapHeight * 32;
|
||||
var newmap = map.generateMap(mapWidth, mapHeight);
|
||||
@ -21,6 +21,37 @@ var map = newmap["map"];
|
||||
var utilMap = newmap["utilMap"];
|
||||
var defaultMvnt = 2;
|
||||
|
||||
var items = [
|
||||
"boots1",
|
||||
"boots2",
|
||||
"boots3",
|
||||
"boots4",
|
||||
"boots5",
|
||||
];
|
||||
|
||||
var itemPlayerChanges = {
|
||||
"boots1" : {
|
||||
changeMovementLand : 1,
|
||||
text : "Geschwindigkeit an Land +1"
|
||||
},
|
||||
"boots2" : {
|
||||
changeMovementLand : 2,
|
||||
text : "Geschwindigkeit an Land +2"
|
||||
},
|
||||
"boots3" : {
|
||||
changeMovementLand : 3,
|
||||
text : "Geschwindigkeit an Land +3"
|
||||
},
|
||||
"boots4" : {
|
||||
changeMovementLand : 4,
|
||||
text : "Geschwindigkeit an Land +4"
|
||||
},
|
||||
"boots5" : {
|
||||
changeMovementLand : 5,
|
||||
text : "Geschwindigkeit an Land +5"
|
||||
},
|
||||
}
|
||||
|
||||
server.listen(PORT);
|
||||
|
||||
console.log("Pirate running on port:" + PORT);
|
||||
@ -35,10 +66,23 @@ io.on('connection', function(socket){
|
||||
y: 10,
|
||||
mvnt: defaultMvnt,
|
||||
special: {},
|
||||
mode : 0 //0 = ship //1 foot
|
||||
mode: 0, //0 = ship //1 foot
|
||||
items: {
|
||||
slot1: null,
|
||||
slot2: null,
|
||||
slot3: null
|
||||
}
|
||||
};
|
||||
var player = allPlayers[socket.id];
|
||||
io.sockets.emit("newPlayer", { player : allPlayers[socket.id], id : socket.id });
|
||||
io.sockets.emit("newPlayer", {
|
||||
player: allPlayers[socket.id],
|
||||
id: socket.id,
|
||||
items: {
|
||||
slot1: null,
|
||||
slot2: null,
|
||||
slot3: null
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
userCnt--;
|
||||
@ -104,6 +148,19 @@ io.on('connection', function(socket){
|
||||
obj["newName"] = "treasure-open";
|
||||
io.sockets.emit("replaceUtil", obj);
|
||||
socket.emit("stopAnimation", 2000);
|
||||
|
||||
let randomItem = getRandomItem();
|
||||
let nearFieldCoords = getNearEmptyField(obj["mapX"], obj["mapY"]);
|
||||
|
||||
utilMap[nearFieldCoords["y"]][nearFieldCoords["x"]] = randomItem;
|
||||
let newObj = {
|
||||
mapY: nearFieldCoords["y"],
|
||||
mapX: nearFieldCoords["x"],
|
||||
newName: randomItem
|
||||
}
|
||||
io.sockets.emit("dropItem", newObj);
|
||||
console.log("newObj", newObj)
|
||||
|
||||
}, 2000); //2 Secs
|
||||
socket.emit("animation", 2000);
|
||||
}
|
||||
@ -111,9 +168,27 @@ io.on('connection', function(socket){
|
||||
}
|
||||
player["action"] = true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function getNearEmptyField(x, y) {
|
||||
for(var i=-1;i<2;i++) {
|
||||
for(var k=-1;k<2;k++) {
|
||||
console.log("check",i, k, y+i, x+k, utilMap[y+i][x+k])
|
||||
if(utilMap[y+i][x+k] == "") {
|
||||
return {
|
||||
y : y+i,
|
||||
x : x+k
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRandomItem() {
|
||||
console.log("rnd", items.length, getRandomNumber(0, items.length), items)
|
||||
return items[getRandomNumber(0, items.length)];
|
||||
}
|
||||
|
||||
function getNearestObject(x, y) {
|
||||
var mapX = Math.floor(x / 32);
|
||||
var mapY = Math.floor(y / 32);
|
||||
@ -252,3 +327,7 @@ function getPlayerMvnt(player, groundUnderPlayer) {
|
||||
}
|
||||
return defaultMvnt;
|
||||
}
|
||||
|
||||
function getRandomNumber(min, max) { //min (inclusive) and max (exclusive)
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user