staticgrenade.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local StaticGrenade = {}
  2. StaticGrenade.code = 'staticgrenade'
  3. StaticGrenade.duration = .8
  4. StaticGrenade.radius = 100
  5. function StaticGrenade:activate(mx, my)
  6. self.x, self.y = self.owner.x, self.owner.y
  7. self.hp = self.duration
  8. self.angle = self.owner.angle
  9. self.distance = math.distance(self.owner.x, self.owner.y, mx, my)
  10. self.speed = self.distance / self.duration
  11. self.tx, self.ty = self.owner.x + math.dx(self.distance, self.angle), self.owner.y + math.dy(self.distance, self.angle)
  12. self.z = 1
  13. self.zVel = 750
  14. self.zAcc = -1900
  15. end
  16. function StaticGrenade:update()
  17. self.x, self.y = self.x + math.dx(self.speed * tickRate, self.angle), self.y + math.dy(self.speed * tickRate, self.angle)
  18. self.z = self.z + self.zVel * tickRate
  19. self.zVel = self.zVel + self.zAcc * tickRate
  20. self.hp = timer.rot(self.hp, function()
  21. local targets = ctx.collision:circleTest(self.x, self.y, self.radius, {tag = 'player', fn = function(p) return p.team ~= self.owner.team end, all = true})
  22. table.each(targets, function(p)
  23. ctx.buffs:add(p, 'staticgrenade')
  24. ctx.buffs:remove(p, 'plasmasickness')
  25. end)
  26. ctx.event:emit('particle.create', {
  27. kind = 'staticgrenade',
  28. vars = {
  29. x = self.x,
  30. y = self.y,
  31. radius = self.radius
  32. }
  33. })
  34. ctx.spells:deactivate(self)
  35. end)
  36. end
  37. function StaticGrenade:draw()
  38. local x, y = ctx.view:three(self.x, self.y, self.z)
  39. local scale = 1 + (ctx.view:convertZ(self.z) / 500)
  40. local g = love.graphics
  41. g.setColor(0, 255, 255)
  42. g.circle('fill', x, y, 10 * scale)
  43. end
  44. return StaticGrenade