feat: implement fake y-sorting for tiles

This commit is contained in:
Kazhnuz 2021-04-05 21:07:40 +02:00
parent 70029ba7bd
commit 9c4efa3512
2 changed files with 39 additions and 0 deletions

View file

@ -138,6 +138,23 @@ function StiWrapper:getTileTypeAtPoint(x, y)
return self:getTileTypeAtCoord(xx, yy) return self:getTileTypeAtCoord(xx, yy)
end end
function StiWrapper:haveUpperLayerAtCoord(x, y)
local xx, yy = self:convertPixelToTile(x, y)
local haveLayer = false
if (self.objectlayer > 0) then
for i = self.objectlayer, self.nbrLayer, 1 do
local layer = self.sti.layers[i]
if layer.visible and layer.opacity > 0 and (layer.type == "tilelayer") then
local _, tileid = self:getTileId(layer.name, xx, yy)
if (tileid > 0) then
haveLayer = true
end
end
end
end
return haveLayer
end
function StiWrapper:getTileTypeAtCoord(x, y) function StiWrapper:getTileTypeAtCoord(x, y)
local canSearch = true local canSearch = true
local currentType = nil local currentType = nil

View file

@ -128,6 +128,27 @@ end
function TiledMultiMap:drawUpperLayers() function TiledMultiMap:drawUpperLayers()
local player = self.world.players[1].actor
local pos1AUpperLayer = self:haveUpperLayerAtCoord(player.x, player.y + 8)
local pos2AUpperLayer = self:haveUpperLayerAtCoord(player.x + 16, player.y + 8)
local y = math.floor((player.y)/16)*16
if (pos1AUpperLayer or pos2AUpperLayer) then
y = math.floor((player.y - player.z)/16)*16
end
local camx, camy = self.world.cameras:getViewCoordinate(1)
local viewy = math.floor(y - camy - 16)
love.graphics.setScissor(0, viewy, 424, 240)
self:drawUpperWrappers()
love.graphics.setScissor()
end
function TiledMultiMap:haveUpperLayerAtCoord(x, y)
local wrapper = self:getMapAtPoint(x, y)
return wrapper:haveUpperLayerAtCoord(x, y)
end
function TiledMultiMap:drawUpperWrappers()
local x, y, w, h = self.world.cameras:getViewCoordinate(1) local x, y, w, h = self.world.cameras:getViewCoordinate(1)
local listWrapper = self:getMapsInRect(x, y, w, h) local listWrapper = self:getMapsInRect(x, y, w, h)
for i, wrapper in ipairs(listWrapper) do for i, wrapper in ipairs(listWrapper) do
@ -141,6 +162,7 @@ function TiledMultiMap:drawLowerLayers()
for i, wrapper in ipairs(listWrapper) do for i, wrapper in ipairs(listWrapper) do
wrapper:drawLowerLayers() wrapper:drawLowerLayers()
end end
self:drawUpperWrappers()
end end
return TiledMultiMap return TiledMultiMap