Mothback/code/objects.lua

82 lines
1.7 KiB
Lua
Raw Normal View History

LoadedObjects = {
Entities = {},
2021-10-16 23:06:11 +00:00
Collisions = {},
Platforms = {},
Ladders = {},
Hazards = {}
2021-10-16 23:06:11 +00:00
}
-- level functions
function LoadedObjects.DrawCollisions()
2022-02-17 23:03:32 +00:00
for _, ladder in pairs(LoadedObjects.Collisions) do
ladder: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
2021-10-16 23:06:11 +00:00
end
for _, ladder in pairs(LoadedObjects.Ladders) do
2021-10-16 23:06:11 +00:00
ladder:Draw(2)
end
for _, hazard in pairs(LoadedObjects.Hazards) do
hazard:Draw(1)
end
2021-10-16 23:06:11 +00:00
end
-- returns true if theres a collision at that point
function isThereObjectAt(x,y,objectType)
for _, object in pairs(objectType) do
if object.disable then
-- Dont calculate if dissabled
elseif x >= object.from.x
and x <= object.to.x
and y >= object.from.y
and y <= object.to.y then
object.isColliding = true
return true
2021-10-16 23:06:11 +00:00
end
end
return false
2021-10-16 23:06:11 +00:00
end
function isThereCollisionAt(x,y)
if x >= 0 and x < #CollisionTable
and y >= 0 and y < #CollisionTable[0] then
return CollisionTable[math.floor(y)][math.floor(x)]
end
return false
2021-10-16 23:06:11 +00:00
end
2021-10-16 23:06:11 +00:00
-- 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
2021-10-16 23:06:11 +00:00
end
for _, platform in pairs(LoadedObjects.Platforms) do
if main_Player.pos.y < platform.from.y then
platform.disable = false
2021-10-16 23:06:11 +00:00
else
platform.disable = true
2021-10-16 23:06:11 +00:00
end
end
for _, platform in pairs(LoadedObjects.Hazards) do
if main_Player.isOnGround then
platform.disable = true
else
platform.disable = false
end
end
2021-10-16 23:06:11 +00:00
end