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

View file

@ -1,19 +1,32 @@
local PlayerCharset = Object:extend()
local ACTIONS_LARGEANIM = {"jump"}
local ACTIONS_ISFAST = {"jump"}
function PlayerCharset:initPlayerCharset()
self:updateCurrentCharset()
end
function PlayerCharset: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
self:setCharset(self:getCharset(), self.active.data.charId)
self.isFast = self:getIsFast()
self.largeAnim = self:getLargeAnim()
end
return PlayerCharset
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
return PlayerCharset