sonic-radiance/sonic-radiance.love/scenes/battlesystem/actors/battler.lua

141 lines
3.2 KiB
Lua
Raw Normal View History

2021-08-06 20:18:48 +02:00
local Parent = require("scenes.battlesystem.actors.movable")
local Battler = Parent:extend()
2021-05-09 15:07:38 +02:00
local outputColor = {
good = {0, 1, 0},
bad = {1, 0, 0},
pp = {0.3, 0.8, 1}
}
function Battler:new(world, x, y, z, owner)
Battler.super.new(self, world, x, y, z)
self.isBattler = true
self.isActive = false
self.debugActiveTimer = 0
2020-07-19 21:41:14 +02:00
2021-05-09 15:07:38 +02:00
self.output = {}
self.output.string = "0"
self.output.isBad = true
self.output.type = ""
self.showOutput = false
self.outputY = 0
2020-08-22 23:53:13 +02:00
2020-07-19 21:41:14 +02:00
self.isSelected = false
self.owner = owner
2021-03-13 15:49:21 +01:00
self.isDefending = false
end
function Battler:destroy()
Battler.super.destroy(self)
end
2021-05-09 15:07:38 +02:00
function Battler:getOutputY()
return self.sprHeight or 32
end
function Battler:avoidedAttack()
self:newOutput("", "MISS")
2020-08-22 23:53:13 +02:00
end
function Battler:setDamageNumber(number, isPP)
2021-05-09 15:07:38 +02:00
local type = "good"
if (isPP == true) then type = "pp" end
if (number < 0) then type = "bad" end
local string = math.abs(math.floor(number))
self:newOutput(type, string)
end
function Battler:newOutput(type, string)
self.output.type = type or ""
self.output.string = string or "error"
self.outputY = self:getOutputY() - 8
self.showOutput = true
self.tweens:newTween(0, 0.4, {outputY = self:getOutputY()}, "outQuad")
self.tweens:newTimer(0.5, "removeOutput")
end
function Battler:getOuputColor(type)
return outputColor[type] or {1,1,1}
2020-08-22 23:53:13 +02:00
end
function Battler:setActive()
core.debug:print("cbs/actor","actor " .. self.id .. " is active")
self.isActive = true
self.debugActiveTimer = 0
end
function Battler:update(dt)
2019-08-16 23:04:30 +02:00
Battler.super.update(self, dt)
if (self.isActive) then
self.debugActiveTimer = self.debugActiveTimer + dt
if self.debugActiveTimer >= 0.5 then
core.debug:print("cbs/battler", "counter ended, switching active battler")
self.isActive = false
self.world:switchActiveBattler()
end
end
end
2021-08-07 11:39:34 +02:00
-- Movement
-- Some specific movement function
function Battler:land()
self:changeAnimation("idle")
end
-- CHOREGRAPHY FUNCTIONS
-- All functions related to the choregraphy system
function Battler:choregraphyEnded()
2021-08-07 11:09:49 +02:00
self:resetMovement()
end
-- DAMAGE FUNCTIONS
2020-08-05 11:40:29 +02:00
function Battler:getHurt()
end
function Battler:die()
self:destroy()
end
-- DRAW FUNCTIONS
2021-05-09 15:07:38 +02:00
function Battler:drawOutput()
if (self.showOutput) then
2020-08-22 23:53:13 +02:00
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
2021-05-09 15:07:38 +02:00
local color = self:getOuputColor(self.output.type)
love.graphics.setColor(color[1], color[2], color[3], 1)
2020-08-22 23:53:13 +02:00
2021-05-09 15:07:38 +02:00
self.assets.fonts["hudnbrs_small"]:print(self.output.string, x, y - self.outputY - self.z, "center")
2020-08-22 23:53:13 +02:00
utils.graphics.resetColor()
end
end
function Battler:draw()
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
love.graphics.setColor(1, 0, 0, 1)
love.graphics.rectangle("fill", x - 8, y - 32, 16, 32)
love.graphics.setColor(1, 1, 1, 1)
end
2020-08-04 22:19:11 +02:00
function Battler:initSprite()
if (self.assets.sprites[self.owner.name] == nil) then
self.assets:addSprite(self.owner.name, self:getSpritePath())
end
self.assets.sprites[self.owner.name]:setCustomSpeed(16)
self:setSprite(self.owner.name, 32, 48, true)
self:cloneSprite()
self:changeAnimation("idle")
end
function Battler:validateAction()
end
return Battler