Skip to main content

Directions

Direction · 2 bits of value; stored as a word for the party, a byte for monsters and script operands

Blocks, directions and positions · LevelBlockRuntime · MonsterRuntime

The game numbers the four compass directions clockwise from north. The same values give the party's facing, a monster's facing, the step to a neighboring block and the side of a block that a wall reference belongs to. Turning adds or subtracts one, modulo 4.

/* A compass direction (values 0–3; arithmetic is done modulo 4). */
typedef enum Direction {
DIRECTION_NORTH = 0, /* Neighbor: row − 1, block index − 32. */
DIRECTION_EAST = 1, /* Neighbor: column + 1, block index + 1. */
DIRECTION_SOUTH = 2, /* Neighbor: row + 1, block index + 32. */
DIRECTION_WEST = 3 /* Neighbor: column − 1, block index − 1. */
} Direction;

Row 00 is the northern edge of a level and column 00 its western edge, so [00:00] is the north-west corner. Positions are written [XX:YY], column then row; block index = YY × 32 + XX.

Relative directions​

For a facing d:

Relative directionValueExample, facing DIRECTION_NORTH
AheaddDIRECTION_NORTH
Right(d + 1) & 3DIRECTION_EAST
Behind(d + 2) & 3DIRECTION_SOUTH
Left(d + 3) & 3DIRECTION_WEST

The party's "turn left" and "step left" buttons use d − 1, the right ones d + 1. When the party looks at the block ahead, it sees that block's (d + 2) & 3 side, the side turned towards it.

Where it is used​

Edge case​

The neighbor routine wraps the block index to 0–1,023 without checking the row: stepping east from column 31 leads to column 0 of the next row, and stepping north from row 0 to row 31. A level whose edges are not closed by walls would therefore connect its opposite sides this way.

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references.

The neighbor routine and its direction steps; the compass shapes and compass drawing; the visible blocks and the view setup; the movement buttons; the monster patrol modes. Comparative source: generateBlockDrawingBuffer in REF-SCUMM-016.