feat: add dash/run
This commit is contained in:
parent
34b409f423
commit
84af3076f2
7 changed files with 109 additions and 19 deletions
18
sonic-radiance.love/assets/sprites/gfx/dash.lua
Normal file
18
sonic-radiance.love/assets/sprites/gfx/dash.lua
Normal 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,
|
||||
},
|
||||
}
|
||||
}
|
BIN
sonic-radiance.love/assets/sprites/gfx/dash.png
Normal file
BIN
sonic-radiance.love/assets/sprites/gfx/dash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -1,6 +1,7 @@
|
|||
local PlayerActions = Object:extend()
|
||||
|
||||
local BASE_SPEED = 120
|
||||
local RUN_FACTOR = 2.5
|
||||
local JMP_STRENGHT = 2.5
|
||||
|
||||
local ACTIONS = {}
|
||||
|
@ -19,6 +20,26 @@ function PlayerActions:canDoAction(action)
|
|||
end
|
||||
|
||||
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
|
||||
self.ysp = -BASE_SPEED
|
||||
self.charDir = "up"
|
||||
|
@ -35,6 +56,7 @@ function PlayerActions:actionMove()
|
|||
self.xsp = BASE_SPEED
|
||||
self.charDir = "right"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PlayerActions:actionJump()
|
||||
|
@ -42,7 +64,11 @@ function PlayerActions:actionJump()
|
|||
if (self.onGround) then
|
||||
self:goUpward(JMP_STRENGHT)
|
||||
self.assets.sfx["jump"]:play()
|
||||
if (self.currentAction == "run") then
|
||||
self.currentAction = "jumpdash"
|
||||
else
|
||||
self.currentAction = "jump"
|
||||
end
|
||||
elseif (self.currentAction == "jump" and self:canDoAction("fly")) then
|
||||
self.currentAction = "fly"
|
||||
self.grav = 0
|
||||
|
@ -70,8 +96,39 @@ function PlayerActions:actionSwitch()
|
|||
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"
|
||||
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
|
||||
|
||||
return PlayerActions
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local PlayerCharset = Object:extend()
|
||||
|
||||
local ACTIONS_LARGEANIM = {"jump"}
|
||||
local ACTIONS_ISFAST = {"jump", "fly"}
|
||||
local ACTIONS_ISFAST = {"jump", "fly", "run", "jumpdash"}
|
||||
local ACTIONS_ALWAYSWALK = {"fly"}
|
||||
|
||||
function PlayerCharset:initPlayerCharset()
|
||||
|
@ -17,7 +17,7 @@ end
|
|||
|
||||
function PlayerCharset:getCharset()
|
||||
local charset = self.active.data.charset
|
||||
if (self.currentAction == "jump") then
|
||||
if (self.currentAction == "jump" or self.currentAction == "jumpdash") then
|
||||
charset = charset .. "-jump"
|
||||
elseif (self.currentAction == "fly") then
|
||||
charset = charset .. "-flight"
|
||||
|
|
|
@ -38,6 +38,7 @@ function Player:updateStart(dt)
|
|||
self:actionMove()
|
||||
self:actionJump()
|
||||
self:actionSwitch()
|
||||
self:actionRun()
|
||||
|
||||
self.world:getTileTypeAtPoint(self.x, self.y)
|
||||
|
||||
|
@ -104,4 +105,9 @@ function Player:drawHUD(id)
|
|||
self:drawEmblems(self.scene:getEmblemsPosition(), 24)
|
||||
end
|
||||
|
||||
function Player:draw()
|
||||
Player.super.draw(self)
|
||||
self:drawActionEffect()
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
@ -9,6 +9,7 @@ return {
|
|||
{"cursorground", "assets/gui/cursor/ground"},
|
||||
{"hitGFX", "assets/sprites/gfx/hit"},
|
||||
{"encounter", "assets/sprites/encounter"},
|
||||
{"dash", "assets/sprites/gfx/dash"},
|
||||
},
|
||||
["textures"] = {
|
||||
{"menucursor", "assets/gui/cursor-menulist.png"},
|
||||
|
|
|
@ -4,6 +4,13 @@ local folder = "assets/sprites/charset/"
|
|||
local animation = {1, 2, 3, 2}
|
||||
local directionList = {"down", "right", "up", "left"}
|
||||
|
||||
local angle = {
|
||||
down = 270,
|
||||
right = 180,
|
||||
up = 90,
|
||||
left = 0
|
||||
}
|
||||
|
||||
local CHARWIDTH = 38
|
||||
local CHARHEIGHT = 48
|
||||
local FAST_BOOST = 2.5
|
||||
|
@ -22,6 +29,7 @@ function Charset:new(scene)
|
|||
end
|
||||
self.currentFrame = 0
|
||||
self.fastFrame = 0
|
||||
self.angle = angle
|
||||
end
|
||||
|
||||
function Charset:update(dt)
|
||||
|
|
Loading…
Reference in a new issue