kujuattack.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. local KujuAttack = extend(Spell)
  2. function KujuAttack:activate()
  3. self.direction = math.sign(self.target.x - self.unit.x)
  4. self.x = self.unit.x + self.unit.width / 2 * self.direction
  5. self.prevx = self.x
  6. self.y = self.unit.y - self.unit.height / 3
  7. self.team = self.unit.team
  8. self.angle = -self.direction * math.pi
  9. self.speed = 300
  10. self.width = 32
  11. ctx.event:emit('view.register', {object = self})
  12. end
  13. function KujuAttack:deactivate()
  14. ctx.event:emit('view.unregister', {object = self})
  15. end
  16. function KujuAttack:update()
  17. local unit = self.unit
  18. self.prevx = self.x
  19. self.x = self.x + math.dx(self.speed * ls.tickrate, 0) * self.direction
  20. if not self.target or math.abs(self.x - self.target.x) < self.width / 2 or math.sign(self.target.x - self.x) ~= self.direction then
  21. unit:attack({target = self.target, damage = unit.damage, noparticles = true})
  22. ctx.particles:emit('kujuattack', self.x, self.y, 1)
  23. ctx.particles:emit('kujuattackhit', self.x, self.y, 1)
  24. local windchill = unit:upgradeLevel('windchill')
  25. if self.target.buffs and windchill > 0 then
  26. self.target.buffs:add('windchill', {slow = .2 * windchill, timer = .25 + .25 * windchill})
  27. self.target:hurt(unit.spirit * (.2 + .2 * windchill), unit)
  28. end
  29. ctx.spells:remove(self)
  30. end
  31. end
  32. function KujuAttack:draw()
  33. if not self.target then return end
  34. local g = love.graphics
  35. g.setColor(255, 255, 255, 255 * (self.target.alpha or 1))
  36. local image = data.media.graphics.spell.kujuattack
  37. local scale = self.width / image:getWidth()
  38. local x = math.lerp(self.prevx, self.x, ls.accum / ls.tickrate)
  39. g.draw(image, x, self.y, 0, -self.direction * scale, scale, image:getWidth() / 2, image:getHeight() / 2)
  40. end
  41. return KujuAttack