smg.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local SMG = extend(app.logic.weapon)
  2. ----------------
  3. -- Meta
  4. ----------------
  5. SMG.name = 'SMG'
  6. SMG.code = 'smg'
  7. SMG.text = 'It is a SMG. It pumps people full of lead.'
  8. SMG.type = 'weapon'
  9. ----------------
  10. -- Data
  11. ----------------
  12. SMG.image = data.media.graphics.smg
  13. SMG.scale = 1
  14. SMG.damage = 15
  15. SMG.fireTime = .13
  16. SMG.reloadTime = 1.6
  17. SMG.switchTime = .5
  18. SMG.clip = 12
  19. SMG.ammo = 120
  20. SMG.spread = .07
  21. SMG.recoil = 3
  22. SMG.anchorx = 15
  23. SMG.anchory = 7
  24. SMG.tipx = 14
  25. SMG.tipy = 0
  26. ----------------
  27. -- Crosshair
  28. ----------------
  29. function SMG:crosshair()
  30. local g, p, x, y = love.graphics, ctx.players:get(ctx.id), ctx.view:frameMouseX(), ctx.view:frameMouseY()
  31. local vx, vy, s = ctx.view:worldMouseX(), ctx.view:worldMouseY(), ctx.view.scale
  32. local d = math.distance(p.x, p.y, vx, vy)
  33. local len = 4 * s
  34. local dir = p.angle
  35. local dx, dy = p.class.handx * p.class.scale * s, p.class.handy * p.class.scale * s
  36. x = x + math.dx(dx, dir) - math.dy(dy, dir)
  37. y = y + math.dy(dx, dir) + math.dx(dy, dir)
  38. dx, dy = self.tipx * self.scale * s, self.tipy * self.scale * s
  39. x = x + math.dx(dx, dir) - math.dy(dy, dir)
  40. y = y + math.dy(dx, dir) + math.dx(dy, dir)
  41. 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)
  42. x = x - math.dx(math.min(d2, d) * s, dir)
  43. y = y - math.dy(math.min(d2, d) * s, dir)
  44. local r = math.abs(math.atan(self.spread)) * math.max(math.distance(p.x, p.y, vx, vy) - d2, 0) * s
  45. local alpha = self.timers.switch > 0 and 128 or 255
  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. g.circle('line', x, y, r )
  49. g.line(x, y - r - len, x, y - r + len)
  50. g.line(x - r - len, y, x - r + len, y)
  51. g.line(x + r - len, y, x + r + len, y)
  52. g.line(x, y + r - len, x, y + r + len)
  53. end
  54. return SMG