killPopup.lua 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. local KillPopup = class()
  2. local g = love.graphics
  3. function KillPopup:init()
  4. self.streak = {}
  5. self.multikill = {}
  6. self.multikillTick = {}
  7. self.feed = {}
  8. ctx.event:on(app.net.events.dead, function(data)
  9. self.streak[data.id] = 0
  10. if data.id ~= data.kill then
  11. self.multikill[data.kill] = self.multikill[data.kill] or 0
  12. if not self.multikillTick[data.kill] or (tick - self.multikillTick[data.kill]) * tickRate > math.min(4 + self.multikill[data.kill] / 2, 6) then
  13. self.multikill[data.kill] = 1
  14. else
  15. self.multikill[data.kill] = self.multikill[data.kill] + 1
  16. end
  17. self.multikillTick[data.kill] = tick
  18. self.streak[data.kill] = (self.streak[data.kill] or 0) + 1
  19. local u, v = ctx.hud.u, ctx.hud.v
  20. if self.streak[data.kill] == 3 or self.streak[data.kill] == 5 or self.streak[data.kill] == 8 then
  21. table.insert(self.feed, 1, {player = data.kill, kind = 'streak', amount = self.streak[data.kill], x = u * .5, y = -v * .1, alpha = 3})
  22. end
  23. if self.multikill[data.kill] >= 2 then
  24. table.insert(self.feed, 1, {player = data.kill, kind = 'multikill', amount = self.multikill[data.kill], x = u * .5, y = -v * .1, alpha = 3})
  25. end
  26. end
  27. end)
  28. end
  29. function KillPopup:update()
  30. local u, v = ctx.hud.u, ctx.hud.v
  31. local ty = v * .22
  32. for i = 1, #self.feed do
  33. if i > #self.feed then break end
  34. self.feed[i].x = math.lerp(self.feed[i].x, u * .5, math.min(10 * tickRate, 1))
  35. self.feed[i].y = math.lerp(self.feed[i].y, ty, math.min(10 * tickRate, 1))
  36. local height
  37. if self.feed[i].kind == 'multikill' then height = v * .06 + (v * .008 * (self.feed[i].amount - 2))
  38. elseif self.feed[i].kind == 'streak' then height = v * .06 + (v * .008 * (self.feed[i].amount - 3) / 2) end
  39. ty = ty + (v * .035) + height + (v * .03)
  40. self.feed[i].alpha = self.feed[i].alpha - tickRate
  41. if self.feed[i].alpha <= 0 then
  42. table.remove(self.feed, i)
  43. i = i - 1
  44. end
  45. end
  46. end
  47. function KillPopup:draw()
  48. local u, v = ctx.hud.u, ctx.hud.v
  49. for i = 1, #self.feed do
  50. local f = self.feed[i]
  51. local p = ctx.players:get(f.player)
  52. if f.kind == 'streak' then str = p.username .. ' is on a'
  53. elseif f.kind == 'multikill' then str = p.username .. ' just scored a' end
  54. g.setColor(255, 255, 255, 255 * math.min(f.alpha, 1))
  55. g.setFont('BebasNeue', v * .035)
  56. g.printCenter(str, f.x, f.y, true, false)
  57. local height
  58. if f.kind == 'multikill' then
  59. height = v * .06 + (v * .01 * (f.amount - 2))
  60. local multipliers = {[2] = 'double', [3] = 'triple', [4] = 'quadra', [5] = 'monster'}
  61. str = multipliers[math.min(f.amount, #multipliers)] .. ' kill'
  62. elseif f.kind == 'streak' then
  63. height = v * .06 + (v * .01 * (f.amount - 3) / 2)
  64. local streaks = {[3] = 'killing spree', [5] = 'bloodbath', [8] = 'massacre'}
  65. str = streaks[math.min(f.amount, #streaks)]
  66. end
  67. g.setFont('BebasNeue', height)
  68. g.printCenter(str, f.x, f.y + v * .038, true, false)
  69. end
  70. end
  71. return KillPopup