From 9dd96e2a86fc029f0ab7b2d7dfc964fbbb480877 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 27 Nov 2021 13:10:37 +0100 Subject: [PATCH] chore:extract position handling in both system --- .../modules/subgames/world/actors/parent.lua | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sonic-bluestreak.love/game/modules/subgames/world/actors/parent.lua b/sonic-bluestreak.love/game/modules/subgames/world/actors/parent.lua index 5a9c759..44b1bd8 100644 --- a/sonic-bluestreak.love/game/modules/subgames/world/actors/parent.lua +++ b/sonic-bluestreak.love/game/modules/subgames/world/actors/parent.lua @@ -7,17 +7,13 @@ function Parent:new(world, type, x, y, z, w, h, d, isSolid) end function Parent:draw() - local drawx, drawy, drawz = self.x, self.y, self.z - if (self.world.maptype == "shoot") then - drawx = drawx + math.floor(drawy/2) - end self:drawStart() if (self.box ~= nil) then - self.box:draw(drawx, drawy, drawz) + self.box:draw(math.floor(self.x), math.floor(self.y), math.floor(self.z)) else - local x, y = math.floor(drawx), math.floor(drawy - drawz - self.d + (self.h/2)) - if (math.floor(drawz) < -2) and (self.world.maptype == "shoot") then - core.screen:setScissor(0, 0, 424, 58+drawy/2) + local x, y, z = self:computeDrawingPosition() + if (math.floor(z) < -2) and (self.world.maptype == "shoot") then + core.screen:setScissor(0, 0, 424, 58+self.y/2) self:drawSprite(x, y) core.screen:resetScissor() else @@ -27,6 +23,14 @@ function Parent:draw() self:drawEnd() end +function Parent:computeDrawingPosition() + local drawx, drawy, drawz = self.x, self.y, self.z + if (self.world.maptype == "shoot") then + drawx = drawx + math.floor(drawy/2) + end + return math.floor(drawx), math.floor(drawy - drawz - self.d + (self.h/2)), math.floor(drawz) +end + function Parent:drawShadow(x, y) local x = x or 0 local y = y or 0