Mothback/data/scripts/objects.lua

63 lines
1.5 KiB
Lua

LoadedObjects = {
Entities = {},
Collisions = {},
Platforms = {},
Ladders = {}
}
-- level functions
function LoadedObjects.DrawCollisions()
for _, collision in pairs(LoadedObjects.Collisions) do
collision:Draw(1)
end
for _, platform in pairs(LoadedObjects.Platforms) do
if platform.disable == true then platform:Draw(2) end
if platform.disable == false then platform:Draw(1) end
end
for _, ladder in pairs(LoadedObjects.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)
for _, collision in pairs(objectType) do
if collision.disable then
-- Dont calculate if dissabled
elseif x >= collision.from.x
and x <= collision.to.x
and y >= collision.from.y
and y <= collision.to.y then
collision.collision = true
return true
end
end
return false
end
function isThereAnyCollisionAt(x,y)
return isThereObjectAt(x,y,LoadedObjects.Collisions) or isThereObjectAt(x,y,LoadedObjects.Ladders) or isThereObjectAt(x,y,LoadedObjects.Platforms)
end
-- flags
function SetCollisionFlags(player)
for _, collision in pairs(LoadedObjects.Collisions) do
collision.collision = false
end
for _, platform in pairs(LoadedObjects.Platforms) do
platform.collision = false
if player.pos.y < platform.from.y then
platform.disable = false
else
platform.disable = true
end
end
for _, ladder in pairs(LoadedObjects.Ladders) do
ladder.collision = false
end
end