From 9c4efa3512932a8fea89c61039f704e5c003e3dc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 5 Apr 2021 21:07:40 +0200 Subject: [PATCH] feat: implement fake y-sorting for tiles --- .../modules/world/maps/tiled/stiwrapper.lua | 17 ++++++++++++++ sonic-radiance.love/scenes/overworld/map.lua | 22 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua index f2ee979..361975c 100644 --- a/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua +++ b/sonic-radiance.love/core/modules/world/maps/tiled/stiwrapper.lua @@ -138,6 +138,23 @@ function StiWrapper:getTileTypeAtPoint(x, y) return self:getTileTypeAtCoord(xx, yy) 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) local canSearch = true local currentType = nil diff --git a/sonic-radiance.love/scenes/overworld/map.lua b/sonic-radiance.love/scenes/overworld/map.lua index d270203..c0b0376 100644 --- a/sonic-radiance.love/scenes/overworld/map.lua +++ b/sonic-radiance.love/scenes/overworld/map.lua @@ -128,6 +128,27 @@ end 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 listWrapper = self:getMapsInRect(x, y, w, h) for i, wrapper in ipairs(listWrapper) do @@ -141,6 +162,7 @@ function TiledMultiMap:drawLowerLayers() for i, wrapper in ipairs(listWrapper) do wrapper:drawLowerLayers() end + self:drawUpperWrappers() end return TiledMultiMap