Make 3d mazes more 'branchy'

This commit is contained in:
Starbeamrainbowlabs 2020-04-30 01:59:23 +01:00
parent 6b39c130b6
commit f3a1874ab0
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -92,12 +92,16 @@ function M.generate_maze(seed, width, height, depth)
if cx + 2 < width and world[cz][cy][cx + 2] == "#" then if cx + 2 < width and world[cz][cy][cx + 2] == "#" then
directions = directions .. "r" directions = directions .. "r"
end end
-- If this is 1 or less, then we will switch our attention to another candidate node after moving
local shift_attention = math.random(0, 3)
--print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode) --print("radar output: '" .. directions .. "' (length: " .. #directions .. "), curnode: " .. curnode)
if #directions > 0 then if #directions > 0 then
-- we still have somewhere that we can go -- we still have somewhere that we can go
local curdirnum = math.random(1, #directions) local curdirnum = math.random(1, #directions)
local curdir = string.sub(directions, curdirnum, curdirnum) local curdir = string.sub(directions, curdirnum, curdirnum)
if curdir == "+" then if curdir == "+" then
world[cz + 1][cy][cx] = " " world[cz + 1][cy][cx] = " "
@ -128,6 +132,9 @@ function M.generate_maze(seed, width, height, depth)
table.insert(nodes, { x = cx, y = cy, z = cz }) table.insert(nodes, { x = cx, y = cy, z = cz })
else else
table.remove(nodes, curnode) table.remove(nodes, curnode)
end
if #directions == 0 or shift_attention <= 1 then
if #nodes > 0 then if #nodes > 0 then
curnode = math.random(1, #nodes) curnode = math.random(1, #nodes)