YASTFHTECB4SLOHBRREMWGEVDSNUC2USP7P4PJLXZPKC3J5G3CKQC
CA32MRE2G2SLFQIGKU2PW66JI45AFKDSZR277C3XDJUPNMHKMOUQC
JBMY3NW7Z4SQWVWDFRKXSNC4HLEVCZJVFOFPW5VTY2CKWQNVKKGQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
7TQAF4BYIK75EEYCCK7VEUSZHNCWMWIA3HZGQKIILYESUZ5ZZRVQC
JIBCE66ZTWM5WEHEHNKKTRWBJQSQWBDDWPMOJIJR5Q676OSHYCNAC
7P3EK7K2AWA3YDMQBFWJY4TVIKGJ5LI7E4P4F7Z2CVAGVETA3JHAC
BF7TW3EKRIDYC6J2Q2J4YOBAVQF55Y3H6KGZIHNXMH4N72MR6GXQC
7OF2JQRH3YCJGRFQ2VHNZJDHL34QJUB4TVVSXHTWWJHEIYCGECJAC
OELP2MAL5RGZ3AZ42V6H7RLGX52JLNHGUD7GV6YIVZ3ACOK5SFSQC
7KX3WBFEXMIHNKWNF4NUOBW5HO3PEL3ZEFFMTAXFOQG6V7BYXZ3AC
test_overlapping_intervals = function()
check(overlapping_intervals(0, 1, -20, 21), 'within')
end
test_straddles_interval = function()
check(straddles_interval(-20, 21, 0), '1')
end
test_overlapping_areas = function()
check(
overlapping_areas(
{x=0, y=0, w=1, h=1},
{x=0, y=0, w=1, h=1}),
'identical')
end
Spawn_candidates = {}
draw_debug_definitions = function()
for k,def in pairs(Definitions) do
App.color{r=1, g=0, b=0}
-- love.graphics.rectangle('line', vx(def.x-20), vy(def.y-20), scale(620), scale(30))
love.graphics.rectangle('line', vx(def.x-20), vy(def.y-20), scale(def.w+20), scale(def.h+60))
end
for _,cand in ipairs(Spawn_candidates) do
App.color{r=0.4, g=0.8, b=0.4}
love.graphics.rectangle('line', vx(cand.x), vy(cand.y), scale(800), scale(140))
love.graphics.print(cand.name, vx(cand.x), vy(cand.y))
end
end
Show_debug = false
draw_debug = function()
draw_debug_definitions()
end
overlaps_any_definition = function(box)
for k,def in pairs(Definitions) do
if overlapping_areas(box, def) then
print(def.key)
box.name = def.key
return true
end
end
end
-- return true if a is less than some distance from b
overlapping_areas = function(a, b)
return overlapping_intervals(a.x, a.x+a.w, b.x-20, b.x+b.w+20)
and overlapping_intervals(a.y, a.y+a.h, b.y-20, b.y+b.h+60) -- leave more space below existing definitions
end
overlapping_intervals = function(alo,ahi, blo,bhi)
return straddles_interval(alo,ahi, blo)
or straddles_interval(alo,ahi, bhi)
or straddles_interval(blo, bhi, alo)
or straddles_interval(blo, bhi, ahi)
end
straddles_interval = function(lo,hi, border)
return lo <= border and hi >= border
end
return {
x = math.random(Viewport.x, Viewport.x+Viewport.w),
y = math.random(Viewport.y, Viewport.y+Viewport.h),
}
Spawn_candidates = {}
for _=1,10 do
local result = {w=600, h=100}
result.x = math.random(Viewport.x, Viewport.x+Viewport.w)
result.x = round(result.x/100)*100
result.y = math.random(Viewport.y, Viewport.y+Viewport.h)
if _ == 10 or not overlaps_any_definition(result) then
result.w, result.h = nil
result.x = result.x + 100
result.y = result.y + 20
return result
end
table.insert(Spawn_candidates, result)
end