improvement: improve the run/dash action
This commit is contained in:
parent
38c197a9fb
commit
9a9615b120
2 changed files with 40 additions and 8 deletions
Binary file not shown.
|
@ -15,6 +15,7 @@ function PlayerActions:initActions()
|
|||
self.canAct = true
|
||||
self.speedFactor = 1
|
||||
self.forceAction = nil
|
||||
self.dashJustStarted = false
|
||||
end
|
||||
|
||||
function PlayerActions:canDoAction(action)
|
||||
|
@ -59,24 +60,43 @@ function PlayerActions:actionMove()
|
|||
end
|
||||
|
||||
if (self.currentAction == "jumpdash" or self.currentAction == "run") then
|
||||
self.xsp, self.ysp = utils.math.lengthdir(charSpeed * RUN_FACTOR, math.rad(self.charsetManager.angle[self.charDir]))
|
||||
self.xsp = -self.xsp
|
||||
local xsp, ysp = self:getDash()
|
||||
if (utils.table.contain({"up", "down"}, self.charDir)) then
|
||||
if self.keys["left"].isDown then
|
||||
self.xsp = -charSpeed
|
||||
xsp = -charSpeed
|
||||
end
|
||||
if self.keys["right"].isDown then
|
||||
self.xsp = charSpeed
|
||||
xsp = charSpeed
|
||||
end
|
||||
if (self.ysp == 0) then
|
||||
if (self.currentAction == "jumpdash") then
|
||||
self.currentAction = "jump"
|
||||
else
|
||||
self.currentAction = "idle"
|
||||
end
|
||||
elseif (self.dashJustStarted) then
|
||||
self.dashJustStarted = false
|
||||
self.assets.sfx["dash"]:play()
|
||||
end
|
||||
else
|
||||
if self.keys["up"].isDown then
|
||||
self.ysp = -charSpeed
|
||||
ysp = -charSpeed
|
||||
end
|
||||
if self.keys["down"].isDown then
|
||||
self.ysp = charSpeed
|
||||
ysp = charSpeed
|
||||
end
|
||||
if (self.xsp == 0) then
|
||||
if (self.currentAction == "jumpdash") then
|
||||
self.currentAction = "jump"
|
||||
else
|
||||
self.currentAction = "idle"
|
||||
end
|
||||
elseif (self.dashJustStarted) then
|
||||
self.dashJustStarted = false
|
||||
self.assets.sfx["dash"]:play()
|
||||
end
|
||||
end
|
||||
|
||||
self.xsp, self.ysp = xsp, ysp
|
||||
else
|
||||
if self.keys["up"].isDown then
|
||||
self.ysp = -charSpeed
|
||||
|
@ -97,6 +117,15 @@ function PlayerActions:actionMove()
|
|||
end
|
||||
end
|
||||
|
||||
function PlayerActions:getCharspeed()
|
||||
return BASE_SPEED * self.speedFactor
|
||||
end
|
||||
|
||||
function PlayerActions:getDash()
|
||||
local xsp, ysp = utils.math.lengthdir(self:getCharspeed() * RUN_FACTOR, math.rad(self.charsetManager.angle[self.charDir]))
|
||||
return -xsp, ysp
|
||||
end
|
||||
|
||||
function PlayerActions:actionJump()
|
||||
if self.keys["B"].isPressed then
|
||||
if (self.onGround and self.canJump) then
|
||||
|
@ -137,12 +166,13 @@ end
|
|||
function PlayerActions:actionRun()
|
||||
if self.keys["C"].isPressed then
|
||||
if (self:canDoAction("run") and self.speedFactor > 0) then
|
||||
self.assets.sfx["dash"]:play()
|
||||
self.dashJustStarted = true
|
||||
if (utils.table.contain({"run", "idle"}, self.currentAction)) then
|
||||
self.currentAction = "run"
|
||||
elseif (utils.table.contain({"jumpdash", "jump"}, self.currentAction)) then
|
||||
self.currentAction = "jumpdash"
|
||||
end
|
||||
self.xsp, self.ysp = self:getDash()
|
||||
end
|
||||
elseif (not self.keys["C"].isDown) then
|
||||
if (self.currentAction == "run") then
|
||||
|
@ -185,6 +215,8 @@ function PlayerActions:drawActionEffect()
|
|||
local dx, dy = utils.math.lengthdir(20, math.rad(self.charsetManager.angle[self.charDir]))
|
||||
if (self.charDir == "down") then
|
||||
dy = 8
|
||||
elseif (self.charDir == "left" or self.charDir == "right") then
|
||||
dy = -8
|
||||
end
|
||||
local x, y = self.x + 8 - dx, self.y + 8 - self.z + dy
|
||||
self.assets.sprites["dash"]:drawAnimation(x, y, math.rad(self.charsetManager.angle[self.charDir]))
|
||||
|
|
Loading…
Reference in a new issue