diff --git a/sonic-radiance.love/assets/sprites/gfx/dash.lua b/sonic-radiance.love/assets/sprites/gfx/dash.lua new file mode 100644 index 0000000..41713d7 --- /dev/null +++ b/sonic-radiance.love/assets/sprites/gfx/dash.lua @@ -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, + }, + } +} diff --git a/sonic-radiance.love/assets/sprites/gfx/dash.png b/sonic-radiance.love/assets/sprites/gfx/dash.png new file mode 100644 index 0000000..3ac30c7 Binary files /dev/null and b/sonic-radiance.love/assets/sprites/gfx/dash.png differ diff --git a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua index 9d3d320..5f162d6 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/actions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/actions.lua @@ -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,21 +20,42 @@ function PlayerActions:canDoAction(action) end function PlayerActions:actionMove() - 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" + 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" + 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 @@ -42,7 +64,11 @@ function PlayerActions:actionJump() if (self.onGround) then self:goUpward(JMP_STRENGHT) 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 self.currentAction = "fly" self.grav = 0 @@ -70,8 +96,39 @@ function PlayerActions:actionSwitch() 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() - 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 return PlayerActions diff --git a/sonic-radiance.love/scenes/overworld/actors/player/charset.lua b/sonic-radiance.love/scenes/overworld/actors/player/charset.lua index 58001b0..6e16906 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/charset.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/charset.lua @@ -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" diff --git a/sonic-radiance.love/scenes/overworld/actors/player/init.lua b/sonic-radiance.love/scenes/overworld/actors/player/init.lua index d7f9267..1b95d27 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/init.lua @@ -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 diff --git a/sonic-radiance.love/scenes/overworld/assets.lua b/sonic-radiance.love/scenes/overworld/assets.lua index ee834e3..e3a51bb 100644 --- a/sonic-radiance.love/scenes/overworld/assets.lua +++ b/sonic-radiance.love/scenes/overworld/assets.lua @@ -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"}, diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua index 1fdc205..023bc8e 100644 --- a/sonic-radiance.love/scenes/overworld/charsetmanager.lua +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -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)