forked from ReikaKalseki/DragonIndustries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxes.lua
34 lines (30 loc) · 1.15 KB
/
boxes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function moveBox(area, dx, dy)
--printTable(area)
area.left_top.x = area.left_top.x+dx
area.left_top.y = area.left_top.y+dy
area.right_bottom.x = area.right_bottom.x+dx
area.right_bottom.y = area.right_bottom.y+dy
return area
end
function padBox(area, padX, padY)
area.left_top.x = area.left_top.x-padX
area.left_top.y = area.left_top.y-padY
area.right_bottom.x = area.right_bottom.x+padX
area.right_bottom.y = area.right_bottom.y+padY
return area
end
function getMovedBox(entity, dx, dy)
local base = entity.prototype.collision_box
return moveBox(base, dx, dy)
end
function getPaddedBox(entity, padX, padY)
local base = entity.prototype.collision_box
return moveBox(padBox(base, padX, padY), entity.position.x, entity.position.y)
end
function intersects(box1, box2)
if box1.right_bottom.x < box2.left_top.x then return false end -- box1 is left of box2
if box1.left_top.x > box2.right_bottom.x then return false end -- box1 is right of box2
if box1.right_bottom.y < box2.left_top.y then return false end -- box1 is above box2
if box1.left_top.y > box2.right_bottom.y then return false end -- box1 is below box2
return true -- boxes overlap
end