aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2019-12-09 20:57:21 -0500
committerMatt Kohls <mattkohls13@gmail.com>2019-12-09 20:57:21 -0500
commitc8a5d3a7597fc5b943a04e13aa8f3b01afdb3c48 (patch)
tree646d763c0972739f2f36eb42019bbd35ce4d955d
parenta5c786cc8a621ae70425a7795592ecfdfb1758ac (diff)
downloadrogue.js-c8a5d3a7597fc5b943a04e13aa8f3b01afdb3c48.tar.gz
rogue.js-c8a5d3a7597fc5b943a04e13aa8f3b01afdb3c48.tar.bz2
rogue.js-c8a5d3a7597fc5b943a04e13aa8f3b01afdb3c48.zip
Lots of improvements and bug fixes
Staff is now goal, and is given when trying to go down bottom stairs. Moving between floors now puts character on correct stairs. +'s and other symbols are now rendered on client. Mobs now have a type, and client will pick a proper sprite for them. Crashing on undefined action should be fixed.
-rw-r--r--floors.json11
-rw-r--r--public/index.html2
-rw-r--r--public/js/rogue.js59
-rw-r--r--public/styles/simple.css2
-rw-r--r--rogue-server.js121
5 files changed, 142 insertions, 53 deletions
diff --git a/floors.json b/floors.json
index 5a5e01c..db5f9e3 100644
--- a/floors.json
+++ b/floors.json
@@ -1,5 +1,12 @@
-[
+{
+ "maps":[
"***************************************************************************************************** *** *** ** ** ***************** * ******* *** ***** **** * * ** *** *** ** **** * * ******* * * ****** ********* *** * * * ** ** * ** ***** * ***** * ** *** ****** * **** ** * ** *** * ***** * * * *** ** ** *** * **** **** ** **** ** ***** * * **** * ** * ****** *** * * < * ******* * *** **** * * **** * ** **** * ** ****** *** * ** ******* * ** **** * * ******* * *** **** * *** ** * *** * ********** ** ****** ***** ****** * *** ***** * ***** *** * ** **** **** * *** ** *********** ****** * *** ****** ***** ** * ** **** *** *** *** ** ******* ** *** ** * *** ****** * * * * ** * *** **** ****** *** ** ** * ** * ***** ** ******* *** ** ** * * * * * **** ** *** ** **** * * *** *** * *** * *** ** ** *** ***** * *** ****** * ** ** *** *** * **** *** ** ** ** *********** *** ****** * *** ** ** * ** * **** ****** ***** ** **** ** ****** ********** **** ******** ** ** * **** ** ******* **** ** **** * * ***** ** * ******** **** * ******** * **** ** * ** ** *** * ** *** * ********* **** ***** *** ****** ***** * * **** ****** * **** ********* * * ******** ****** ****** ** *** *** * **** * ******* ******* ** ** * * * ***** ************** * ** **** ** ** **** * **** * ******* ** * ** ** *** *** ****** **** * **** **** **** * ** * **** ***** *** * * ** * ** ** **** ***** **** ** **** **** * * * *** * * ****** ** * * * ****** **** ******* ** * *** **** ** * * **** * * * *** * * ** ******** ****** ** ** ******** ** ** ** * * **** *** * ** * * ************ **** **** * ****** * ** ** * *** * **** ** * ******* * ********** **** * ******* * ** * *** *** * *** ***** ** ********** *** ******** *** * ** ******* * ** *** * **** * *** ******* * *** ** ***** ** ******** * *** * **** * *** *** ***** * ***** * ** ** ***** * * *** **** **** * ***** * * * * * ** ****** * * * * **** * * ******** ***** * ****** ** ** ****** * ** * *** * **** ** *** *** ***** * ***** > * * * *** ******** * ** *** * ***** *** ****** ****** ** * * * ** *** ***** ** * * ***** ** ****** ****** * ** **** ** ** * * * *** ** * ***** *** * ***** * ** * ************* * * * * ** ** * ********** * ** * ****** * * *** * ********** **** * * * ****** * ****** **** *** ****** * ** ** * * * ** * **** ** * ** ***** * *** ** **** **** *** ** * * * *** * ** * ** ** * ***** * * *** ** *** *** * *** * * ** * * * * * * * * ** *** ******* ***** ******* ** ** *** ***** * * * *****************************************************************************************************",
"***************************************************************************************************** ****** ****** ** ***** ** ***************** *** ********** *** ** ***** **** * ***** ** ***** **** **** ***** ***** *** * *** ** * * ******* ** ***** **** ***** **** ******* *** * * **** * ** **** * *** ***** ****** ** * ** ********* **** ** * *** * **** ** **** *** *********** ***** * ***** ** **** **** * *** **** * ** **** ******** *********** **** * ******* ** *** ****** *** ** ****** ** ****** ** ***** **** ***** **** ******* *** *** ******** *** * * ****** ***** ******* * * ****** ** *** ********* ******** *** ****** *** * * > * * *** * ** ******** ** ***************** ****** ** * * * ** * **** * * ** ** *** * ****** ** ******* ****** *** *** * * * * * * * ** * * ******** **** ***** * ** * * ****** *** *** ** * * **** *** * ** ****** ***** ** ** ** * * * ****** *** *** ***** *** * ** * *** * ** * ** * * *** ** *** ** ** *** ***** ** ******** *** ******* * *** * * * * * ** ** *** *** ** * *** * * ** ***** **** ******* *** ** * * **** * ** ** ** * ** ** ***** * * * ** **** ****** *** ** * ****** * ** *** ** ***** ** **** ******* * ** * **** * ***** * ********** *** ** ***** ** **** ** **** * * ** ********* * ** ** * ********* * ** ***** ** **** ******** * * ******** * *** * * * ******** * * ** ***** ** ***** *** ** ** ***** ** ** **** *** * * * ** ***** ******** ** ** *** ***** ** ** *** * **** **** *** *** ******* ** ********** ** ******* ***** *** **** ***** * ******** * ** ** **** ** **** ** *** * ***** *********** ***** * * ***** * * * * **** ** * ***** *** ** ***** **************** * ** ****** **** * * * **** *** ******* ***** ** ** * * ******* ** ** *** ***** ***** * * * ** ** * * ****** ** **** * **** * ** **** * ** *** ******* **** * * * * * * * ******* **** * **** **** ****** *** ** ******* ** *** * * * * * ********** * * ***** * **** **** * ******* *** ** * *** * * * * ***** ** ** **** ***** ************ ** ** * * * * * * * * * **** * ** * **** ****** ********* * * ** * * ** ** ** ** * *** *** ** * *** ** *** **** ** * * ** ** * * * * **** * ***** ** *** * * ** ****** * * * * ** ** ** * * **** **** ****** ** *** * ** ** *** * * ** * ** * *** ** **** ****** * ** **** ** ** *** ***** * * * *** ***** ** * * ** ****** * ** * *** **** ** * * * * ***** * * * * ** *** * *** *** ** * * * * < **** * * * * * **** * ** * ******** **** ** ********* **** * *****************************************************************************************************",
"***************************************************************************************************** * ***** * ** ********** ****** ****** **** ****** ** **************** ********** ** ******* * ** ******* ******** * ** *** * *** * ****** ******** * ****** ** ********** ** ****** ******** * * * * * ****** **** ** ********** ********* ********** ** **** **** ** > * ** **** * ** * ******* ******* ******* *** ** **** * *** * ** * ** ** ***** ** ** **** * *** * ***** **** * * * * ****** **** ** * ****** ** **** **** * ** * * * ***** ** **** * ** ***** **** ** **** **** * *** *** ** * * ***** * ** *** * * ** * * **** *** * ***** *** ** * ** ****** *** < * * * ** *** ** ** * * * *** * * ***** ** ** * ** ** ***** ** * *** * ** **** * ** ** ** ** ** * * ** ** ** ** ** *** *** * * * ***** * * * **** **** * * * ** ** * ** ** ** ** *** ** * ** ** * * **** **** * * * ** * * *** ** *** ** ******** * * *** * **** * ***** * * * * * ** *** ****** ** * **** * *** ** ******* * ***** * * ** * * * *** ** ** ** ** **** * *** ** ********* * * ** * * * * ** ** ** ***** *** ****** *** ***** * *** *** * * *** ** ****** ** ** **** ******* ****** *** * * ** *** ** * * ** * * ** * ***** * ****** * * ****** *** *** ** * * ** ** * ** * ***** ** ** * * * * * ***** *** ** ** ** * **** *** * * * **** ** * *** ** * ** *** ** * ***** ** ** *** * **** *** * ** * *** * *** ** * * **** *** ***** * ** ** ************ * *** * ** ** **** **** *** *** ******** *** ********* * **** * ** ** *********** *** ***** *********** * ***** ** * * * ** * * * ******* * **** *** ***** ** * * *** * ** * * **** * ** * * ***** ** ** *** ***** * *** *** * ** * ** * ******** ** * ** ** * ** * ** **** ** ** *** * * * * ** *** * * ** * ** * *** * **** ******** ** **** ** ** ** ** ** *** * *** * *** ****** ******** * ** **** ****** ******** ** * **** * * ** * *** ****** ******** * * ** ****** *** **** *** **** ** * * * * * ****************** * ** ****** ** ** * * *** ** * * * * *** ** *********** *** ** * * ** ** **** *** * * * * * * ** ** ********** *** ** **** ****** * *********** * * ** * *** * *** ** * ********** ***** ** ******* ***** ** ********* ** * ***** * *** * ******* *** **** **** ***** **** ***** **** * * ************ *** ** *** ******* ******** ***** ***** ** * ** ***** * * ***** *** ** * ** * *** * * ***** ** ********** *** ***** ********* ** ****** ***** *****************************************************************************************************"
-]
+],
+ "stairs":[
+ {"dx":44, "dy":30, "ux":77, "uy":5},
+ {"dx":68, "dy":9, "ux":33, "uy":37},
+ {"dx":55, "dy":4, "ux":64, "uy":9}
+ ]
+}
diff --git a/public/index.html b/public/index.html
index e8adc13..47bcec0 100644
--- a/public/index.html
+++ b/public/index.html
@@ -12,6 +12,7 @@
<div class="center">
<h1>rogue.js</h1>
</div>
+ <pre id="messages" style="height: 100px; overflow: scroll"></pre>
<canvas id="gameboard" class="center" width="512" height="416"></canvas>
<div class="center">
<table class="center">
@@ -23,7 +24,6 @@
</tr>
</table>
</div>
- <pre id="messages" style="height: 400px; overflow: scroll"></pre>
<footer><p>&copy; Matt Kohls, 2019</footer>
<script src="js/rogue.js"></script>
</body>
diff --git a/public/js/rogue.js b/public/js/rogue.js
index d627c18..3564103 100644
--- a/public/js/rogue.js
+++ b/public/js/rogue.js
@@ -242,20 +242,36 @@ function drawInitialBoard() {
drawSprite(nothing, i, j, false);
}
}
- for(var i = 5; i < 30; i++) {
- for(var j = 2; j < 10; j++) {
- drawSprite(dirt, i, j, false);
- }
- }
for(var i = 0; i < 32; i++) {
drawSprite(wall[0], i, 0, false);
- drawSprite(wall[1], i, 25, false);
+ drawSprite(wall[0], i, 25, false);
}
for(var j = 0; j < 26; j++) {
- drawSprite(wall[2], 0, j, false);
- drawSprite(wall[2], 31, j, false);
+ drawSprite(wall[0], 0, j, false);
}
+ drawSprite(players[0], 4, 7, false);
+ renderText("This is you", 6, 7);
+ drawSprite(players[1], 4, 8, false);
+ renderText("These are other players", 6, 8);
+ drawSprite(zombie, 4, 9, false);
+ renderText("Watch out for monsters", 6, 9);
+
+ drawSprite(stairsup, 4, 11, false);
+ drawSprite(stairsdown, 4, 12, false);
+ renderText("Stairs allow you to move", 6, 11);
+ renderText("between floors", 6, 12);
+
+ drawSprite(potion, 4, 14, false);
+ renderText("Using a potion heals you", 6, 14);
+ drawSprite(sword, 4, 15, false);
+ renderText("Moving into someone attacks", 6, 15);
+ renderText("them", 6, 16);
+
+ drawSprite(staff, 4, 18, false);
+ renderText("Find the staff and return", 6, 18);
+ renderText("to the surface", 6, 19);
+
drawPlayerInfo();
}
@@ -305,7 +321,22 @@ function drawMap() {
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);
+ var sprite;
+ switch(mobs[i].type) {
+ case "player":
+ sprite = players[1];
+ break;
+ case "zombie":
+ sprite = zombie;
+ break;
+ case "slime":
+ sprite = slime;
+ break;
+ default:
+ sprite = rat;
+ break;
+ }
+ drawSprite(sprite, 11 + mobx, 13 + moby, false);
}
}
@@ -468,6 +499,16 @@ function renderText(message, x, y) {
sprite = indexSprite(lower, character - 97);
} else if(character == 45) {
sprite = indexSprite(symbol, 21);
+ } else if(character == 43) {
+ sprite = indexSprite(symbol, 20);
+ } else if(character == 46) {
+ sprite = indexSprite(symbol, 5);
+ } else if(character == 44) {
+ sprite = indexSprite(symbol, 6);
+ } else if(character == 33) {
+ sprite = indexSprite(symbol, 7);
+ } else if(character == 63) {
+ sprite = indexSprite(symbol, 8);
}
// TODO: Add other symbols
}
diff --git a/public/styles/simple.css b/public/styles/simple.css
index 490e115..f342e78 100644
--- a/public/styles/simple.css
+++ b/public/styles/simple.css
@@ -48,7 +48,7 @@ p {
}
table, th, td {
- border: 1px solid black;
+ border: 0px solid black;
}
th, td {
diff --git a/rogue-server.js b/rogue-server.js
index 4978895..717669b 100644
--- a/rogue-server.js
+++ b/rogue-server.js
@@ -46,10 +46,10 @@ class Item {
get name() {
var name = "";
- if(this._bonus > 0) {
+ if(this._bonus >= 0) {
name = name + "+" + this._bonus;
} else if(this.bonus < 0) {
- name = name + "-" +this._bonus;
+ name = name + this._bonus;
}
return name;
}
@@ -80,7 +80,7 @@ class Action {
class Mob {
- constructor(strength, dexterity, constitution, intelligence, wisdom, level, location, uuid) {
+ constructor(strength, dexterity, constitution, intelligence, wisdom, level, location, uuid, type) {
this.strength = strength;
this.dexterity = dexterity;
this.constitution = constitution;
@@ -99,6 +99,7 @@ class Mob {
this.weapon = null;
this.staff = null;
this._uuid = uuid;
+ this._type = type;
}
stats() {
@@ -209,6 +210,8 @@ class Mob {
get uuid() { return this._uuid; }
+ get type() { return this._type; }
+
attack(type) {
if(type == "weapon") {
if(this.weapon != null) {
@@ -283,6 +286,14 @@ class Mob {
return "Aquired: " + item.name;
}
}
+
+ hasStaff() {
+ if(this.staff != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
/** Turn generation **/
@@ -355,20 +366,30 @@ function move(mob, dir) {
location.x = location.x + 1;
break;
case '.':
- var symbol = floors[location.floor].charAt(location.y * 100 + location.x);
+ var symbol = floors.maps[location.floor].charAt(location.y * 100 + location.x);
if(symbol == '>') {
- location.floor = location.floor + 1;
- if(location.floor > floors.length - 1) {
- return "Already at bottom floor";
+ var newfloor = location.floor + 1;
+ if(newfloor > floors.maps.length - 1) {
+ if(mobs[mob].hasStaff()) {
+ return "You look again, but you already found the staff";
+ } else {
+ mobs[mob].pickUp(new Item(5, "staff"));
+ return "Hiding behind the fake stairs was THE STAFF! Return through the stairs on the top floor!";
+ }
}
- mobs[mob].location = location;
+ mobs[mob].location = new Location(floors.stairs[newfloor].ux, floors.stairs[newfloor].uy, newfloor);
return "Go down the stairs";
} else if(symbol == '<') {
- location.floor = location.floor - 1;
- if(location.floor < 0) {
- return "Already at top floor";
+ var newfloor = location.floor - 1;
+ if(newfloor < 0) {
+ if(mobs[mob].hasStaff()) {
+ // TODO: Add some flag for exiting dungeon
+ return "You exit the dungeon, wielding THE STAFF!";
+ } else {
+ return "You don't want to give up finding the staff already";
+ }
}
- mobs[mob].location = location;
+ mobs[mob].location = new Location(floors.stairs[newfloor].dx, floors.stairs[newfloor].dy, newfloor);
return "Go up the stairs";
}
break;
@@ -378,7 +399,7 @@ function move(mob, dir) {
if(location.x < 0 || location.x > 99 || location.y < 0 || location.y > 39) {
return "Hit a wall";
}
- if(floors[location.floor].charAt(location.y * 100 + location.x) == '*') {
+ if(floors.maps[location.floor].charAt(location.y * 100 + location.x) == '*') {
return "Hit a wall";
}
for(var i = 0; i < mobs.length; i++) {
@@ -407,32 +428,36 @@ function performActions(init) {
if(mobs[mob].action == null) {
message = "You sit";
}
- switch(mobs[mob].action.type) {
- case 'wait':
- message = "You sit";
- break;
- case 'move':
- message = move(mob, mobs[mob].action.message);
- break;
- case 'cast':
- cast(mob, mobs[mob].action.message);
- break;
- case 'drink':
- message = mobs[mob].drinkPotion();
- break;
- case 'pick':
- // TODO: Allow for pickups boi
- //message = mobs[init[i][j]].pickUp();
- break;
- case 'drop':
- message = "Item dropped";
- mobs[mob].drop(mobs[mob].action.message);
- default:
- message = "You sit";
- break;
+ if(typeof mobs[mob].action !== 'undefined' || mobs[mob] != null) {
+ switch(mobs[mob].action.type) {
+ case 'wait':
+ message = "You sit";
+ break;
+ case 'move':
+ message = move(mob, mobs[mob].action.message);
+ break;
+ case 'cast':
+ cast(mob, mobs[mob].action.message);
+ break;
+ case 'drink':
+ message = mobs[mob].drinkPotion();
+ break;
+ case 'pick':
+ // TODO: Allow for pickups boi
+ //message = mobs[init[i][j]].pickUp();
+ break;
+ case 'drop':
+ message = "Item dropped";
+ mobs[mob].drop(mobs[mob].action.message);
+ default:
+ message = "You sit";
+ break;
+ }
}
}
- mobs[mob].action = new Action('done', message);
+ if(mobs[mob] != null) {
+ mobs[mob].action = new Action('done', message);
+ }
}
}
}
@@ -448,7 +473,7 @@ function buildPlayerMsg(character) {
function buildTurnMsg(character, mobmsg) {
var local = character.location.floor;
- var message = "{\"map\":\"" + floors[local] + "\",";
+ var message = "{\"map\":\"" + floors.maps[local] + "\",";
message = message + character.stats();
if(character.action != null) {
message = message + ",\"msg\":\"" + character.action.message + "\"";
@@ -465,7 +490,7 @@ function buildTurnMsg(character, mobmsg) {
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 + "}";
+ mobmsg += "{\"x\":" + mobs[i].location.x + ",\"y\":" + mobs[i].location.y + ",\"floor\":" + mobs[i].location.floor + ",\"type\":\"" + mobs[i].type + "\"}";
if(i != mobs.length - 1) {
mobmsg += ",";
}
@@ -529,8 +554,24 @@ wsServer.on('connection', function connection(ws, request) {
players.set(id, ws);
device.set(ws, id);
var local = new Location(78, 5, 0);
- var character = new Mob(genStat(), genStat(), genStat(), genStat(), genStat(), 1, local, id);
+ var character = new Mob(genStat(), genStat(), genStat(), genStat(), genStat(), 1, local, id, "player");
character.addPotions(5);
+ var rand = Math.floor(Math.random() * 19) + 1;
+ if(rand > 15) {
+ character.pickUp(new Item(1, "weapon"));
+ } else if(rand == 1) {
+ character.pickUp(new Item(-1, "weapon"));
+ } else {
+ character.pickUp(new Item(0, "weapon"));
+ }
+ rand = Math.floor(Math.random() * 19) + 1;
+ if(rand > 15) {
+ character.pickUp(new Item(1, "armor"));
+ } else if(rand == 1) {
+ character.pickUp(new Item(-1, "armor"));
+ } else {
+ character.pickUp(new Item(0, "armor"));
+ }
ws.send(buildPlayerMsg(character));
mobs.push(character);
console.log(new Date().toUTCString() + ' | ' + device.get(ws) + ' joins');