Maze - gegerlan/aog GitHub Wiki

Detail

Filename Author Version Core Update Last Patch Update Active contributor
Maze.rb gegerlan 1.0 - - YES

Version history

Summary

Find a random path between two points in a 2-dimensional array. Avoids collision with itself, and makes sure paths don't overlap.

Rationale

In an earlier version of the game, a quest had the player follow specific directional instructions to progress. These instructions were hardcoded, and players could easily brute force their way through the invisible maze.

As the quest was re-introduced, a pathing script was written to mimic the idea of having to follow a specific set of direction to reach ones goal.

Rather than having a real maze, a simple random path script was made to keep it inline with the original quest.

Iterface

Maze.new(width, height)

Creates a new maze with the provided units. Each unit is considered a non-/walkable area.

Returns Maze.

plot(start, stop)

Calculates the path between start and stop.

Start is an array with the [x, y] value where the maze starts.

End is an array with the [x, y] value where the maze stops.

Returns TRUE if successful, else FALSE.

paint(callback)

Iterates over all units in the map, and passes it to the callback with a boolean if the tile is a passage.

Callback is a .call-able (e.g. lambda, proc) object that takes three parameters y (integer, current maze's y-position), x (integer, current maze's x-position), path (boolean, if the current position is a part of the path connecting start with end position).