diff options
-rw-r--r-- | public/js/rogue.js | 10 | ||||
-rw-r--r-- | rogue-server.js | 15 |
2 files changed, 24 insertions, 1 deletions
diff --git a/public/js/rogue.js b/public/js/rogue.js index 5a9896e..d627c18 100644 --- a/public/js/rogue.js +++ b/public/js/rogue.js @@ -135,6 +135,7 @@ function showMessage(message) { function parseMessage(message) { var msg = JSON.parse(message); map = msg.map; + mobs = msg.mobs; player = new Player(msg.strength, msg.dexterity, msg.constitution, msg.intelligence, msg.wisdom, msg.level, msg.x, msg.y, msg.floor, msg.hp, msg.ac, msg.potions, msg.armor, msg.weapon, msg.staff); if(msg.msg != "" && msg.msg != "undefined") { showMessage(msg.msg); @@ -232,6 +233,7 @@ spritemap.onload = drawInitialBoard; spritemap.src = 'scroll-o-sprites-edited.png'; var gamemap; +var mobs; var player = new Player(10, 10, 10, 10, 10, 1, 0, 0, 1, 100, 15, 0, "none", "none", "none"); function drawInitialBoard() { @@ -299,6 +301,14 @@ function drawMap() { localX++; } + for(var i = 0; i < mobs.length; i++) { + if(mobs[i].floor == player.floor) { + var mobx = mobs[i].x - player.x; + var moby = mobs[i].y - player.y; + drawSprite(players[1], 11 + mobx, 13 + moby, false); + } + } + drawSprite(players[0], 11, 13, false); } diff --git a/rogue-server.js b/rogue-server.js index a490d25..4978895 100644 --- a/rogue-server.js +++ b/rogue-server.js @@ -443,6 +443,10 @@ function performActions(init) { * @param character The mob the player is in charge of */ function buildPlayerMsg(character) { + return buildTurnMsg(character, ",\"mobs\":[]"); +} + +function buildTurnMsg(character, mobmsg) { var local = character.location.floor; var message = "{\"map\":\"" + floors[local] + "\","; message = message + character.stats(); @@ -451,6 +455,7 @@ function buildPlayerMsg(character) { } else { message = message + ",\"msg\":\"\""; } + message += mobmsg; return message + "}"; } @@ -458,10 +463,18 @@ function buildPlayerMsg(character) { * Send out action results to all players */ function sendResults() { + var mobmsg = ",\"mobs\":["; + for(var i = 0; i < mobs.length; i++) { + mobmsg += "{\"x\":" + mobs[i].location.x + ",\"y\":" + mobs[i].location.y + ",\"floor\":" + mobs[i].location.floor + "}"; + if(i != mobs.length - 1) { + mobmsg += ","; + } + } + mobmsg += "]"; for(var i = 0; i < mobs.length; i++) { if(players.has(mobs[i].uuid)) { console.log(new Date().toUTCString() + ' | sending turn data to ' + mobs[i].uuid); - players.get(mobs[i].uuid).send(buildPlayerMsg(mobs[i])); + players.get(mobs[i].uuid).send(buildTurnMsg(mobs[i], mobmsg)); } } } |