energyrifle.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local EnergyRifle = extend(app.logic.weapon)
  2. ----------------
  3. -- Meta
  4. ----------------
  5. EnergyRifle.name = 'Energy Rifle'
  6. EnergyRifle.code = 'energyrifle'
  7. EnergyRifle.text = 'Bzzt.'
  8. EnergyRifle.type = 'weapon'
  9. ----------------
  10. -- Data
  11. ----------------
  12. EnergyRifle.image = data.media.graphics.smg
  13. EnergyRifle.scale = 1
  14. EnergyRifle.damage = 15
  15. EnergyRifle.fireTime = .35
  16. EnergyRifle.reloadTime = 1.5
  17. EnergyRifle.switchTime = .3
  18. EnergyRifle.clip = 10
  19. EnergyRifle.ammo = 50
  20. EnergyRifle.recoil = 5
  21. EnergyRifle.anchorx = 15
  22. EnergyRifle.anchory = 7
  23. EnergyRifle.tipx = 14
  24. EnergyRifle.tipy = 0
  25. ----------------
  26. -- Crosshair
  27. ----------------
  28. function EnergyRifle:crosshair()
  29. local g, p, x, y = love.graphics, ctx.players:get(ctx.id), ctx.view:frameMouseX(), ctx.view:frameMouseY()
  30. local vx, vy, s = ctx.view:worldMouseX(), ctx.view:worldMouseY(), ctx.view.scale
  31. local d = math.distance(p.x, p.y, vx, vy)
  32. local len = 8 * s
  33. local dir = p.angle
  34. local dx, dy = p.class.handx * p.class.scale * s, p.class.handy * p.class.scale * s
  35. x = x + math.dx(dx, dir) - math.dy(dy, dir)
  36. y = y + math.dy(dx, dir) + math.dx(dy, dir)
  37. dx, dy = self.tipx * self.scale * s, self.tipy * self.scale * s
  38. x = x + math.dx(dx, dir) - math.dy(dy, dir)
  39. y = y + math.dy(dx, dir) + math.dx(dy, dir)
  40. local d2 = (math.distance(0, 0, p.class.handx, p.class.handy) * p.class.scale) + (math.distance(0, 0, self.tipx, self.tipy) * self.scale)
  41. x = x - math.dx(math.min(d2, d) * s, dir)
  42. y = y - math.dy(math.min(d2, d) * s, dir)
  43. local alpha = self.timers.switch > 0 and 128 or 255
  44. local factor = (1 - (math.clamp(tick - p.lastDamageDealt, 0, .4 / tickRate) / (.4 / tickRate))) ^ 2
  45. g.setColor(table.interpolate({0, 255, 255, alpha}, {255, 0, 0, alpha}, factor))
  46. g.line(x, y - len, x, y + len)
  47. g.line(x - len, y, x + len, y)
  48. g.line(x - len, y, x + len, y)
  49. g.line(x, y - len, x, y + len)
  50. end
  51. return EnergyRifle