consistent naming; moving functions from level.lua to gameworld.lua
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
objects = {
|
||||
entities = {},
|
||||
LoadedObjects = {
|
||||
Entities = {},
|
||||
|
||||
collisions = {},
|
||||
platforms = {},
|
||||
ladders = {}
|
||||
Collisions = {},
|
||||
Platforms = {},
|
||||
Ladders = {}
|
||||
}
|
||||
|
||||
-- level functions
|
||||
function objects.DrawCollisions()
|
||||
for _, col in pairs(objects.collisions) do
|
||||
col:Draw(1)
|
||||
function LoadedObjects.DrawCollisions()
|
||||
for _, collision in pairs(LoadedObjects.Collisions) do
|
||||
collision: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
|
||||
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(objects.ladders) do
|
||||
for _, ladder in pairs(LoadedObjects.Ladders) do
|
||||
ladder:Draw(2)
|
||||
end
|
||||
end
|
||||
@@ -25,48 +25,38 @@ 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 _, col in pairs(objectType) 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
|
||||
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
|
||||
col.collision = true
|
||||
collision.collision = true
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function isThereAnyCollisionAt(x,y)
|
||||
local result = false
|
||||
if not result then
|
||||
result = isThereObjectAt(x,y,objects.collisions)
|
||||
end
|
||||
if not result then
|
||||
result = isThereObjectAt(x,y,objects.ladders)
|
||||
end
|
||||
if not result then
|
||||
result = isThereObjectAt(x,y,objects.platforms)
|
||||
end
|
||||
return result
|
||||
return isThereObjectAt(x,y,LoadedObjects.Collisions) or isThereObjectAt(x,y,LoadedObjects.Ladders) or isThereObjectAt(x,y,LoadedObjects.Platforms)
|
||||
end
|
||||
-- flags
|
||||
function SetCollisionFlags(player)
|
||||
for _, col in pairs(objects.collisions) do
|
||||
col.collision = false
|
||||
for _, collision in pairs(LoadedObjects.Collisions) do
|
||||
collision.collision = false
|
||||
end
|
||||
|
||||
for _, plat in pairs(objects.platforms) do
|
||||
plat.collision = false
|
||||
if player.pos.y < plat.from.y then
|
||||
plat.disable = false
|
||||
for _, platform in pairs(LoadedObjects.Platforms) do
|
||||
platform.collision = false
|
||||
if player.pos.y < platform.from.y then
|
||||
platform.disable = false
|
||||
else
|
||||
plat.disable = true
|
||||
platform.disable = true
|
||||
end
|
||||
end
|
||||
|
||||
for _, ladder in pairs(objects.ladders) do
|
||||
for _, ladder in pairs(LoadedObjects.Ladders) do
|
||||
ladder.collision = false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user