1. Start with all wall-cells as walls and all path cells as not part of the maze.
2. Choose one path-cell. Make it part of the maze. Add neighboring walls to your wall queue (what you called "n". btw: seriously, choose better variable names. Mine aren't perfect either, but at least you get an idea what they're used for).
3. While the wall queue is not empty:
3.a. Choose random element of the wall queue. (The one I painted pink)
3.b. If only one path-cell at the selected queue element is part of the maze:
3.b.1 Make the selected queue entry a passage.
3.b.2 Add other path-cell to the maze.
3.b.3 Add neighboring walls to the wall queue (if not already in there)
3.c Remove selected queue entry from the queue.
4. Done
In pictures:size_x, size_y, size_z = 0.3, 0.3, 0.3
local function draw_box()
set_color(1, 0, 0, .5)
body = get_body_info(0, 11)
draw_box_m(body.pos.x, body.pos.y, body.pos.z, size_x, size_y, size_z, body.rot)
body = get_body_info(0, 12)
draw_box_m(body.pos.x, body.pos.y, body.pos.z, size_x, size_y, size_z, body.rot)
set_color(0, 0, 1, .5)
body = get_body_info(1, 11)
draw_box_m(body.pos.x, body.pos.y, body.pos.z, size_x, size_y, size_z, body.rot)
body = get_body_info(1, 12)
draw_box_m(body.pos.x, body.pos.y, body.pos.z, size_x, size_y, size_z, body.rot)
end
add_hook("draw3d", "draw_box", draw_box)
Extremely anti-complicated code that color-codes Tori and Uke's hands. You know, just in case you're in a room, and can't tell who is who. In those rare cases.x = 0
y = 0
length = 50
angle = 0.0
angle_stepsize = .45
angtbl = {}
w,h = get_window_size()
lenset = 200
while angle < 2 * math.pi do
table.insert(angtbl,{x=lenset * math.cos(angle) + w/2, y=lenset *math.sin(angle) + h/2})
angle = angle + .1
end
add_hook("draw2d","y_test",function()
set_color(0,0,0,1)
draw_quad(0,0,w,h)
for i = 1,#angtbl do
set_color(math.random(),math.random(),math.random(),1)
draw_quad(angtbl[i].x, angtbl[i].y,4,4)
angtbl[i].x = angtbl[i].x + math.cos(math.random(0,360))*2
angtbl[i].y = angtbl[i].y + math.sin(math.random(0,360))*2
end
lenset = lenset + (150 - lenset/2)*.1
end)
x = 0
y = 0
length = 50
angle = 0.0
angle_stepsize = .45
angtbl = {}
w,h = get_window_size()
lenset = 0
size = 4
oldtime = os.clock()
while angle < 2 * math.pi do
table.insert(angtbl,{x=lenset * math.cos(angle) + w/2, y=lenset *math.sin(angle) + h/2, dirx = math.cos(angle), diry = math.sin(angle)})
angle = angle + math.random()*2
end
add_hook("draw2d","y_test",function()
set_color(0,0,0,1)
draw_quad(0,0,w,h)
for i = 1,#angtbl do
set_color(math.random(),math.random(),math.random(),1)
draw_quad(angtbl[i].x, angtbl[i].y,size,size)
angtbl[i].x = angtbl[i].x + angtbl[i].dirx*4
angtbl[i].y = angtbl[i].y + angtbl[i].diry*4
if(size <= 0.01)then
table.remove(angtbl,i)
end
end
newtime = os.clock()
if(newtime > oldtime + .1)then
size = size - 1
oldtime = os.clock()
end
end)
x = 0
y = 0
length = 50
angle = 0.0
angle_stepsize = .45
angtbl = {}
w,h = get_window_size()
lenset = 0
size = 4
clicked = true
cursorx = 0
cursory = 0
gravity = 50
add_hook("draw2d","y_test",function()
set_color(0,0,0,1)
draw_quad(0,0,w,h)
if(clicked)then
while angle < 2 * math.pi do
table.insert(angtbl,{randgrey = math.random() * 2 - 2/2 + .5, gravity = 0, size = 7, x=lenset * math.cos(angle) + cursorx, y=lenset *math.sin(angle) + cursory, dirx = math.cos(angle), diry = math.sin(angle)})
angle = angle + math.random()*2
end
end
for i = 1,#angtbl do
set_color(math.random(),math.random(),math.random(),1)
draw_quad(angtbl[i].x, angtbl[i].y,angtbl[i].size,angtbl[i].size)
angtbl[i].size = angtbl[i].size + (0 - angtbl[i].size)*.05
angtbl[i].x = angtbl[i].x + angtbl[i].dirx*4
angtbl[i].y = (angtbl[i].y + angtbl[i].diry*4) + angtbl[i].gravity
angtbl[i].gravity = angtbl[i].gravity + (gravity - angtbl[i].gravity)*.005
if(angtbl[i].size <=0.01)then
table.remove(angtbl,i)
end
end
end)
function getmousepos(x,y)
cursorx = x
cursory = y
end
function mouseclicked(button,x,y)
clicked = true
cursorx = x
cursory = y
end
function mouseunclicked(button,x,y)
cursorx = x
cursory = y
angle = 0
end
add_hook("mouse_move","mousepos", getmousepos)
add_hook("mouse_button_down","mouseclicked",mouseclicked)
add_hook("mouse_button_up", "unclicked", mouseunclicked)