89 lines
1.8 KiB
Lua
89 lines
1.8 KiB
Lua
|
LoadedObjects = {
|
||
|
Entities = {},
|
||
|
|
||
|
Collisions = {},
|
||
|
Platforms = {},
|
||
|
Ladders = {},
|
||
|
Hazards = {}
|
||
|
}
|
||
|
|
||
|
-- 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
|
||
|
|
||
|
for _, hazard in pairs(LoadedObjects.Hazards) do
|
||
|
hazard:Draw(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- returns true if theres a collision at that point
|
||
|
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.isColliding = true
|
||
|
return true
|
||
|
end
|
||
|
end
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
function isThereAnyCollisionAt(x,y)
|
||
|
local Check = {
|
||
|
LoadedObjects.Collisions,
|
||
|
LoadedObjects.Ladders,
|
||
|
LoadedObjects.Platforms
|
||
|
}
|
||
|
for _, type in pairs(Check) do
|
||
|
local result = isThereObjectAt(x,y,type)
|
||
|
if result then
|
||
|
return result
|
||
|
end
|
||
|
end
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
-- flags
|
||
|
function SetCollisionFlags()
|
||
|
local Check = {
|
||
|
LoadedObjects.Collisions,
|
||
|
LoadedObjects.Ladders,
|
||
|
LoadedObjects.Platforms,
|
||
|
LoadedObjects.Hazards
|
||
|
}
|
||
|
for _, type in pairs(Check) do
|
||
|
for _, object in pairs(type) do
|
||
|
object.isColliding = false
|
||
|
end
|
||
|
end
|
||
|
for _, platform in pairs(LoadedObjects.Platforms) do
|
||
|
if main_Player.pos.y < platform.from.y then
|
||
|
platform.disable = false
|
||
|
else
|
||
|
platform.disable = true
|
||
|
end
|
||
|
end
|
||
|
for _, platform in pairs(LoadedObjects.Hazards) do
|
||
|
if main_Player.isOnGround then
|
||
|
platform.disable = true
|
||
|
else
|
||
|
platform.disable = false
|
||
|
end
|
||
|
end
|
||
|
end
|