sonic-radiance/sonic-radiance.love/scenes/overworld/actors/player/actions.lua
2021-04-10 17:59:01 +02:00

61 lines
1.5 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"
end
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