Ref wrote:You guys are creating some very nice wall paper but I was wondering if you had any scripts that would permit specifying a starting position (like lower left corner) and an objective position (like upper right corner or center screen) and maze grid size - something used for game scripts?
You could just slightly modify the recursive backtracker to have a higher chance of moving towards the finish point and have it start at the start point.
Or you could make your own recursive backtracker, it really isn't that hard.
Code: Select all
--Backtracker
function love.load()
path={math.random(1,width),math.random(1,height)}
map = newMap()
end
function love.update(dt)
if #path > 0 then
local x,y = path[#path][1],path[#path][2]
local t = {}
-- Add all the positions it CAN walk to from x and y
if #t > 0 then -- It can walk somewhere
local c = t[math.random(1,#t)]
merge(x,y,c.x,c.y) -- Merge the points
path[#path+1] = {c.x,c.y} -- Add the new point to the path
else
path[#path] = nil -- Remove the part in the path that could no walk anywhere
end
else
print('DONE')
end
end
function love.draw()
love.graphics.draw( -- draw the map
end
thats what the actual algorithm looks like ( if not optimised ) but should not be too hard to make.
and as I have not seen anyone store maps the way I do here is a quick explanation:
using a texture atlas / tile sheet a table storing the different quads from 1 to 15. ( using 0 most of the time )
left,up,right,down = 1,2,4,8 -- power of two's
the first quad (quad[1])
is just quad[left] and therefore only goes left
and likewise quad[left+up+down] goes left, up and down
they can therefore be quickly added to a map where 0 is empty by doing
map[y][x] = map[y][x] + (left, up, right or down)
which is used instead of map[y][x].(left, up, right or down) = true
I use this method because:
1) its just the quad index stored in the map.
2) it take up less ram since less tables are needed.
the drawbacks are:
1) may be harder to get a hang on at first.
thats a quick summary of it, if you want a more complete explanation please tell me so.