chore: prepare action system

This commit is contained in:
Kazhnuz 2021-04-10 17:41:53 +02:00
parent 1281bb30c4
commit 91c885e1fb
2 changed files with 28 additions and 15 deletions

View file

@ -4,7 +4,7 @@ local BASE_SPEED = 120
local JMP_STRENGHT = 2.5 local JMP_STRENGHT = 2.5
function PlayerActions:initActions() function PlayerActions:initActions()
self.isJumping = false self.currentAction = "idle"
end end
function PlayerActions:actionMove() function PlayerActions:actionMove()
@ -30,20 +30,20 @@ function PlayerActions:actionJump()
if self.keys["B"].isPressed then if self.keys["B"].isPressed then
if (self.onGround) then if (self.onGround) then
self:goUpward(JMP_STRENGHT) self:goUpward(JMP_STRENGHT)
self.isJumping = true
self.assets.sfx["jump"]:play() self.assets.sfx["jump"]:play()
self.currentAction = "jump"
end end
end end
end end
function PlayerActions:actionSwitch() function PlayerActions:actionSwitch()
if self.keys["select"].isPressed and self.onGround then if self.keys["select"].isPressed and (self.currentAction == "idle") then
self:switchActiveCharacter() self:switchActiveCharacter()
end end
end end
function PlayerActions:endJump() function PlayerActions:endJump()
self.isJumping = false self.currentAction = "idle"
end end
return PlayerActions return PlayerActions

View file

@ -1,19 +1,32 @@
local PlayerCharset = Object:extend() local PlayerCharset = Object:extend()
local ACTIONS_LARGEANIM = {"jump"}
local ACTIONS_ISFAST = {"jump"}
function PlayerCharset:initPlayerCharset() function PlayerCharset:initPlayerCharset()
self:updateCurrentCharset() self:updateCurrentCharset()
end end
function PlayerCharset:updateCurrentCharset() function PlayerCharset:updateCurrentCharset()
if (not self.isJumping) then self:setCharset(self:getCharset(), self.active.data.charId)
self:setCharset(self.active.data.charset, self.active.data.charId) self.isFast = self:getIsFast()
self.largeAnim = false self.largeAnim = self:getLargeAnim()
self.isFast = false
else
self:setCharset(self.active.data.charset .. "-jump", self.active.data.charId)
self.largeAnim = true
self.isFast = true
end end
function PlayerCharset:getCharset()
local charset = self.active.data.charset
if (self.currentAction == "jump") then
charset = charset .. "-jump"
end
return charset
end
function PlayerCharset:getLargeAnim()
return utils.table.contain(ACTIONS_ISFAST, self.currentAction)
end
function PlayerCharset:getIsFast()
return utils.table.contain(ACTIONS_LARGEANIM, self.currentAction)
end end
return PlayerCharset return PlayerCharset