fennel-ray-casting/mapper.fnl
2024-10-10 14:17:16 -04:00

27 lines
932 B
Fennel

;Generate a map of width by height:
(fn print_map [map]
(for [i 1 (length map)]
(var r "")
(for [j 1 (length (. map i))]
(set r (.. r " " (. map i j))))
(print r)))
; Function to generate the map. From here, all additional functions are used.
(fn generate [height width]
(var map [])
; Generate the outside shell. This is actually a double-lined outer layer. The
; outer-most layer allows for a single-square transitional tile, used as the
; entry/exit spot to the map.
(for [i 1 (+ height 2)]
(tset map i [])
(for [j 1 (+ width 2)]
(var tile 0) ; By default, draw an empty space
(when (or (= i 1) (= i 2) (= i (+ height 1)) (= i (+ height 2))) (set tile 1)) ; The first and last rows
(when (or (= j 1) (= j 2) (= j (+ width 1)) (= j (+ width 2))) (set tile 1)) ; The first and last rows
(tset map i j tile)))
; Add in "set pieces": structures or
map)
(print_map (generate 20 20))
{: generate}