Mothback/data/scripts/objects.lua

73 lines
1.4 KiB
Lua
Raw Normal View History

2021-10-16 23:06:11 +00:00
objects = {
entities = {},
collisions = {},
platforms = {},
ladders = {}
}
-- level functions
function objects.DrawCollisions()
for _, col in pairs(objects.collisions) do
col:Draw(1)
end
for _, plat in pairs(objects.platforms) do
if plat.disable == true then plat:Draw(2) end
if plat.disable == false then plat:Draw(1) end
end
for _, ladder in pairs(objects.ladders) do
ladder:Draw(2)
end
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function isThereObjectAt(x,y,objectType)
2021-10-16 23:06:11 +00:00
local result = false
for _, col in pairs(objectType) do
if x >= col.from.x
and x <= col.to.x
and y >= col.from.y
and y <= col.to.y
and col.disable ~= true then
2021-10-16 23:06:11 +00:00
result = true
col.collision = true
end
end
return result
end
function isThereAnyCollisionAt(x,y)
local result = false
if not result then
result = isThereObjectAt(x,y,objects.collisions)
2021-10-16 23:06:11 +00:00
end
if not result then
result = isThereObjectAt(x,y,objects.ladders)
2021-10-16 23:06:11 +00:00
end
if not result then
result = isThereObjectAt(x,y,objects.platforms)
2021-10-16 23:06:11 +00:00
end
return result
end
-- flags
function SetCollisionFlags(player)
for _, col in pairs(objects.collisions) do
col.collision = false
end
for _, plat in pairs(objects.platforms) do
plat.collision = false
if player.pos.y < plat.from.y then
plat.disable = false
else
plat.disable = true
end
end
for _, ladder in pairs(objects.ladders) do
ladder.collision = false
end
end