2019-08-14 16:26:23 +02:00
|
|
|
local Battler = require("scenes.battlesystem.actors.battler")
|
|
|
|
local Hero = Battler:extend()
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:new(world, x, y, charid, charnumber)
|
|
|
|
Hero.super.new(self, world, x, y, 0)
|
2019-03-10 13:11:26 +01:00
|
|
|
self.isHero = true
|
|
|
|
self.turnAction = nil
|
|
|
|
self.startx, self.starty = self.x, self.y
|
|
|
|
self.dx, self.dy = self.x, self.y
|
|
|
|
self.direction = 1
|
|
|
|
self.directionPrevious = 1
|
|
|
|
|
|
|
|
if charid == nil then
|
2019-08-13 22:28:05 +02:00
|
|
|
core.debug:error("FATAL ERROR: charid not set")
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
self.charid = charid
|
2019-08-12 12:37:00 +02:00
|
|
|
self.actionPerTurn = game.characters.list[self.charid].turns
|
|
|
|
self.assets:addSprite(charid, "datas/gamedata/characters/" .. charid .. "/sprites")
|
2019-03-10 13:11:26 +01:00
|
|
|
self.assets.sprites[self.charid]:setCustomSpeed(16)
|
|
|
|
self:setAnimation("idle")
|
|
|
|
self:setSprite(charid, 32, 48, true)
|
2019-08-14 13:56:25 +02:00
|
|
|
|
|
|
|
self.charnumber = charnumber or 1
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:setAnimation(animation)
|
2019-03-10 13:11:26 +01:00
|
|
|
if (self.animation ~= animation) then
|
|
|
|
self.animation = animation
|
|
|
|
self.assets.sprites[self.charid]:changeAnimation(animation, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:draw()
|
|
|
|
x, y = self.maputils.gridToPixel(self.x, self.y, true)
|
2019-03-10 13:11:26 +01:00
|
|
|
--love.graphics.rectangle("fill", x - 8, y - 32, 16, 32)
|
|
|
|
self:drawSprite()
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:drawIcon(x, y)
|
2019-03-10 13:11:26 +01:00
|
|
|
local iconID = 1
|
|
|
|
self.assets.tileset["charicons"]:drawTile(iconID, x, y)
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:setActive()
|
2019-03-10 13:11:26 +01:00
|
|
|
local gridsize = game.characters.list[self.charid].base_stats.move
|
2019-08-12 12:37:00 +02:00
|
|
|
if (gridsize == nil) then
|
|
|
|
gridsize = 3
|
|
|
|
core.debug:warning("cbs/character", "move value is nil")
|
|
|
|
end
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world.cursor:setGrid(self.x, self.y, "square", gridsize, 1, self)
|
2019-03-10 13:11:26 +01:00
|
|
|
self.startx, self.starty = self.x, self.y
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world.cursor:set(self.startx, self.starty)
|
2019-03-10 13:11:26 +01:00
|
|
|
self.currentAction = "selectDirection"
|
|
|
|
|
|
|
|
self.directionPrevious = self.direction
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:update(dt)
|
|
|
|
self.keys = self.scene:getKeys(1)
|
2019-03-10 13:11:26 +01:00
|
|
|
if (self.currentAction == "moving") then
|
|
|
|
self.xprevious = self.x
|
|
|
|
self.yprevious = self.y
|
|
|
|
self.x = (self.x) + ((self.dx) - (self.x)) * dt*15
|
|
|
|
self.y = (self.y) + ((self.dy) - (self.y)) * dt*15
|
|
|
|
|
|
|
|
local xspeed, yspeed = math.abs(self.x - self.xprevious),
|
|
|
|
math.abs(self.y - self.yprevious)
|
|
|
|
|
|
|
|
local speed = math.sqrt(xspeed*xspeed + yspeed*yspeed) * 32
|
|
|
|
self.assets.sprites[self.charid]:setCustomSpeed(speed * 60)
|
|
|
|
local direction = utils.math.sign(self.x - self.xprevious)
|
|
|
|
if direction ~= 0 then
|
|
|
|
self.direction = direction
|
|
|
|
end
|
|
|
|
if (math.abs(self.x - self.dx) < 0.01) and (math.abs(self.y - self.dy) < 0.01) then
|
|
|
|
self.x = self.dx
|
|
|
|
self.y = self.dy
|
|
|
|
self:setAnimation("idle")
|
|
|
|
self.currentAction = "selectAttack"
|
2019-08-14 16:26:23 +02:00
|
|
|
self.scene.menu:set( self )
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
elseif (self.currentAction == "selectAttack") then
|
2019-08-12 12:37:00 +02:00
|
|
|
if (self.keys["B"].isPressed) then
|
2019-03-10 13:11:26 +01:00
|
|
|
--self.currentAction = "selectDirection"
|
2019-08-14 16:26:23 +02:00
|
|
|
--self.world.cursor:set(self.x, self.y)
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
elseif (self.currentAction == "selectDirection") then
|
|
|
|
self.xprevious = self.x
|
|
|
|
self.yprevious = self.y
|
|
|
|
|
|
|
|
self.x = (self.x) + ((self.startx) - (self.x)) * dt*15
|
|
|
|
self.y = (self.y) + ((self.starty) - (self.y)) * dt*15
|
|
|
|
|
|
|
|
local xspeed, yspeed = math.abs(self.x - self.xprevious),
|
|
|
|
math.abs(self.y - self.yprevious)
|
|
|
|
|
|
|
|
local speed = math.sqrt(xspeed*xspeed + yspeed*yspeed) * 32
|
|
|
|
self.assets.sprites[self.charid]:setCustomSpeed(speed * 60)
|
|
|
|
local direction = utils.math.sign(self.x - self.xprevious)
|
|
|
|
if direction ~= 0 then
|
|
|
|
self.direction = direction
|
|
|
|
end
|
|
|
|
|
|
|
|
if (math.abs(self.x - self.startx) < 0.01) and (math.abs(self.y - self.starty) < 0.01) then
|
|
|
|
self.x = self.startx
|
|
|
|
self.y = self.starty
|
|
|
|
self:setAnimation("idle")
|
|
|
|
self.direction = self.directionPrevious
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:validateAction()
|
2019-03-10 13:11:26 +01:00
|
|
|
if (self.currentAction == "selectDirection") then
|
|
|
|
self:setAnimation("walk")
|
|
|
|
self.currentAction = "moving"
|
2019-08-14 16:26:23 +02:00
|
|
|
self.dx, self.dy = self.world.cursor.x, self.world.cursor.y
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world.cursor:unset( )
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:getStats()
|
2019-03-10 13:11:26 +01:00
|
|
|
return game.characters.list[self.charid].stats
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:getSignal(action_type, id)
|
2019-03-10 13:11:26 +01:00
|
|
|
--print(action_type .. " " .. id)
|
|
|
|
if (action_type == "back") then
|
|
|
|
self.currentAction = "selectDirection"
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world.cursor:set(self.x, self.y)
|
2019-03-10 13:11:26 +01:00
|
|
|
self:setAnimation("walk")
|
|
|
|
elseif (action_type == "defend") then
|
|
|
|
self.turnAction = "defend"
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world:switchActiveBattler( )
|
2019-03-10 13:11:26 +01:00
|
|
|
else
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world:switchActiveBattler( )
|
2019-03-10 13:11:26 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:getBackSignal()
|
2019-03-31 17:35:55 +02:00
|
|
|
self.currentAction = "selectDirection"
|
2019-08-14 16:26:23 +02:00
|
|
|
self.world.cursor:set(self.x, self.y)
|
2019-03-31 17:35:55 +02:00
|
|
|
self:setAnimation("walk")
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:drawHUD()
|
2019-08-14 13:56:25 +02:00
|
|
|
local HUDBASE = -8
|
|
|
|
local HUDSEP = 152
|
|
|
|
local x = HUDBASE + (self.charnumber-1)*HUDSEP
|
|
|
|
local y = 32
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
self.assets.images["statusbar"]:draw(x, y)
|
2019-04-01 08:55:59 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
return Hero
|