feat(overworld): add jump

This commit is contained in:
Kazhnuz 2021-04-10 14:28:20 +02:00
parent 09e14eae86
commit 6d1900d5a5
2 changed files with 53 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View file

@ -26,6 +26,8 @@ function Player:new(world, x, y, id)
self.previousMap = 0
self:updateCurrentCharset()
self.onGround = true
self.isJumping = false
end
function Player:updateStart(dt)
@ -49,11 +51,23 @@ function Player:updateStart(dt)
end
if self.keys["select"].isPressed and self.canChangeActive then
if (self.onGround) then
game.characters:setActiveCharacter()
self.canChangeActive = false
self.tweens:newTimer(0.3, "changeCharacter")
self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + 1}, "inQuad")
end
end
if self.keys["B"].isPressed then
if (self.onGround) then
self.zsp = 2.5
self.grav = 10
self.onGround = false
self.isJumping = true
self.assets.sfx["jump"]:play()
end
end
self.tweens:update(dt)
@ -71,10 +85,44 @@ function Player:updateStart(dt)
self.scene:updateCurrentMap(currentMap)
end
end
self:updateCurrentCharset()
end
function Player:applyGravity(dt)
local grav = self.grav * -1
self.zsp = self.zsp + (grav * dt)
if utils.math.sign(self.zsp) == utils.math.sign(grav) then
self:checkGround( )
end
end
function Player:checkGround()
if (self.z + self.zsp <= 0) then
self.onGround = true
self.isJumping = false
self.z = 0
self.zsp = 0
end
end
function Player:autoMove(dt)
Player.super.autoMove(self, dt)
self.z = self.z + self.zsp
end
function Player:updateCurrentCharset()
if (not self.isJumping) then
self:setCharset(self.active.data.charset, self.active.data.charId)
self.largeAnim = false
self.isFast = false
else
self:setCharset(self.active.data.charset .. "-jump", self.active.data.charId)
self.largeAnim = true
self.isFast = true
end
end
function Player:collisionResponse(col)