From 84af3076f2089315c8d29efc887db06933efd556 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 10 Apr 2021 19:32:41 +0200 Subject: [PATCH] feat: add dash/run --- .../assets/sprites/gfx/dash.lua | 18 ++++ .../assets/sprites/gfx/dash.png | Bin 0 -> 1647 bytes .../overworld/actors/player/actions.lua | 91 ++++++++++++++---- .../overworld/actors/player/charset.lua | 4 +- .../scenes/overworld/actors/player/init.lua | 6 ++ .../scenes/overworld/assets.lua | 1 + .../scenes/overworld/charsetmanager.lua | 8 ++ 7 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 sonic-radiance.love/assets/sprites/gfx/dash.lua create mode 100644 sonic-radiance.love/assets/sprites/gfx/dash.png 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 0000000000000000000000000000000000000000..3ac30c7325e84b1bb3d1f66e0b14c922de72c49d GIT binary patch literal 1647 zcmV-#29WuQP)EX>4Tx04R}tk-JO7P!z_$rj?dbanQj^hYZz0EQo?QxLCy^R0y?#RR{CvLrBt) zq_{W=t_26t#n+&JfavPrDhPrih`9I<_*$gIbCW=ev|hNJU%s64aqo8l?p&2MD>Mpd zx^3n%X@0q|!iV1wLKI=d5f^34m==UAIjZCAHav}7Q_6VJ(pX%kn7 zCpK+^@ey&KToD!G3*r%z4oLjUbjjmS#$}he2xBv!n;}jR^W_$nT3D`_8u1iyQqgqs z=hi(|7;iJy)SB#{lie^@)Rz{i4%1E`0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;+aTTTJ;s>s;#5o8PQ3E z5L|pAR9=_Y0sB3{@GR_xnjRcMh?7Aa-)A+C)P7Ge>`|HSy21jf9GPp`=w5A2+YP^A zy8)b@Htg=d&qWA1iLRJi-r}=1Da)h{u~@5)<;GB_UbehrS~@i1(bBOiv&`fB*ww>; zlGB=e?+YYVN)dtb(T)lTUm$5OmLBt4qdpubpXe0Rn|Q)B#Dulq6D%J43PA)y2tM>& z)_Wg=E$TKM3H=PDIXRuK%}Hzz&zlMmC*acOCw4xI_K9WsfXfb`s9QDZ6G%H^NBIOY tbUJv1z1&B{&oJ23?_{q-hQz-3_5%UP3sZfqm)`&Y002ovPDHLkV1l*7_uv2k literal 0 HcmV?d00001 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)