Generate a maze and display it with the raycaster

This commit is contained in:
Bill Niblock 2024-10-30 18:53:30 -04:00
parent a5c2a4c825
commit d9f69ecbd6
3 changed files with 238 additions and 40 deletions

View file

@ -118,10 +118,70 @@ Each cell is a combination of hallways and walls. For each cell, if the "row" or
```lisp
(var cell [])
(for [i 1 cell-size]
(for [j 1 cell-size]
(var cell-index (+ j (* (- i 1) cell-size)))
(if (and (< i (+ hall-width 1)) (< j (+ hall-width 1)))
(tset cell cell-index 0)
(tset cell cell-index 1))))
(each [k v (ipairs meta-cells)]
(var row-limit (if (. v :e) (+ hall-width wall-width) hall-width))
(var col-limit (if (. v :s) (+ hall-width wall-width) hall-width))
(for [i 1 cell-size]
(for [j 1 cell-size]
(var cell-index (+ j (* (- i 1) cell-size)))
(if (and (< i (+ col-limit 1)) (< j (+ row-limit 1)))
(tset cell cell-index 0)
(tset cell cell-index 1))
(if (and (> i hall-width) (> j hall-width))
(tset cell cell-index 1))))
```
This becomes a bit more challenging with considering connections. It is likely a
matter of modifying the conditional such that: when there is a horizontal
connection, check for `i` to be less than the entire cell width (`hall-width` +
`wall-width`); and then similar for `j` with vertical connections. However, this
will then remove the corner wall when there are both vertical and horizontal
connections. This could be solved by checking if both `i` and `j` are beyond
`hall-width`, which would represent the always corner.
The above code should translate from a `meta-cells` list of meta-data to a
`cells` list of 0's and 1's.
---
With a bit of modification, the logic for the maze generation from above appears
to work. There is one challenge which remains, which is updating the walls. A
way around this is to make the data about the next cell more verbose: include
not only the cell number, but also the direction. Then, use a case statement to
update accordingly.
The last remaining tasks are to buffer the entire maze, such that there are two
cells worth of walls around it; and to establish starting and ending squares.
Creating the buffer means adding two cells worth of walls to the north and west
walls, and 1 cell worth of walls to the south and east walls. This should
theoretically be very easy using `table.insert`, which automatically modifies
all further table values. However, will need to be mindful when updating east
and west. Updating north is just `(table.insert 1 1)` for `(* cell-num cell-size
cell-size)` times twice. Similar for south, except `(table.insert 1)` for `(*
cell-num cell-size cell-size)` once. East and west seem more challenging.
Though, thinking about it for a moment, I could essentially migrate the
generated array one "row" at a time into a new array, padding it on either side
as I do so. I believe this may be the way. I can use `table.move` to accomplish
this.
As part of the padding, I also need to translate the map from a single list into
a list of lists. Again, this can be done using the `table.move` function and
`table.insert`.
```lisp
(var map [])
(var map-row [])
(table.move cell_map x y 1 map-row)
(table.insert map map-row)
```
---
Remaining tasks:
1. Finalize map generation:
[X] Establish starting spot, and add the northern feature spawn point.
[X] Establish ending spot, and add the southern feature finale point.
[ ] Could do an eastern and western spot too
[ ] Modify the map wall values to account for random wall heights.
2. Draw floors
3. Draw skyboxen
4. Add monster mechanics