tremor.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local Tremor = extend(Spell)
  2. local g = love.graphics
  3. Tremor.maxHealth = 1.5
  4. Tremor.depth = -5
  5. function Tremor:activate()
  6. local ability, unit = self:getAbility(), self:getUnit()
  7. self.timer = self.maxHealth
  8. self.direction = self:getAbility():getUnitDirection()
  9. self.x = unit.x + (unit.width / 2 + self.width / 2) * self.direction
  10. self.team = unit.team
  11. table.each(ctx.target:inRange(self, self.width / 2, 'enemy', 'unit'), function(target)
  12. target:hurt(self.damage, unit)
  13. target.buffs:add('tremorstun', {stun = self.stun, timer = self.stun})
  14. end)
  15. self.x = unit.x
  16. self.spikeTargetY = ctx.map.height - ctx.map.groundHeight + 16
  17. self.spikes = {}
  18. for i = 1, self.spikeCount do
  19. local height = 90 - (10 * math.min(i, 3))
  20. local y = self.spikeTargetY + height
  21. self.spikes[i] = {
  22. height = height,
  23. x = unit.x + (unit.width / 2 + (self.width * .8) * (i / self.spikeCount)) * self.direction,
  24. starty = y,
  25. y = y,
  26. alpha = 0
  27. }
  28. end
  29. self.activeSpike = 1
  30. for i = 1, 25 do
  31. ctx.spells:add('dirt', {x = self.spikes[1].x, y = self.spikeTargetY})
  32. end
  33. ctx.event:emit('view.register', {object = self})
  34. end
  35. function Tremor:deactivate()
  36. ctx.event:emit('view.unregister', {object = self})
  37. end
  38. function Tremor:update()
  39. self.timer = timer.rot(self.timer, function()
  40. ctx.spells:remove(self)
  41. end)
  42. if self.activeSpike then
  43. local spike = self.spikes[self.activeSpike]
  44. spike.y = math.max(spike.y - 650 * ls.tickrate, self.spikeTargetY)
  45. spike.alpha = 1 - ((spike.y - self.spikeTargetY) / (spike.starty - self.spikeTargetY))
  46. if spike.y == self.spikeTargetY then
  47. self.activeSpike = self.activeSpike + 1
  48. if self.activeSpike > self.spikeCount then self.activeSpike = nil
  49. else
  50. for i = 1, 25 do
  51. ctx.spells:add('dirt', {x = self.spikes[self.activeSpike].x, y = self.spikeTargetY})
  52. end
  53. end
  54. end
  55. end
  56. end
  57. function Tremor:draw()
  58. local image = data.media.graphics.spell.tremor
  59. for i = 1, self.spikeCount do
  60. local spike = self.spikes[i]
  61. local scale = spike.height / image:getHeight()
  62. g.setColor(255, 255, 255, (spike.alpha * math.clamp(self.timer, 0, .2) / .2) * 255)
  63. g.draw(image, spike.x, spike.y, 0, scale * self.direction, scale, image:getWidth() / 2, image:getHeight())
  64. end
  65. end
  66. return Tremor