ThePix / QuestJS

A major re-write of Quest that is written in JavaScript and will run in the browser.
MIT License
74 stars 16 forks source link

Evolution: Customize available directions in a zone (for instance to disallow diagonal moves) #17

Closed Kln95130 closed 3 years ago

Kln95130 commented 4 years ago

I really struggled on how to represent the player moving down "long" rooms like hallways or streets, and your newest feature will definitely bring a lot of quality-of-life in that area. Same with the map builder feature.

I keep watching your updates now and then, and I appreciate your continuous work for this framework. I hope you will be able to see it through.

Kln95130 commented 4 years ago

Proposition: I would like to experiment the player moving in an old school grid pattern, meaning only north, east, south, and west. For now, I can handle it through a BORDER and some math, but that could be something more easily customizable. It could be something simple, like an attribute that takes an array of strings, and whose default value would be ["n", "ne", "e", "se", "s", "sw", "w", "nw"]. Then, a check "if dirList.contains(dir)" to check if the direction is available.

I can also see a potential for NPCs "patrolling" the area. Maybe even rudimentary AI that reacts to the player being in range. It might need some effort to make it work without any custom code, however.

Kln95130 commented 4 years ago

I take the liberty to answer on my own message, as I found a solution for the customization of the exit list.

Add a falcutative list of blocked directions to ZONE, then check the direction.

const ZONE = function(defaultToBlocked, blockedDirs=[]) {
  const res = {
// ...
    blockedDirs: blockedDirs
  };

Then

 res.hasExit = function(dir, options) {
// ...
    // Non-compass directions not allowed
    if (this.blockedDirs.includes(dir) || this.defaultToBlocked || this[dir].data.type !== 'compass') {
      return false
    }

Which gives us, for a zone that forbids diagonal moves:

ZONE(false, ["northeast", "northwest", "southeast", "southwest"])
ThePix commented 4 years ago

One way to do this would be in Zone.js, at line 84, instead of iterating over all exits, just iterate over the ones you want. Or even, forget iterating - there is only four, set each one yourself.

ThePix commented 3 years ago

I think this has been resolved (and indeed was back in July), so I am closing. Re-open if it is still an issue.