feat: add flight

This commit is contained in:
Kazhnuz 2021-04-10 18:28:52 +02:00
parent 8f27270c39
commit 34b409f423
7 changed files with 35 additions and 6 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -30,6 +30,7 @@ function Parent:initCharset()
self.isTurning = false self.isTurning = false
self.isFast = false self.isFast = false
self.largeAnim = false self.largeAnim = false
self.alwaysWalk = false
end end
function Parent:setCharset(charset, charId, cantWalk) function Parent:setCharset(charset, charId, cantWalk)
@ -50,7 +51,7 @@ function Parent:drawCharset(charset, charId)
self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast) self.charsetManager:drawLargeAnim(self.charset, self.charId, self.charDir, x, y - z, self.isFast)
else else
if (not self.isTurning) then if (not self.isTurning) then
if (self:isMoving() and (not self.cantWalk)) then if ((self:isMoving() and (not self.cantWalk)) or self.alwaysWalk) then
self.charsetManager:drawMoving(self.charset, self.charId, self.charDir, x, y - z, self.isFast) self.charsetManager:drawMoving(self.charset, self.charId, self.charDir, x, y - z, self.isFast)
else else
self.charsetManager:drawStanding(self.charset, self.charId, self.charDir, x, y - z, self.isFast) self.charsetManager:drawStanding(self.charset, self.charId, self.charDir, x, y - z, self.isFast)

View file

@ -43,8 +43,25 @@ function PlayerActions:actionJump()
self:goUpward(JMP_STRENGHT) self:goUpward(JMP_STRENGHT)
self.assets.sfx["jump"]:play() self.assets.sfx["jump"]:play()
self.currentAction = "jump" self.currentAction = "jump"
elseif (self.currentAction == "jump" and self:canDoAction("fly")) then
self.currentAction = "fly"
self.grav = 0
self.zsp = 0
self.tweens:newTimer(0.75, "endFly")
self.assets.sfx["fly"]:play()
end end
end end
if self.keys["B"].isReleased then
self:endFly()
end
end
function PlayerActions:endFly()
if (self.currentAction == "fly") then
self:goUpward(0)
self.currentAction = "idle"
end
end end
function PlayerActions:actionSwitch() function PlayerActions:actionSwitch()

View file

@ -1,7 +1,8 @@
local PlayerCharset = Object:extend() local PlayerCharset = Object:extend()
local ACTIONS_LARGEANIM = {"jump"} local ACTIONS_LARGEANIM = {"jump"}
local ACTIONS_ISFAST = {"jump"} local ACTIONS_ISFAST = {"jump", "fly"}
local ACTIONS_ALWAYSWALK = {"fly"}
function PlayerCharset:initPlayerCharset() function PlayerCharset:initPlayerCharset()
self:updateCurrentCharset() self:updateCurrentCharset()
@ -11,22 +12,29 @@ function PlayerCharset:updateCurrentCharset()
self:setCharset(self:getCharset(), self.active.data.charId) self:setCharset(self:getCharset(), self.active.data.charId)
self.isFast = self:getIsFast() self.isFast = self:getIsFast()
self.largeAnim = self:getLargeAnim() self.largeAnim = self:getLargeAnim()
self.alwaysWalk = self:getAlwaysWalk()
end 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") then
charset = charset .. "-jump" charset = charset .. "-jump"
elseif (self.currentAction == "fly") then
charset = charset .. "-flight"
end end
return charset return charset
end end
function PlayerCharset:getLargeAnim() function PlayerCharset:getLargeAnim()
return utils.table.contain(ACTIONS_ISFAST, self.currentAction)
end
function PlayerCharset:getIsFast()
return utils.table.contain(ACTIONS_LARGEANIM, self.currentAction) return utils.table.contain(ACTIONS_LARGEANIM, self.currentAction)
end end
function PlayerCharset:getIsFast()
return utils.table.contain(ACTIONS_ISFAST, self.currentAction)
end
function PlayerCharset:getAlwaysWalk()
return utils.table.contain(ACTIONS_ALWAYSWALK, self.currentAction)
end
return PlayerCharset return PlayerCharset

View file

@ -95,6 +95,8 @@ end
function Player:timerResponse(response) function Player:timerResponse(response)
if (response == "changeCharacter") then if (response == "changeCharacter") then
self:endCharacterSwitchAnimation() self:endCharacterSwitchAnimation()
elseif (response == "endFly") then
self:endFly()
end end
end end

View file

@ -45,6 +45,7 @@ return {
{"hit", "assets/sfx/hit.wav"}, {"hit", "assets/sfx/hit.wav"},
{"hitconnect", "assets/sfx/hitconnect.wav"}, {"hitconnect", "assets/sfx/hitconnect.wav"},
{"jump", "assets/sfx/jump.wav"}, {"jump", "assets/sfx/jump.wav"},
{"fly", "assets/sfx/flight.wav"},
{"woosh", "assets/sfx/woosh.wav"}, {"woosh", "assets/sfx/woosh.wav"},
{"spincharge", "assets/sfx/spincharge.wav"}, {"spincharge", "assets/sfx/spincharge.wav"},
{"spinrelease", "assets/sfx/spinrelease.wav"}, {"spinrelease", "assets/sfx/spinrelease.wav"},