plasmacannon.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. local PlasmaCannon = extend(app.logic.spell)
  2. PlasmaCannon.code = 'plasmacannon'
  3. function PlasmaCannon:activate(charge)
  4. local weapon = data.weapon.plasmacannon
  5. self.speed = 800 + (charge / weapon.maxCharge) * 3000
  6. self.damage = weapon.minDamage + (charge / weapon.maxCharge) * (weapon.maxDamage - weapon.minDamage)
  7. self.radius = 30 + (charge / weapon.maxCharge) * 120
  8. self.ded = false
  9. self:mirrorOwner()
  10. local dx, dy = self.owner.class.handx * self.owner.class.scale, self.owner.class.handy * self.owner.class.scale
  11. self.x = self.x + math.dx(dx, self.angle) - math.dy(dy, self.angle)
  12. self.y = self.y + math.dy(dx, self.angle) + math.dx(dy, self.angle)
  13. dx, dy = weapon.tipx * weapon.scale, weapon.tipy * weapon.scale
  14. self.x = self.x + math.dx(dx, self.angle) - math.dy(dy, self.angle)
  15. self.y = self.y + math.dy(dx, self.angle) + math.dx(dy, self.angle)
  16. for _ = 1, 4 do
  17. ctx.event:emit('particle.create', {
  18. kind = 'spark',
  19. vars = {
  20. x = self.x,
  21. y = self.y,
  22. angle = self.angle + love.math.random() * 1.56 - .78
  23. }
  24. })
  25. end
  26. ctx.event:emit('particle.create', {
  27. kind = 'muzzleFlash',
  28. vars = {
  29. owner = self.owner.id,
  30. weapon = 'energyrifle'
  31. }
  32. })
  33. self:playSound('pulse')
  34. local d = math.distance(self.owner.x, self.owner.y, self.x, self.y)
  35. if self:wallDistance(d) < d then self:die() end
  36. end
  37. function PlasmaCannon:update()
  38. if self.ded then return ctx.spells:deactivate(self) end
  39. self.prevx, self.prevy = self.x, self.y
  40. local dis = self.speed * tickRate
  41. local wall, d = ctx.collision:lineTest(self.x, self.y, self.x + math.dx(dis, self.angle), self.y + math.dy(dis, self.angle), {tag = 'wall'})
  42. if wall then dis = d end
  43. local tx, ty = self.x + math.dx(dis, self.angle), self.y + math.dy(dis, self.angle)
  44. local target, d = ctx.collision:lineTest(self.x, self.y, tx, ty, {tag = 'player', fn = function(p) return p.team ~= self.owner.team end, first = true})
  45. if target and d < dis then d = dis end
  46. if target or wall then
  47. self.x, self.y = self.x + math.dx(dis, self.angle), self.y + math.dy(dis, self.angle)
  48. 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})
  49. table.each(targets, function(p)
  50. ctx.net:emit(app.net.events.damage, {id = p.id, amount = self.damage, from = self.owner.id, tick = tick})
  51. ctx.buffs:add(p, 'plasmasickness')
  52. end)
  53. ctx.event:emit('particle.create', {
  54. kind = 'plasmacannon',
  55. vars = {
  56. x = self.x,
  57. y = self.y,
  58. radius = self.radius
  59. }
  60. })
  61. self.ded = true
  62. else
  63. self.x, self.y = tx, ty
  64. end
  65. end
  66. function PlasmaCannon:draw()
  67. local g = love.graphics
  68. local x, y = math.lerp(self.prevx, self.x, tickDelta / tickRate), math.lerp(self.prevy, self.y, tickDelta / tickRate)
  69. g.setColor(0, 255, 255)
  70. g.circle('fill', x, y, 10)
  71. end
  72. return PlasmaCannon