arcadetext.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. local ArcadeText = {}
  2. ArcadeText.name = 'ArcadeText'
  3. ArcadeText.code = 'arcadetext'
  4. ArcadeText.activate = function(self)
  5. local dir = math.clamp(love.math.randomNormal(math.pi / 6, math.pi / 2), math.pi / 3, 2 * math.pi / 3)
  6. self.vx = math.cos(dir) * 100
  7. self.vy = math.sin(dir) * -100
  8. self.alpha = 1.5
  9. ctx.view:register(self, 'gui')
  10. end
  11. ArcadeText.update = function(self)
  12. self.prevx, self.prevy = self.x, self.y
  13. self.x = self.x + self.vx * tickRate
  14. self.y = self.y + self.vy * tickRate
  15. self.vy = self.vy + 500 * tickRate
  16. self.alpha = math.lerp(self.alpha, 0, math.min(4 * tickRate, 1))
  17. if self.alpha < .01 then return true end
  18. end
  19. ArcadeText.gui = function(self)
  20. local g, v = love.graphics, ctx.view
  21. local a = math.min(self.alpha, 1)
  22. local x = math.lerp(self.prevx or self.x, self.x, tickDelta / tickRate)
  23. local y = math.lerp(self.prevy or self.y, self.y, tickDelta / tickRate)
  24. x = (x - v.x) * v.scale
  25. y = (y - v.y) * v.scale
  26. g.setFont('pixel', 8)
  27. g.setColor(0, 0, 0, 255 * a)
  28. g.printCenter(self.str, x + 1, y + 1)
  29. g.setColor(255, 255, 255, 255 * a)
  30. g.printCenter(self.str, x, y)
  31. end
  32. return ArcadeText