feat: make that any actor can block choregraphy

This commit is contained in:
Kazhnuz 2021-08-07 11:28:27 +02:00
parent bccc71ec58
commit 28a869a42e
3 changed files with 86 additions and 78 deletions

View file

@ -25,10 +25,6 @@ function Battler:new(world, x, y, z, owner)
self.owner = owner
self.isDefending = false
self.tags = {}
self.choregraphy = nil
self.frameSignals = {}
end
function Battler:destroy()
@ -84,68 +80,15 @@ function Battler:update(dt)
end
end
function Battler:purgeFrameSignal()
self.frameSignals = {}
end
function Battler:receiveFrameSignal(signal)
table.insert(self.frameSignals, signal)
end
function Battler:haveFrameSignal(signal)
return utils.table.contain(self.frameSignals, signal)
end
-- CHOREGRAPHY FUNCTIONS
-- All functions related to the choregraphy system
function Battler:blockChoregraphy(isBlocking, currentlyBlocking, blockedBy)
if (isBlocking) then
self.currentlyBlocking = currentlyBlocking
self.blockedBy = blockedBy
end
end
function Battler:addTaggedAction(tag, choregraphy, taggedBy)
if (not utils.string.isEmpty(tag)) then
self.tags[tag] = taggedBy
self.choregraphy = choregraphy
end
end
function Battler:unlockTag(taggedBy)
for tag, actionTag in pairs(self.tags) do
if (self.choregraphy ~= nil) and (actionTag == taggedBy) then
self.choregraphy:finishTagAction(tag)
self.tags[tag] = nil
end
end
end
function Battler:unblockChoregraphy()
self.currentlyBlocking:finish()
self.currentlyBlocking = nil
end
function Battler:timerResponse(signal)
self:finishAction(signal)
if (signal == "removeOutput") then
self.showOutput = false
end
end
function Battler:finishAction(signal)
if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
self:unblockChoregraphy()
end
self:unlockTag(signal)
end
function Battler:choregraphyEnded()
self:resetMovement()
end
-- DAMAGE FUNCTIONS
function Battler:getHurt()
end
@ -183,23 +126,6 @@ function Battler:initSprite()
self:changeAnimation("idle")
end
function Battler:changeAnimation(animation, restart)
self:purgeFrameSignal()
Battler.super.changeAnimation(self, animation, restart)
end
function Battler:animationEnded(animation)
if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then
self:unblockChoregraphy()
end
self:unlockTag("animation")
self:getNewAnimation(animation)
end
function Battler:getNewAnimation(animation)
end
function Battler:validateAction()
end

View file

@ -29,6 +29,8 @@ function Parent:new(world, x, y, z)
self.tweens = TweenManager(self)
self:resetTags()
self:setSprite()
self:register()
end
@ -67,6 +69,8 @@ function Parent:setSprite(spritename, ox, oy, active)
self.sprite.exist = (spritename ~= nil)
self.sprite.clone = nil
self.sprite.active = active or false
self:resetFrameSignal()
end
function Parent:cloneSprite()
@ -77,6 +81,7 @@ function Parent:cloneSprite()
end
function Parent:changeAnimation(animation, restart)
self:resetFrameSignal()
if (self.sprite.clone == nil) then
self.assets.sprites[self.sprite.name]:changeAnimation(animation, restart)
else
@ -93,7 +98,15 @@ function Parent:setAnimSpeed(speed)
end
function Parent:animationEnded(animation)
-- Empty placeholder function
if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then
self:unblockChoregraphy()
end
self:unlockTag("animation")
self:getNewAnimation(animation)
end
function Parent:getNewAnimation(animation)
end
function Parent:setCustomSpeed(customSpeed)
@ -184,6 +197,75 @@ function Parent:drawSprite(tx, ty)
end
end
-- FRAME SIGNAL
-- Get signals from specific frames of the animation
function Parent:resetFrameSignal()
self.frameSignals = {}
end
function Parent:receiveFrameSignal(signal)
table.insert(self.frameSignals, signal)
end
function Parent:haveFrameSignal(signal)
return utils.table.contain(self.frameSignals, signal)
end
-- TAGS
-- Handle tags
function Parent:resetTags()
self.tags = {}
self.choregraphy = nil
end
function Parent:addTaggedAction(tag, choregraphy, taggedBy)
if (not utils.string.isEmpty(tag)) then
self.tags[tag] = taggedBy
self.choregraphy = choregraphy
end
end
function Parent:unlockTag(taggedBy)
for tag, actionTag in pairs(self.tags) do
if (self.choregraphy ~= nil) and (actionTag == taggedBy) then
self.choregraphy:finishTagAction(tag)
self.tags[tag] = nil
end
end
end
-- CHOREGRAPHY BLOCKING
-- Handle blocking/unblocking the choregraphy
function Parent:blockChoregraphy(isBlocking, currentlyBlocking, blockedBy)
if (isBlocking) then
self.currentlyBlocking = currentlyBlocking
self.blockedBy = blockedBy
end
end
function Parent:unblockChoregraphy()
self.currentlyBlocking:finish()
self.currentlyBlocking = nil
end
function Parent:timerResponse(signal)
self:finishAction(signal)
if (signal == "removeOutput") then
self.showOutput = false
end
end
function Parent:finishAction(signal)
if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
self:unblockChoregraphy()
end
self:unlockTag(signal)
end
-- DRAW FUNCTIONS
-- Handle draw functions

View file

@ -13,7 +13,7 @@ function ChoregraphySystem:new(action, choregraphy)
self.action = action
self.fighter = action.fighter
self.actor = self.fighter.actor
self.actor:purgeFrameSignal()
self.actor:resetFrameSignal()
self.assets = self.fighter.actor.assets
self.world = self.actor.world
self.target = action.target