From b16665a2b0fd673678874c602b7e30efd39ea439 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 18 Apr 2021 11:03:34 +0200 Subject: [PATCH] feat: scissor player when under the ground height --- .../scenes/overworld/actors/parent.lua | 24 +++++++++++++++---- .../overworld/actors/player/charset.lua | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/parent.lua b/sonic-radiance.love/scenes/overworld/actors/parent.lua index d738baf..2fb1862 100644 --- a/sonic-radiance.love/scenes/overworld/actors/parent.lua +++ b/sonic-radiance.love/scenes/overworld/actors/parent.lua @@ -31,6 +31,8 @@ function Parent:initCharset() self.isFast = false self.largeAnim = false self.alwaysWalk = false + self.scissorSprite = false + self.groundHeight = 0 end function Parent:setCharset(charset, charId, cantWalk) @@ -45,8 +47,17 @@ function Parent:drawCharset(charset, charId) local z = math.floor(self.z) love.graphics.setColor(1,1,1,0.5) - self.assets.images["shadow"]:draw(x + 1, y + 11) + if (self.groundHeight == 0) then + self.assets.images["shadow"]:draw(x + 1, y + 11) + end utils.graphics.resetColor() + + if (self.scissorSprite) then + local _, camy = self.world.cameras:getViewCoordinate(1) + local viewy = math.floor((self.y + self.h - self.groundHeight) - camy) + love.graphics.setScissor(0, 0, 424, viewy) + end + if (self.largeAnim) then self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast) else @@ -60,15 +71,18 @@ function Parent:drawCharset(charset, charId) self.charsetManager:drawTurning(self.charset, self.charId, x, y - z, self.isFast) end end + + if (self.scissorSprite) then + love.graphics.setScissor() + end end function Parent:draw() + if (self.drawDebugBox) then + love.graphics.rectangle("line", math.floor(self.x), math.floor(self.y), self.w, self.h) + end if (self.charset ~= nil) then self:drawCharset() - else - if (self.drawDebugBox) then - love.graphics.rectangle("line", math.floor(self.x), math.floor(self.y), self.w, self.h) - end end end diff --git a/sonic-radiance.love/scenes/overworld/actors/player/charset.lua b/sonic-radiance.love/scenes/overworld/actors/player/charset.lua index b66fa0e..712df59 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/charset.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/charset.lua @@ -5,6 +5,7 @@ local ACTIONS_ISFAST = {"jump", "fly", "run", "jumpdash"} local ACTIONS_ALWAYSWALK = {"fly"} function PlayerCharset:initPlayerCharset() + self.scissorSprite = true self:updateCurrentCharset() end