lazor.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. local Lazor = extend(app.logic.spell)
  2. Lazor.code = 'lazor'
  3. Lazor.maxCharge = 1.2
  4. Lazor.turnSpeed = .21
  5. Lazor.width = 28
  6. function Lazor:activate()
  7. self.charge = 0
  8. self.owner.haste = self.owner.haste - (self.owner.class.speed * .5)
  9. self:mirrorOwner()
  10. end
  11. function Lazor:deactivate()
  12. self.owner.haste = self.owner.haste + (self.owner.class.speed * .5)
  13. end
  14. function Lazor:update()
  15. self.x, self.y = self.owner.x, self.owner.y
  16. local diff = math.anglediff(self.angle, self.owner.angle)
  17. self.angle = self.angle + math.min(math.abs(diff), self.turnSpeed * tickRate) * math.sign(diff)
  18. self.owner.angle = self.angle
  19. self.charge = self.charge + tickRate
  20. if self.charge >= self.maxCharge then
  21. local hit = {}
  22. local wall, dis = ctx.collision:lineTest(self.x, self.y, self.x + math.dx(2000, self.angle), self.y + math.dy(2000, self.angle), {tag = 'wall', first = true})
  23. dis = wall and dis or 2000
  24. for i = 1, 3 do
  25. local offset = -self.width / 2 + (self.width / 2) * (i - 1)
  26. local ox, oy = self.x + math.dx(offset, self.angle + math.pi / 2), self.y + math.dy(offset, self.angle + math.pi / 2)
  27. local x2, y2 = ox + math.dx(dis, self.angle), oy + math.dy(dis, self.angle)
  28. local targets = ctx.collision:lineTest(ox, oy, x2, y2, {tag = 'player', fn = function(p) return p.team ~= self.owner.team and not hit[p.id] end, all = true})
  29. table.each(targets, function(p)
  30. hit[p.id] = true
  31. local buff = ctx.buffs:get(p, 'plasmasickness')
  32. local damage = 70 + 50 * (buff and buff.stacks or 0)
  33. ctx.net:emit(app.net.events.damage, {id = p.id, from = self.owner.id, amount = damage, tick = tick})
  34. ctx.buffs:remove(p, 'plasmasickness')
  35. end)
  36. end
  37. self:die()
  38. end
  39. end
  40. function Lazor:draw()
  41. love.graphics.setColor(255, 0, 0)
  42. love.graphics.setLineWidth(self.width * (self.charge / self.maxCharge))
  43. local wall, dis = ctx.collision:lineTest(self.x, self.y, self.x + math.dx(2000, self.angle), self.y + math.dy(2000, self.angle), {tag = 'wall', first = true})
  44. dis = wall and dis or 2000
  45. love.graphics.line(self.x, self.y, self.x + math.dx(dis, self.angle), self.y + math.dy(dis, self.angle))
  46. love.graphics.setLineWidth(1)
  47. end
  48. return Lazor