feat: add dash/run

This commit is contained in:
Kazhnuz 2021-04-10 19:32:41 +02:00
parent 34b409f423
commit 84af3076f2
7 changed files with 109 additions and 19 deletions

View file

@ -0,0 +1,18 @@
return {
metadata = {
width = 26,
height = 44,
defaultAnim = "default",
ox = 0,
oy = 22,
},
animations = {
["default"] = {
startAt = 1,
endAt = 4,
loop = 1,
speed = 15,
pauseAtEnd = false,
},
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -1,6 +1,7 @@
local PlayerActions = Object:extend() local PlayerActions = Object:extend()
local BASE_SPEED = 120 local BASE_SPEED = 120
local RUN_FACTOR = 2.5
local JMP_STRENGHT = 2.5 local JMP_STRENGHT = 2.5
local ACTIONS = {} local ACTIONS = {}
@ -19,6 +20,26 @@ function PlayerActions:canDoAction(action)
end end
function PlayerActions:actionMove() function PlayerActions:actionMove()
if (self.currentAction == "jumpdash" or self.currentAction == "run") then
self.xsp, self.ysp = utils.math.lengthdir(BASE_SPEED * RUN_FACTOR, math.rad(self.charsetManager.angle[self.charDir]))
self.xsp = -self.xsp
if (utils.table.contain({"up", "down"}, self.charDir)) then
if self.keys["left"].isDown then
self.xsp = -BASE_SPEED
end
if self.keys["right"].isDown then
self.xsp = BASE_SPEED
end
else
if self.keys["up"].isDown then
self.ysp = -BASE_SPEED
end
if self.keys["down"].isDown then
self.ysp = BASE_SPEED
end
end
else
if self.keys["up"].isDown then if self.keys["up"].isDown then
self.ysp = -BASE_SPEED self.ysp = -BASE_SPEED
self.charDir = "up" self.charDir = "up"
@ -35,6 +56,7 @@ function PlayerActions:actionMove()
self.xsp = BASE_SPEED self.xsp = BASE_SPEED
self.charDir = "right" self.charDir = "right"
end end
end
end end
function PlayerActions:actionJump() function PlayerActions:actionJump()
@ -42,7 +64,11 @@ function PlayerActions:actionJump()
if (self.onGround) then if (self.onGround) then
self:goUpward(JMP_STRENGHT) self:goUpward(JMP_STRENGHT)
self.assets.sfx["jump"]:play() self.assets.sfx["jump"]:play()
if (self.currentAction == "run") then
self.currentAction = "jumpdash"
else
self.currentAction = "jump" self.currentAction = "jump"
end
elseif (self.currentAction == "jump" and self:canDoAction("fly")) then elseif (self.currentAction == "jump" and self:canDoAction("fly")) then
self.currentAction = "fly" self.currentAction = "fly"
self.grav = 0 self.grav = 0
@ -70,8 +96,39 @@ function PlayerActions:actionSwitch()
end end
end end
function PlayerActions:endJump() function PlayerActions:actionRun()
if self.keys["C"].isDown then
if (self:canDoAction("run")) then
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
end
elseif (self.currentAction == "run") then
self.currentAction = "idle" self.currentAction = "idle"
elseif (self.currentAction == "jumpdash") then
self.currentAction = "jump"
end
end
function PlayerActions:endJump()
if (self.currentAction == "jump") then
self.currentAction = "idle"
elseif (self.currentAction == "jumpdash") then
self.currentAction = "run"
end
end
function PlayerActions:drawActionEffect()
if (((self.currentAction == "run") or (self.currentAction == "jumpdash")) and (self.xsp ~= 0 or self.ysp ~= 0)) then
local dx, dy = utils.math.lengthdir(20, math.rad(self.charsetManager.angle[self.charDir]))
if (self.charDir == "down") 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]))
end
end end
return PlayerActions return PlayerActions

View file

@ -1,7 +1,7 @@
local PlayerCharset = Object:extend() local PlayerCharset = Object:extend()
local ACTIONS_LARGEANIM = {"jump"} local ACTIONS_LARGEANIM = {"jump"}
local ACTIONS_ISFAST = {"jump", "fly"} local ACTIONS_ISFAST = {"jump", "fly", "run", "jumpdash"}
local ACTIONS_ALWAYSWALK = {"fly"} local ACTIONS_ALWAYSWALK = {"fly"}
function PlayerCharset:initPlayerCharset() function PlayerCharset:initPlayerCharset()
@ -17,7 +17,7 @@ end
function PlayerCharset:getCharset() function PlayerCharset:getCharset()
local charset = self.active.data.charset local charset = self.active.data.charset
if (self.currentAction == "jump") then if (self.currentAction == "jump" or self.currentAction == "jumpdash") then
charset = charset .. "-jump" charset = charset .. "-jump"
elseif (self.currentAction == "fly") then elseif (self.currentAction == "fly") then
charset = charset .. "-flight" charset = charset .. "-flight"

View file

@ -38,6 +38,7 @@ function Player:updateStart(dt)
self:actionMove() self:actionMove()
self:actionJump() self:actionJump()
self:actionSwitch() self:actionSwitch()
self:actionRun()
self.world:getTileTypeAtPoint(self.x, self.y) self.world:getTileTypeAtPoint(self.x, self.y)
@ -104,4 +105,9 @@ function Player:drawHUD(id)
self:drawEmblems(self.scene:getEmblemsPosition(), 24) self:drawEmblems(self.scene:getEmblemsPosition(), 24)
end end
function Player:draw()
Player.super.draw(self)
self:drawActionEffect()
end
return Player return Player

View file

@ -9,6 +9,7 @@ return {
{"cursorground", "assets/gui/cursor/ground"}, {"cursorground", "assets/gui/cursor/ground"},
{"hitGFX", "assets/sprites/gfx/hit"}, {"hitGFX", "assets/sprites/gfx/hit"},
{"encounter", "assets/sprites/encounter"}, {"encounter", "assets/sprites/encounter"},
{"dash", "assets/sprites/gfx/dash"},
}, },
["textures"] = { ["textures"] = {
{"menucursor", "assets/gui/cursor-menulist.png"}, {"menucursor", "assets/gui/cursor-menulist.png"},

View file

@ -4,6 +4,13 @@ local folder = "assets/sprites/charset/"
local animation = {1, 2, 3, 2} local animation = {1, 2, 3, 2}
local directionList = {"down", "right", "up", "left"} local directionList = {"down", "right", "up", "left"}
local angle = {
down = 270,
right = 180,
up = 90,
left = 0
}
local CHARWIDTH = 38 local CHARWIDTH = 38
local CHARHEIGHT = 48 local CHARHEIGHT = 48
local FAST_BOOST = 2.5 local FAST_BOOST = 2.5
@ -22,6 +29,7 @@ function Charset:new(scene)
end end
self.currentFrame = 0 self.currentFrame = 0
self.fastFrame = 0 self.fastFrame = 0
self.angle = angle
end end
function Charset:update(dt) function Charset:update(dt)