- Project page
- Tutorial[1]
- Repo[2]
Part 11 is both dungeon levels and player levels. To reduce confusion, I renamed dungeon levels to “floors”.
For dungeon floors things went pretty smoothly:
- Stairs are just another tile type (but being a tile type, any item on the floor hides them).
- The > command checks if there are stairs, and moves down a floor.
- Moving down a floor means deleting all entities that aren’t the player OR aren’t held by the player. In SQL this could be a database query but my Table class doesn’t support the types of queries I would need, so I iterated over all entities instead.
For player levels things went pretty smoothly:
- The player can increase their stats at level up time, but the stats are at the prototype level. I made the
fightercomponent work as either a prototype-level column (for trolls/orcs) or an entity-level column (for the player). This works because Javascript prototype inheritance lets the entity level fields hide the prototype level fields. - I added a dialog box to choose how to level up the same way I added the other dialog boxes. The level up code calls statToIncrease = await Layer.levelup.waitForAnswer() which pauses execution until the dialog box returns an answer.
- The character screen is another dialog box.
I was hoping to make the player level calculation a spreadsheet formula that you can edit in the UI. As part of “embrace Javascript features”, I was planning to use two Javascript features for this: new Function() and the with statement. Here’s how it’d look:
let formula = "250 + 100 * level"; // editable in UI
let player = {level: 5};
let xpRequired = new Function("entity", "with(entity) return " + formula);
return xpRequired(player);
However it turned out to be trickier to integrate into the game loop than I hoped, so I didn’t implement it.
I had some extra time so I decided to show the table showing the map tiles. It’s a big table so I only show a subset of it. But it’s fun to go change the prototypes of those map tiles. For example, try making walls transparent, and change the shape character for the walls.
Here’s the game at the end of Part 11: