burst.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local Burst = extend(Spell)
  2. local g = love.graphics
  3. Burst.depth = -10
  4. function Burst:activate()
  5. local unit, player = self:getUnit(), self:getPlayer()
  6. self.x = unit.x
  7. self.y = unit.y
  8. self.team = unit.team
  9. table.each(ctx.target:inRange(self, self.range, 'enemy', 'unit', 'player'), function(target)
  10. target:hurt(self.damage, unit, {'spell'})
  11. end)
  12. local targets = ctx.target:inRange(self, self.range, 'ally', 'unit', 'player')
  13. if #targets > 0 then
  14. local heal = self.heal / #targets
  15. table.each(targets, function(target)
  16. target:heal(heal, unit)
  17. end)
  18. end
  19. self.scale = 0
  20. self.prevscale = self.scale
  21. self.health = self.maxHealth
  22. self.angle = love.math.random() * 2 * math.pi
  23. self.image = data.media.graphics.spell.burst
  24. ctx.event:emit('view.register', {object = self})
  25. end
  26. function Burst:deactivate()
  27. ctx.event:emit('view.unregister', {object = self})
  28. end
  29. function Burst:update()
  30. self.health = timer.rot(self.health, function() ctx.spells:remove(self) end)
  31. self.prevscale = self.scale
  32. self.scale = math.lerp(self.scale, 1, math.min(20 * ls.tickrate, 1))
  33. end
  34. function Burst:draw()
  35. local unit = self:getUnit()
  36. g.setColor(130, 250, 100, self.health / self.maxHealth * 255)
  37. local scale = math.lerp(self.prevscale, self.scale, ls.accum / ls.tickrate)
  38. scale = scale * ((self.range + 50) * 2 / self.image:getWidth())
  39. g.draw(self.image, self.x, self.y, self.angle, scale, scale, self.image:getWidth() / 2, self.image:getHeight() / 2)
  40. end
  41. return Burst