2022-01-22 22:10:21 +00:00
|
|
|
LoadedObjects = {
|
|
|
|
Entities = {},
|
2021-10-16 23:06:11 +00:00
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
Collisions = {},
|
|
|
|
Platforms = {},
|
|
|
|
Ladders = {}
|
2021-10-16 23:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- level functions
|
2022-01-22 22:10:21 +00:00
|
|
|
function LoadedObjects.DrawCollisions()
|
|
|
|
for _, collision in pairs(LoadedObjects.Collisions) do
|
|
|
|
collision:Draw(1)
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
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
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, ladder in pairs(LoadedObjects.Ladders) do
|
2021-10-16 23:06:11 +00:00
|
|
|
ladder:Draw(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
|
2021-11-28 02:38:30 +00:00
|
|
|
function isThereObjectAt(x,y,objectType)
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, collision in pairs(objectType) do
|
2022-02-05 11:38:08 +00:00
|
|
|
if collision.disable then
|
|
|
|
-- Dont calculate if dissabled
|
|
|
|
elseif x >= collision.from.x
|
2022-01-22 22:10:21 +00:00
|
|
|
and x <= collision.to.x
|
|
|
|
and y >= collision.from.y
|
2022-02-05 11:38:08 +00:00
|
|
|
and y <= collision.to.y then
|
2022-01-22 22:10:21 +00:00
|
|
|
collision.collision = true
|
2022-02-05 11:38:08 +00:00
|
|
|
return true
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
2022-02-05 11:38:08 +00:00
|
|
|
return false
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function isThereAnyCollisionAt(x,y)
|
2022-01-22 22:10:21 +00:00
|
|
|
return isThereObjectAt(x,y,LoadedObjects.Collisions) or isThereObjectAt(x,y,LoadedObjects.Ladders) or isThereObjectAt(x,y,LoadedObjects.Platforms)
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
-- flags
|
|
|
|
function SetCollisionFlags(player)
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, collision in pairs(LoadedObjects.Collisions) do
|
|
|
|
collision.collision = false
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, platform in pairs(LoadedObjects.Platforms) do
|
|
|
|
platform.collision = false
|
|
|
|
if player.pos.y < platform.from.y then
|
|
|
|
platform.disable = false
|
2021-10-16 23:06:11 +00:00
|
|
|
else
|
2022-01-22 22:10:21 +00:00
|
|
|
platform.disable = true
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
for _, ladder in pairs(LoadedObjects.Ladders) do
|
2021-10-16 23:06:11 +00:00
|
|
|
ladder.collision = false
|
|
|
|
end
|
|
|
|
end
|