78 lines
1.9 KiB
Lua
78 lines
1.9 KiB
Lua
local PlayerActions = Object:extend()
|
|
|
|
local BASE_SPEED = 120
|
|
local JMP_STRENGHT = 2.5
|
|
|
|
local ACTIONS = {}
|
|
ACTIONS["speedster"] = {"run"}
|
|
ACTIONS["technic"] = {"fly"}
|
|
ACTIONS["power"] = {"punch"}
|
|
|
|
function PlayerActions:initActions()
|
|
self.currentAction = "idle"
|
|
end
|
|
|
|
function PlayerActions:canDoAction(action)
|
|
local classCanDoAction = utils.table.contain(ACTIONS[self:getCurrentCharType()], action)
|
|
local playerCanDoAction = utils.table.contain(game.actions, action)
|
|
return (classCanDoAction and playerCanDoAction)
|
|
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()
|
|
self.currentAction = "jump"
|
|
elseif (self.currentAction == "jump" and self:canDoAction("fly")) then
|
|
self.currentAction = "fly"
|
|
self.grav = 0
|
|
self.zsp = 0
|
|
self.tweens:newTimer(0.75, "endFly")
|
|
self.assets.sfx["fly"]:play()
|
|
end
|
|
end
|
|
|
|
if self.keys["B"].isReleased then
|
|
self:endFly()
|
|
end
|
|
end
|
|
|
|
function PlayerActions:endFly()
|
|
if (self.currentAction == "fly") then
|
|
self:goUpward(0)
|
|
self.currentAction = "idle"
|
|
end
|
|
end
|
|
|
|
function PlayerActions:actionSwitch()
|
|
if self.keys["select"].isPressed and (self.currentAction == "idle") then
|
|
self:switchActiveCharacter()
|
|
end
|
|
end
|
|
|
|
function PlayerActions:endJump()
|
|
self.currentAction = "idle"
|
|
end
|
|
|
|
return PlayerActions
|