0.4.0 • Published 5 years ago
dungeon-toolkit v0.4.0
A toolkit of level generation and analysis utilities.
Map
A class representing a grid map.
Kind: global class
- Map
- new Map(w, h)
- .copy() ⇒ Map
- .indexToXY(i) ⇒ Object
- .xyToIndex(x, y) ⇒ Number
- .set(x, y, val)
- .get(x, y) ⇒ Number
- .getNeighbors(x, y, [dist]) ⇒ Array
new Map(w, h)
Construct a map.
Param | Type | Description |
---|---|---|
w | Number | The width of the map. |
h | Number | The height of the map. |
map.copy() ⇒ Map
Make a copy of this map.
Kind: instance method of Map
Returns: Map - The copy of this map.
map.indexToXY(i) ⇒ Object
Returns an x,y coord for a index in the array representing the map.
Kind: instance method of Map
Returns: Object - x,y coord.
Param | Type | Description |
---|---|---|
i | Number | The index to turn into an x,y coord. |
map.xyToIndex(x, y) ⇒ Number
Turns an x,y coord into an index into the values array.
Kind: instance method of Map
Returns: Number - The index.
Param | Type | Description |
---|---|---|
x | Number | The x coord. |
y | Number | The y coord. |
map.set(x, y, val)
Set a value in the values array by x,y.
Kind: instance method of Map
Param | Type | Description |
---|---|---|
x | Number | The x coord of the tile to set. |
y | Number | The y coord of the tile to set. |
val | Number | The value to set for the tile. |
map.get(x, y) ⇒ Number
Get a tiles value from the map by x,y.
Kind: instance method of Map
Returns: Number - The tile value at x,y.
Param | Type | Description |
---|---|---|
x | Number | The x coord. |
y | Number | The y coord. |
map.getNeighbors(x, y, dist) ⇒ Array
Get all neighbors for the tile within dist.
Kind: instance method of Map
Returns: Array - An array of tile objects.
Param | Type | Default | Description |
---|---|---|---|
x | Number | The x coord. | |
y | Number | The y coord. | |
dist | Number | 1 | The distance to find neighbors within. |