shotgun.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local Shotgun = extend(app.logic.weapon)
  2. ----------------
  3. -- Meta
  4. ----------------
  5. Shotgun.name = 'Shotgun'
  6. Shotgun.code = 'shotgun'
  7. Shotgun.text = 'It is a shotgun. It blows people to bits.'
  8. Shotgun.type = 'weapon'
  9. ----------------
  10. -- Data
  11. ----------------
  12. Shotgun.image = data.media.graphics.shotgun
  13. Shotgun.scale = .2
  14. Shotgun.damage = 25
  15. Shotgun.fireTime = .65
  16. Shotgun.reloadTime = 2
  17. Shotgun.switchTime = .75
  18. Shotgun.clip = 4
  19. Shotgun.ammo = 16
  20. Shotgun.spread = math.rad(16)
  21. Shotgun.recoil = 6
  22. Shotgun.count = 4
  23. Shotgun.anchorx = 191
  24. Shotgun.anchory = 40
  25. Shotgun.tipx = 246
  26. Shotgun.tipy = -10
  27. ----------------
  28. -- Crosshair
  29. ----------------
  30. function Shotgun:crosshair()
  31. local g, p, x, y = love.graphics, ctx.players:get(ctx.id), ctx.view:frameMouseX(), ctx.view:frameMouseY()
  32. local vx, vy, s = ctx.view:worldMouseX(), ctx.view:worldMouseY(), ctx.view.scale
  33. local d = math.distance(p.x, p.y, vx, vy)
  34. local alpha = 50 + ((300 - math.clamp(d - 200, 0, 300)) / 300) * 205
  35. if self.timers.switch > 0 then alpha = alpha / 2 end
  36. local dir = p.angle
  37. local dx, dy = p.class.handx * p.class.scale * s, p.class.handy * p.class.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. dx, dy = self.tipx * self.scale * s, self.tipy * self.scale * s
  41. x = x + math.dx(dx, dir) - math.dy(dy, dir)
  42. y = y + math.dy(dx, dir) + math.dx(dy, dir)
  43. 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)
  44. x = x - math.dx(math.min(d2, d) * s, dir)
  45. y = y - math.dy(math.min(d2, d) * s, dir)
  46. local factor = (1 - (math.clamp(tick - p.lastDamageDealt, 0, .4 / tickRate) / (.4 / tickRate))) ^ 2
  47. g.setColor(table.interpolate({255, 255, 255, alpha}, {255, 0, 0, alpha}, factor))
  48. local radius = math.abs(math.atan(self.spread / 2)) * math.max(math.distance(p.x, p.y, vx, vy) - d2, 0) * s
  49. g.circle('line', x, y, radius)
  50. end
  51. return Shotgun