Skip to content

Instantly share code, notes, and snippets.

@jonbro
Created December 5, 2013 11:27
Show Gist options
  • Select an option

  • Save jonbro/7803827 to your computer and use it in GitHub Desktop.

Select an option

Save jonbro/7803827 to your computer and use it in GitHub Desktop.
SLOW CODE :(
local edges = collectEdgePositions(self.rooms.members, self.fingerBlock)
-- for each edge
for i,v in ipairs(edges) do
self.ghostBlock:setPosition(v.p.x, v.p.y)
-- check for overlaps
self.commitParent = v.r
local fudged = false
-- search through each room
self.rooms:updateSpatialHash()
if not self.rooms:overlap(self.ghostBlock, function(a, b)
if fudged then
return;
end
-- check to see if we can fudge it, if not then continue looping
if v.d == 'e' or v.d == 'w' then
local oy = b.pos.y
if a.pos.y < b.pos.y then
b.pos.y = math.min(b.pos.y+b.h/4, a.pos.y+b.h)
else
b.pos.y = math.max(b.pos.y-b.h/4, a.pos.y-b.h)
end
if b.pos.y >= v.r.pos.y-b.h and b.pos.y <= v.r.pos.y+v.r.h and not self.rooms:overlap(b, nil, nil, true) then
fudged = true
else
b.pos.y = oy
end
else
local ox = b.pos.x
if a.pos.x < b.pos.x then
b.pos.x = math.min(b.pos.x+b.w/4, a.pos.x+b.w)
else
b.pos.x = math.max(b.pos.x-b.w/4, a.pos.x-b.w)
end
if b.pos.x >= v.r.pos.x-b.w and b.pos.x <= v.r.pos.x+v.r.w and not self.rooms:overlap(b, nil, nil, true) then
fudged = true
else
b.pos.x = ox
end
end
end, nil, true) then
break;
end
if fudged then
print('fudged')
break;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment