Mothback/data/scripts/objects.lua

107 lines
2.4 KiB
Lua

objects = {
entities = {},
collisions = {},
platforms = {},
ladders = {}
}
-- level functions
function objects.DrawCollisions()
for _, col in pairs(objects.collisions) do
col:Draw(1)
end
for _, plat in pairs(objects.platforms) do
if plat.disable == true then plat:Draw(2) end
if plat.disable == false then plat:Draw(1) end
end
for _, ladder in pairs(objects.ladders) do
ladder:Draw(2)
end
end
-- returns true if theres a collision at that point. also marks collisioned tile as collision true
function isThereCollisionAt(x,y)
local result = false
for _, col in pairs(objects.collisions) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y then
result = true
col.collision = true
end
end
return result
end
function isTherePlatformAt(x,y)
local result = false
for _, col in pairs(objects.platforms) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
return result
end
function isThereLadderAt(x,y)
local result = false
for _, col in pairs(objects.ladders) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
return result
end
function isThereAnyCollisionAt(x,y)
local result = false
if not result then
for _, col in pairs(objects.collisions) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y then
result = true
col.collision = true
end
end
end
if not result then
for _, col in pairs(objects.ladders) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
end
if not result then
for _, col in pairs(objects.platforms) do
if x >= col.from.x and x <= col.to.x and y >= col.from.y and y <= col.to.y and col.disable ~= true then
result = true
col.collision = true
end
end
end
return result
end
-- flags
function SetCollisionFlags(player)
for _, col in pairs(objects.collisions) do
col.collision = false
end
for _, plat in pairs(objects.platforms) do
plat.collision = false
if player.pos.y < plat.from.y then
plat.disable = false
else
plat.disable = true
end
end
for _, ladder in pairs(objects.ladders) do
ladder.collision = false
end
end