feat: add hit combo

This commit is contained in:
Kazhnuz 2022-05-28 11:55:21 +02:00
parent 3545e6b898
commit 4598b25e05
7 changed files with 80 additions and 11 deletions

View file

@ -1,17 +1,23 @@
local PlayerControls = Object:extend() local PlayerControls = Object:extend()
function PlayerControls:applyInputs() function PlayerControls:applyInputs()
if (self.world.autorun == true) then self:applyMoveInput()
self:applyAutorunInput()
else
self:applyMoveInput()
end
self:applyJumpInput() self:applyJumpInput()
self:applyActionsInputs() self:applyActionsInputs()
self:applySwitchInputs() self:applySwitchInputs()
end end
function PlayerControls:applyMoveInput() function PlayerControls:applyMoveInput()
if (self:getStateVar("canMove", false)) then
if (self.world.autorun == true) then
self:applyAutorunInput()
else
self:applyFreemoveInput()
end
end
end
function PlayerControls:applyFreemoveInput()
local angle, strenght = self:dpadToAngle() local angle, strenght = self:dpadToAngle()
if (strenght ~= 0) then if (strenght ~= 0) then
self:goTowardDir(angle, strenght) self:goTowardDir(angle, strenght)
@ -62,8 +68,9 @@ end
function PlayerControls:applyActionsInputs() function PlayerControls:applyActionsInputs()
if self.keys["B"].isPressed and (self.onGround) then if self.keys["B"].isPressed then
-- Nothing for the moment --self:setState("hit1")
self:playStateFunc("bAction")
end end
end end

View file

@ -38,10 +38,6 @@ function Player:timerResponse(response)
end end
end end
function Player:animationEnded(name)
end
function Player:getViewCenter() function Player:getViewCenter()
local x, y = Player.super.getViewCenter(self) local x, y = Player.super.getViewCenter(self)
return x, y-16 return x, y-16

View file

@ -0,0 +1,20 @@
local hit1state = {}
hit1state.canSwitch = false
hit1state.canJump = false
hit1state.defaultAnim = false
hit1state.canMove = false
function hit1state:start()
self.sprite:changeAnimation("hit1", true)
end
function hit1state:bAction()
self:setState("hit2")
end
function hit1state:animationEnded()
self:setState("idle")
end
return hit1state

View file

@ -0,0 +1,20 @@
local hit1state = {}
hit1state.canSwitch = false
hit1state.canJump = false
hit1state.defaultAnim = false
hit1state.canMove = false
function hit1state:start()
self.sprite:changeAnimation("hit2", true)
end
function hit1state:bAction()
self:setState("hit3")
end
function hit1state:animationEnded()
self:setState("idle")
end
return hit1state

View file

@ -0,0 +1,16 @@
local hit1state = {}
hit1state.canSwitch = false
hit1state.canJump = false
hit1state.defaultAnim = false
hit1state.canMove = false
function hit1state:start()
self.sprite:changeAnimation("hit3", true)
end
function hit1state:animationEnded()
self:setState("idle")
end
return hit1state

View file

@ -3,5 +3,12 @@ local idleState = {}
idleState.canSwitch = true idleState.canSwitch = true
idleState.canJump = true idleState.canJump = true
idleState.defaultAnim = true idleState.defaultAnim = true
idleState.canMove = true
function idleState:bAction()
if (self.onGround) then
self:setState("hit1")
end
end
return idleState return idleState

View file

@ -1,3 +1,6 @@
return { return {
"idle", "idle",
"hit1",
"hit2",
"hit3",
} }