feat: add a basic "punch" action

Fixes #78
This commit is contained in:
Kazhnuz 2021-04-10 20:47:34 +02:00
parent 84af3076f2
commit cd0190f065
9 changed files with 71 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 B

View file

@ -20,6 +20,9 @@ function PlayerActions:canDoAction(action)
end
function PlayerActions:actionMove()
if (self.currentAction == "punch") then
return
end
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
@ -112,6 +115,24 @@ function PlayerActions:actionRun()
end
end
function PlayerActions:actionPunch()
if self.keys["C"].isPressed then
if (self:canDoAction("punch")) then
self.xsp, self.ysp = utils.math.lengthdir(BASE_SPEED * RUN_FACTOR, math.rad(self.charsetManager.angle[self.charDir]))
self.xsp = -self.xsp
self.currentAction = "punch"
self.tweens:newTimer(0.15, "endPunch")
self.assets.sprites["punch"]:changeAnimation("default", true)
end
end
end
function PlayerActions:endPunch()
if (self.currentAction == "punch") then
self.currentAction = "idle"
end
end
function PlayerActions:endJump()
if (self.currentAction == "jump") then
self.currentAction = "idle"
@ -129,6 +150,15 @@ function PlayerActions:drawActionEffect()
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
if (self.currentAction == "punch") 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
print(x, y)
self.assets.sprites["punch"]:drawAnimation(x, y, math.rad(self.charsetManager.angle[self.charDir]))
end
end
return PlayerActions

View file

@ -21,6 +21,8 @@ function PlayerCharset:getCharset()
charset = charset .. "-jump"
elseif (self.currentAction == "fly") then
charset = charset .. "-flight"
elseif (self.currentAction == "punch") then
charset = charset .. "-jump"
end
return charset
end

View file

@ -39,6 +39,7 @@ function Player:updateStart(dt)
self:actionJump()
self:actionSwitch()
self:actionRun()
self:actionPunch()
self.world:getTileTypeAtPoint(self.x, self.y)
@ -98,6 +99,8 @@ function Player:timerResponse(response)
self:endCharacterSwitchAnimation()
elseif (response == "endFly") then
self:endFly()
elseif (response == "endPunch") then
self:endPunch()
end
end

View file

@ -0,0 +1,17 @@
local Base = require "core.modules.world.actors.actor2D"
local Punch = Base:extend()
function Punch:new(world, x, y, dir)
Punch.super.new(self, world, "wall", x, y, 8, 8, false)
end
function Punch:update(dt)
self.depth = -self.y
Punch.super.update(self, dt)
end
function Punch:draw()
end
return Punch

View file

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