- Project page
- Tutorial[1]
- Repo[2]
Part 9 has a lot going on.
There’s a new command, three new items, and a new behavior:
- a “look” command that lets you look around the map
- ranged attack where the enemy is chosen automatically
- confusion spell where the interface lets you pick an enemy
- ranged attack where the interface lets you pick a location
- a confusion “ai” that changes the enemy behavior
I used Jujutsu to go back to an earlier change and clean up the event handlers in preparation for these changes.
Instead of making an object hierarchy for these new consumable items, I made a consumable optional component, and I used a switch (consumable.type) statement to choose what behavior to apply. This means all consumable behavior is in one place instead of scattered among multiple classes. There are pros and cons of this “union + pattern matching” style, but I generally prefer it over inheritance hierarchies. Scroll to the end of the page to see health_potion, confusion_scroll, etc. defined in the prototype table.
The async/await approach from Part 7 worked very nicely for these new interactions.
I also spent some time making the rest of the table editable, and then added a flag for entities to block the field of view. Try these things:
- Change your hp.
- Make potions block your view.
- Pick up an item by editing its location to held by 1.
- Change the type of a orc into an troll.
- Change the color or shape of a potion.
- Make orcs have higher defense.
- Make corpses holdable, and then go pick one up.
Here’s the game at the end of Part 9: