2019-08-14 16:26:23 +02:00
|
|
|
local Parent = Object:extend() -- On créer la classe des entitées, c'est la classe de base
|
|
|
|
|
|
|
|
local maputils = require "scenes.battlesystem.utils"
|
|
|
|
|
2021-05-05 11:41:25 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
2019-08-16 23:04:30 +02:00
|
|
|
|
2019-08-14 20:11:35 +02:00
|
|
|
-- INIT FUNCTION
|
|
|
|
-- Initilize the actor
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Parent:new(world, x, y, z)
|
|
|
|
self.depth = 0
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.z = z or 0
|
|
|
|
self.direction = 1
|
|
|
|
--self.id = self.world.creationID
|
|
|
|
|
|
|
|
self.world = world
|
|
|
|
self.assets = self.world.assets
|
|
|
|
self.scene = self.world.scene
|
|
|
|
self.map = self.world.map
|
|
|
|
|
|
|
|
self.maputils = maputils
|
|
|
|
|
|
|
|
self.isHero = false
|
|
|
|
self.isActor = false
|
|
|
|
self.isEnnemy = false
|
2019-08-15 15:06:13 +02:00
|
|
|
self.isDestroyed = false
|
2019-08-14 16:26:23 +02:00
|
|
|
|
2019-08-16 23:04:30 +02:00
|
|
|
self.tweens = TweenManager(self)
|
2019-08-18 19:02:14 +02:00
|
|
|
|
2021-08-07 11:28:27 +02:00
|
|
|
self:resetTags()
|
|
|
|
|
2019-08-16 23:04:30 +02:00
|
|
|
self:setSprite()
|
2019-08-14 16:26:23 +02:00
|
|
|
self:register()
|
|
|
|
end
|
|
|
|
|
2021-08-07 11:57:01 +02:00
|
|
|
function Parent:setIndexName(indexName)
|
|
|
|
self.indexName = indexName
|
|
|
|
self.world.index[self.indexName] = self
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Parent:register()
|
|
|
|
self.world:registerActor(self)
|
|
|
|
end
|
|
|
|
|
2019-08-15 15:06:13 +02:00
|
|
|
function Parent:destroy()
|
|
|
|
self.world:destroyActor(self)
|
2019-08-15 19:00:01 +02:00
|
|
|
self.isDestroyed = true
|
2021-08-07 11:57:01 +02:00
|
|
|
if (self.indexName ~= nil) then
|
|
|
|
self.world.index[self.indexName] = nil
|
|
|
|
end
|
2019-08-15 15:06:13 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 20:11:35 +02:00
|
|
|
function Parent:update(dt)
|
2019-08-14 20:24:32 +02:00
|
|
|
self:updateSprite(dt)
|
2019-08-16 23:04:30 +02:00
|
|
|
self.tweens:update(dt)
|
2019-08-14 20:11:35 +02:00
|
|
|
end
|
|
|
|
|
2020-07-24 21:54:12 +02:00
|
|
|
-- GET FUNCTIONS
|
|
|
|
-- Get informations
|
|
|
|
|
|
|
|
function Parent:getCoordinate()
|
2021-07-18 14:05:41 +02:00
|
|
|
return self.x, self.y, self.z
|
2020-07-24 21:54:12 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 20:11:35 +02:00
|
|
|
-- SPRITE FUNCTIONS
|
|
|
|
-- Handle the character sprite
|
|
|
|
|
2019-08-14 20:24:32 +02:00
|
|
|
function Parent:setSprite(spritename, ox, oy, active)
|
2019-08-14 16:26:23 +02:00
|
|
|
self.sprite = {}
|
2019-08-14 20:24:32 +02:00
|
|
|
self.sprite.name = spritename or nil
|
2019-08-14 16:26:23 +02:00
|
|
|
self.sprite.ox = ox or 0
|
|
|
|
self.sprite.oy = oy or 0
|
2019-08-14 20:24:32 +02:00
|
|
|
self.sprite.sx = 1
|
|
|
|
self.sprite.sy = 1
|
|
|
|
self.sprite.exist = (spritename ~= nil)
|
|
|
|
self.sprite.clone = nil
|
2019-08-14 16:26:23 +02:00
|
|
|
self.sprite.active = active or false
|
2021-08-07 11:28:27 +02:00
|
|
|
|
|
|
|
self:resetFrameSignal()
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 20:24:32 +02:00
|
|
|
function Parent:cloneSprite()
|
|
|
|
if self.sprite.name ~= nil then
|
|
|
|
self.sprite.clone = self.assets.sprites[self.sprite.name]:clone()
|
|
|
|
self.sprite.clone:setCallback(self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:changeAnimation(animation, restart)
|
2021-08-07 11:28:27 +02:00
|
|
|
self:resetFrameSignal()
|
2019-08-14 20:24:32 +02:00
|
|
|
if (self.sprite.clone == nil) then
|
|
|
|
self.assets.sprites[self.sprite.name]:changeAnimation(animation, restart)
|
|
|
|
else
|
|
|
|
self.sprite.clone:changeAnimation(animation, restart)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-19 12:12:45 +02:00
|
|
|
function Parent:setAnimSpeed(speed)
|
|
|
|
if (self.sprite.clone == nil) then
|
|
|
|
self.assets.sprites[self.sprite.name]:setSpeedFactor(speed)
|
|
|
|
else
|
|
|
|
self.sprite.clone:setSpeedFactor(speed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 20:24:32 +02:00
|
|
|
function Parent:animationEnded(animation)
|
2021-08-07 11:28:27 +02:00
|
|
|
if (self.currentlyBlocking ~= nil and self.blockedBy=="animation") then
|
|
|
|
self:unblockChoregraphy()
|
|
|
|
end
|
|
|
|
self:unlockTag("animation")
|
|
|
|
self:getNewAnimation(animation)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:getNewAnimation(animation)
|
|
|
|
|
2019-08-14 20:24:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:setCustomSpeed(customSpeed)
|
|
|
|
if (self.sprite.clone == nil) then
|
|
|
|
self.assets.sprites[self.sprite.name]:setCustomSpeed(customSpeed)
|
|
|
|
else
|
|
|
|
self.sprite.clone:setCustomSpeed(customSpeed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:updateSprite(dt)
|
|
|
|
if (self.sprite.clone ~= nil) then
|
|
|
|
self.sprite.clone:update(dt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:setSpriteScallingX(sx)
|
|
|
|
local sx = sx or 1
|
|
|
|
|
|
|
|
self.sprite.sx = sx
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:setSpriteScallingY(sy)
|
|
|
|
local sy = sy or 1
|
|
|
|
|
|
|
|
self.sprite.sy = sy
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:getCurrentAnimation()
|
|
|
|
if (self.sprite.clone == nil) then
|
|
|
|
return self.assets.sprites[self.sprite.name]:getCurrentAnimation()
|
|
|
|
else
|
|
|
|
return self.sprite.clone:getCurrentAnimation()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Parent:getSpriteScalling()
|
|
|
|
return self.sprite.sx, self.sprite.sy
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:getFrame()
|
|
|
|
if (self.sprite.name ~= nil) then
|
|
|
|
if (self.sprite.clone ~= nil) then
|
|
|
|
return self.sprite.clone:getFrame()
|
|
|
|
else
|
|
|
|
return self.assets.sprites[self.sprite.name]:getFrame()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:getRelativeFrame()
|
|
|
|
if (self.sprite.name ~= nil) then
|
|
|
|
if (self.sprite.clone ~= nil) then
|
|
|
|
return self.sprite.clone:getRelativeFrame()
|
|
|
|
else
|
|
|
|
return self.assets.sprites[self.sprite.name]:getRelativeFrame()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:getAnimationDuration()
|
|
|
|
if (self.sprite.name ~= nil) then
|
|
|
|
if (self.sprite.clone ~= nil) then
|
|
|
|
return self.sprite.clone:getAnimationDuration()
|
|
|
|
else
|
|
|
|
return self.assets.sprites[self.sprite.name]:getAnimationDuration()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Parent:drawSprite(tx, ty)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
|
2020-07-19 17:06:17 +02:00
|
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
2019-08-14 16:26:23 +02:00
|
|
|
|
|
|
|
local tx = tx or 0
|
|
|
|
local ty = ty or 0
|
|
|
|
|
|
|
|
if (self.sprite.active) then
|
2020-08-07 13:15:04 +02:00
|
|
|
local sx = self.direction * self.sprite.sx
|
|
|
|
local sy = self.sprite.sy
|
2019-08-14 20:24:32 +02:00
|
|
|
if (self.sprite.clone ~= nil) then
|
2020-08-07 13:15:04 +02:00
|
|
|
self.sprite.clone:draw(x + tx, y + ty, 0, sx, sy, self.sprite.ox, self.sprite.oy)
|
2019-08-14 20:24:32 +02:00
|
|
|
else
|
2020-08-07 13:15:04 +02:00
|
|
|
self.assets.sprites[self.sprite.name]:drawAnimation(x + tx, y + ty, 0, sx, sy, self.sprite.ox, self.sprite.oy)
|
2019-08-14 20:24:32 +02:00
|
|
|
end
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-07 11:28:27 +02:00
|
|
|
-- 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
|
|
|
|
|
2019-08-14 20:11:35 +02:00
|
|
|
-- DRAW FUNCTIONS
|
|
|
|
-- Handle draw functions
|
2019-08-14 16:26:23 +02:00
|
|
|
|
|
|
|
function Parent:draw()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:drawShadow()
|
2020-07-19 17:06:17 +02:00
|
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
2020-08-07 13:15:04 +02:00
|
|
|
self.assets.images["actorsShadow"]:draw(x, y, 0, self.sprite.sx, self.sprite.sy, 12, 5)
|
2020-07-19 21:41:14 +02:00
|
|
|
if (self.isSelected == true) then
|
|
|
|
self.assets.sprites["cursorground"]:drawAnimation(x - 2, y - 1, 0, 1, 1, 12, 5)
|
|
|
|
end
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Parent:drawHUD()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return Parent
|