hudstatus.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. local g = love.graphics
  2. HudStatus = class()
  3. function HudStatus:init()
  4. self.jujuScale = 1
  5. self.populationScale = 1
  6. self.clockScale = 1
  7. self.jujuAngle = 2 * math.pi
  8. self.jjpm = 0
  9. self.jjpmTimer = 1
  10. self.jjpmHover = false
  11. self.jujuDisplay = config.player.baseJuju
  12. self.prev = {}
  13. for _, k in pairs({'jujuScale', 'populationScale', 'clockScale', 'jujuAngle'}) do
  14. self.prev[k] = self[k]
  15. end
  16. self.clockIcon = data.media.graphics.hud.clockBlue
  17. self.hitboxes = {juju = {0, 0, 0, 0}, population = {0, 0, 0, 0}, timer = {0, 0, 0, 0}}
  18. end
  19. function HudStatus:update()
  20. if not ctx.tutorial:shouldShowHudStatus() then return end
  21. for k in pairs(self.prev) do
  22. self.prev[k] = self[k]
  23. end
  24. local p = ctx.player
  25. self.jujuScale = math.lerp(self.jujuScale, 1, 10 * ls.tickrate)
  26. self.populationScale = math.lerp(self.populationScale, 1, 10 * ls.tickrate)
  27. self.clockScale = math.lerp(self.clockScale, 1, 10 * ls.tickrate)
  28. self.jujuAngle = math.lerp(self.jujuAngle, 2 * math.pi, math.min(3 * ls.tickrate, 1))
  29. local benchmark = 'Blue'
  30. local old = self.clockIcon
  31. if math.floor(ctx.timer * ls.tickrate) >= config.medals.gold then benchmark = 'Gold'
  32. elseif math.floor(ctx.timer * ls.tickrate) >= config.medals.silver then benchmark = 'Silver'
  33. elseif math.floor(ctx.timer * ls.tickrate) >= config.medals.bronze then benchmark = 'Bronze' end
  34. self.clockIcon = data.media.graphics.hud['clock' .. benchmark]
  35. if self.clockIcon ~= old then
  36. self.clockScale = 2
  37. end
  38. self.jjpmTimer = timer.rot(self.jjpmTimer, function()
  39. self.jjpm = math.round((p.totalJuju / (ctx.timer * ls.tickrate / 60)) / .1) * .1
  40. if self.jjpmHover then ctx:mousemoved(love.mouse.getPosition()) end
  41. return .5
  42. end)
  43. self.jujuDisplay = math.lerp(self.jujuDisplay, p.juju, 10 * ls.tickrate)
  44. if math.abs(self.jujuDisplay - p.juju) < 1 then self.jujuDisplay = p.juju end
  45. end
  46. function HudStatus:draw()
  47. if not ctx.tutorial:shouldShowHudStatus() then return end
  48. local u, v = ctx.hud.u, ctx.hud.v
  49. local p = ctx.player
  50. local mx, my = love.mouse.getPosition()
  51. local lerpd = {}
  52. for k in pairs(self.prev) do
  53. lerpd[k] = math.lerp(self.prev[k], self[k], ls.accum / ls.tickrate)
  54. end
  55. -- Status bar
  56. local image = data.media.graphics.hud.statusBar
  57. local scale = v * .07 / image:getHeight()
  58. local width, height = 425 * scale, 60 * scale
  59. g.setColor(255, 255, 255)
  60. g.draw(image, u + .05 * u, 0, 0, scale, scale, image:getWidth(), 0)
  61. -- Juju Icon
  62. local image = data.media.graphics.juju
  63. local scale = (height * .6) / image:getHeight()
  64. local s = scale * lerpd.jujuScale
  65. local xx = u - width + (v * .035) + image:getWidth() / 2 * scale + .05 * u
  66. local hitboxX = xx - image:getWidth() / 2 * scale
  67. g.draw(image, xx, height / 2, lerpd.jujuAngle, s, s, image:getWidth() / 2, image:getHeight() / 2)
  68. -- Juju Text
  69. g.setFont('mesmerize', height * .4)
  70. g.setColor(255, 255, 255)
  71. local str = math.floor(self.jujuDisplay)
  72. g.print(str, xx + (v * .03), (height * .5) - g.getFont():getHeight() / 2 + 1)
  73. local hitboxWidth = (xx + (v * .03) + g.getFont():getWidth(str)) - hitboxX
  74. self.hitboxes.juju[1] = hitboxX
  75. self.hitboxes.juju[2] = 0
  76. self.hitboxes.juju[3] = hitboxWidth
  77. self.hitboxes.juju[4] = height
  78. xx = xx + math.max(v * .06, g.getFont():getWidth(str)) + (v * .07)
  79. local hitboxX = xx
  80. -- Population Icon
  81. --[[local image = data.media.graphics.hud.population
  82. local scale = (height * .6) / image:getHeight()
  83. local s = scale * lerpd.populationScale
  84. xx = xx + image:getWidth() / 2 * scale
  85. local r, gg, b = 21, 142, 149
  86. g.setColor(r, gg, b)
  87. g.draw(image, xx, height / 2, 0, s, s, image:getWidth() / 2, image:getHeight() / 2)
  88. -- Population Text
  89. local str = 0
  90. local r, gg, b = 255, 255, 255
  91. g.setColor(r, gg, b)
  92. g.print(str, xx + (v * .025), (height * .5) - g.getFont():getHeight() / 2 + 1)
  93. local hitboxWidth = (xx + (v * .025) + g.getFont():getWidth(str)) - hitboxX
  94. self.hitboxes.population[1] = hitboxX
  95. self.hitboxes.population[2] = 0
  96. self.hitboxes.population[3] = hitboxWidth
  97. self.hitboxes.population[4] = height
  98. xx = xx + math.max(v * .05, g.getFont():getWidth(str)) + (v * .04)
  99. local hitboxX = xx
  100. g.setColor(255, 255, 255)]]
  101. -- Timer Icon
  102. local image = self.clockIcon
  103. local scale = (height * .6) / image:getHeight()
  104. local s = scale * lerpd.clockScale
  105. xx = xx + image:getWidth() / 2 * scale
  106. g.draw(image, xx, height / 2, 0, s, s, image:getWidth() / 2, image:getHeight() / 2)
  107. -- Timer Text
  108. local str = toTime(ctx.timer * ls.tickrate, true)
  109. g.setColor(255, 255, 255)
  110. g.print(str, xx + (.025 * v), (height * .5) - g.getFont():getHeight() / 2 + 1)
  111. local hitboxWidth = (xx + (v * .025) + g.getFont():getWidth(str)) - hitboxX
  112. self.hitboxes.timer[1] = hitboxX
  113. self.hitboxes.timer[2] = 0
  114. self.hitboxes.timer[3] = hitboxWidth
  115. self.hitboxes.timer[4] = height
  116. end
  117. function HudStatus:mousemoved(mx, my)
  118. if not ctx.tutorial:shouldShowHudStatus() then return end
  119. local p = ctx.player
  120. self.jjpmHover = false
  121. if math.inside(mx, my, unpack(self.hitboxes.juju)) then
  122. self.jjpmHover = true
  123. ctx.hud.tooltip:setTooltip('{white}{title}Juju{normal}\n{whoCares}Use it to summon minions and purchase upgrades. Collect it in the juju realm.\n\n{green}' .. p.totalJuju .. ' {white}total juju ({green}' .. self.jjpm .. ' {white}per minute)')
  124. elseif math.inside(mx, my, unpack(self.hitboxes.population)) then
  125. --ooltip('{white}{title}Population{normal}\n{whoCares}The maximum number of minions you may summon at once.\n\n{green}' .. p.totalSummoned .. ' {white}minion' .. (p.totalSummoned == 1 and '' or 's') .. ' summoned.')
  126. elseif math.inside(mx, my, unpack(self.hitboxes.timer)) then
  127. local str = ''
  128. local time = ctx.timer * ls.tickrate
  129. str = str .. 'Bronze: ' .. (time >= config.medals.bronze and '{green}' or '{red}') .. toTime(config.medals.bronze) .. '{white}\n'
  130. str = str .. 'Silver: ' .. (time >= config.medals.silver and '{green}' or '{red}') .. toTime(config.medals.silver) .. '{white}\n'
  131. str = str .. 'Gold: ' .. (time >= config.medals.gold and '{green}' or '{red}') .. toTime(config.medals.gold) .. '{white}\n'
  132. ctx.hud.tooltip:setTooltip('{white}{title}Timer{normal}\n{whoCares}How long you\'ve lasted. Survive for a long time to unlock rewards!\n\n' .. str)
  133. end
  134. end