2021-04-10 17:14:41 +02:00
|
|
|
local PlayerActions = Object:extend()
|
|
|
|
|
|
|
|
local BASE_SPEED = 120
|
|
|
|
local JMP_STRENGHT = 2.5
|
|
|
|
|
|
|
|
function PlayerActions:initActions()
|
2021-04-10 17:41:53 +02:00
|
|
|
self.currentAction = "idle"
|
2021-04-10 17:14:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function PlayerActions:actionMove()
|
|
|
|
if self.keys["up"].isDown then
|
|
|
|
self.ysp = -BASE_SPEED
|
|
|
|
self.charDir = "up"
|
|
|
|
end
|
|
|
|
if self.keys["down"].isDown then
|
|
|
|
self.ysp = BASE_SPEED
|
|
|
|
self.charDir = "down"
|
|
|
|
end
|
|
|
|
if self.keys["left"].isDown then
|
|
|
|
self.xsp = -BASE_SPEED
|
|
|
|
self.charDir = "left"
|
|
|
|
end
|
|
|
|
if self.keys["right"].isDown then
|
|
|
|
self.xsp = BASE_SPEED
|
|
|
|
self.charDir = "right"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PlayerActions:actionJump()
|
|
|
|
if self.keys["B"].isPressed then
|
|
|
|
if (self.onGround) then
|
|
|
|
self:goUpward(JMP_STRENGHT)
|
|
|
|
self.assets.sfx["jump"]:play()
|
2021-04-10 17:41:53 +02:00
|
|
|
self.currentAction = "jump"
|
2021-04-10 17:14:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PlayerActions:actionSwitch()
|
2021-04-10 17:41:53 +02:00
|
|
|
if self.keys["select"].isPressed and (self.currentAction == "idle") then
|
2021-04-10 17:14:41 +02:00
|
|
|
self:switchActiveCharacter()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function PlayerActions:endJump()
|
2021-04-10 17:41:53 +02:00
|
|
|
self.currentAction = "idle"
|
2021-04-10 17:14:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return PlayerActions
|