feat: scissor player when under the ground height

This commit is contained in:
Kazhnuz 2021-04-18 11:03:34 +02:00
parent 15973e491a
commit b16665a2b0
2 changed files with 20 additions and 5 deletions

View file

@ -31,6 +31,8 @@ function Parent:initCharset()
self.isFast = false self.isFast = false
self.largeAnim = false self.largeAnim = false
self.alwaysWalk = false self.alwaysWalk = false
self.scissorSprite = false
self.groundHeight = 0
end end
function Parent:setCharset(charset, charId, cantWalk) function Parent:setCharset(charset, charId, cantWalk)
@ -45,8 +47,17 @@ function Parent:drawCharset(charset, charId)
local z = math.floor(self.z) local z = math.floor(self.z)
love.graphics.setColor(1,1,1,0.5) 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() 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 if (self.largeAnim) then
self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast) self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast)
else else
@ -60,15 +71,18 @@ function Parent:drawCharset(charset, charId)
self.charsetManager:drawTurning(self.charset, self.charId, x, y - z, self.isFast) self.charsetManager:drawTurning(self.charset, self.charId, x, y - z, self.isFast)
end end
end end
if (self.scissorSprite) then
love.graphics.setScissor()
end
end end
function Parent:draw() 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 if (self.charset ~= nil) then
self:drawCharset() 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
end end

View file

@ -5,6 +5,7 @@ local ACTIONS_ISFAST = {"jump", "fly", "run", "jumpdash"}
local ACTIONS_ALWAYSWALK = {"fly"} local ACTIONS_ALWAYSWALK = {"fly"}
function PlayerCharset:initPlayerCharset() function PlayerCharset:initPlayerCharset()
self.scissorSprite = true
self:updateCurrentCharset() self:updateCurrentCharset()
end end