1. Leo Bartoloni
  2. lovewars

Source

lovewars / classes / actor_changeturn.lua

--- ACTOR
-- Change turn with transition

require "lib/SECS"

actor_changeturn = class:new()

--- actor_changeturn (LUADOC TODO add resume)
-- actor_changeturn (LUADOC TODO add description)
-- @param init (LUADOC TODO add init description) 
-- @param pplayer (LUADOC TODO add pplayer description) 
-- @param pturn (LUADOC TODO add pturn description) 
-- @return (LUADOC TODO add return description) 
function actor_changeturn:init(pplayer, pturn)
  -- actor must have this properties and must have :update(dt) and draw() methods
  self.interactive = false
  self.modal = true -- modal true : only this actor in update/draw, stops others actors after
  self.finished = false
  self.timing = "beforemap"
  --
  self.player = pplayer
  self.turn = pturn
  self.delay = 0
  self.maxdelay = 40
  --
  self.alpha = 0
  self.font = love.graphics.newFont(18)
end

--- actor_changeturn (LUADOC TODO add resume)
-- actor_changeturn (LUADOC TODO add description)
-- @param update (LUADOC TODO add update description) 
-- @param dt (LUADOC TODO add dt description) 
-- @return (LUADOC TODO add return description) 
function actor_changeturn:update(dt)
  --
  self.delay = self.delay + 1
  if self.delay > self.maxdelay then
    self.finished = true
    return false
  end
  --
  if self.delay < self.maxdelay/2 then
    self.alpha = 255*(self.delay/(self.maxdelay/2))
  else
    self.alpha = 255*((self.maxdelay-self.delay)/(self.maxdelay/2))
  end
  --
  return true
end

function actor_changeturn:draw()
  love.graphics.setColor(255, 255, 255, self.alpha)
  love.graphics.rectangle('fill', 90, 272, 600, 72)
  love.graphics.setColor(0, 0, 0, self.alpha)
  love.graphics.rectangle('line', 90, 272, 600, 72)
  love.graphics.setFont(self.font)
  love.graphics.printf("Turn "..self.turn, 100, 300, 600, 'center')
  love.graphics.printf("Player "..self.player.name, 100, 318, 600, 'center')
end