63 lines
1.5 KiB
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)
|
|
local result = false
|
|
for _, collision in pairs(objectType) do
|
|
if x >= collision.from.x
|
|
and x <= collision.to.x
|
|
and y >= collision.from.y
|
|
and y <= collision.to.y
|
|
and collision.disable ~= true then
|
|
result = true
|
|
collision.collision = true
|
|
end
|
|
end
|
|
return result
|
|
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
|