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 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,21 +20,42 @@ function PlayerActions:canDoAction(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayerActions:actionMove()
|
function PlayerActions:actionMove()
|
||||||
if self.keys["up"].isDown then
|
if (self.currentAction == "jumpdash" or self.currentAction == "run") then
|
||||||
self.ysp = -BASE_SPEED
|
self.xsp, self.ysp = utils.math.lengthdir(BASE_SPEED * RUN_FACTOR, math.rad(self.charsetManager.angle[self.charDir]))
|
||||||
self.charDir = "up"
|
self.xsp = -self.xsp
|
||||||
end
|
if (utils.table.contain({"up", "down"}, self.charDir)) then
|
||||||
if self.keys["down"].isDown then
|
if self.keys["left"].isDown then
|
||||||
self.ysp = BASE_SPEED
|
self.xsp = -BASE_SPEED
|
||||||
self.charDir = "down"
|
end
|
||||||
end
|
if self.keys["right"].isDown then
|
||||||
if self.keys["left"].isDown then
|
self.xsp = BASE_SPEED
|
||||||
self.xsp = -BASE_SPEED
|
end
|
||||||
self.charDir = "left"
|
else
|
||||||
end
|
if self.keys["up"].isDown then
|
||||||
if self.keys["right"].isDown then
|
self.ysp = -BASE_SPEED
|
||||||
self.xsp = BASE_SPEED
|
end
|
||||||
self.charDir = "right"
|
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"
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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()
|
||||||
self.currentAction = "jump"
|
if (self.currentAction == "run") then
|
||||||
|
self.currentAction = "jumpdash"
|
||||||
|
else
|
||||||
|
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: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()
|
function PlayerActions:endJump()
|
||||||
self.currentAction = "idle"
|
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
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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"},
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue