shell.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. local Shell = {}
  2. Shell.name = 'Shell'
  3. Shell.code = 'shell'
  4. Shell.activate = function(self)
  5. self.speed = love.math.random(250, 500)
  6. self.angularVelocity = love.math.random(-1, 1) * 2 * math.pi
  7. self.angle = love.math.random() * 2 * math.pi
  8. self.alpha = .8
  9. self.image = data.media.graphics.effects.shell
  10. self.scale = 1
  11. self.speedDecay = 5 + love.math.random() * 3
  12. self.depth = -2
  13. ctx.view:register(self)
  14. end
  15. Shell.update = function(self)
  16. self.angularVelocity = math.lerp(self.angularVelocity, 0, math.min(4 * tickRate, 1))
  17. self.angle = self.angle + self.angularVelocity * tickRate
  18. self.speed = math.lerp(self.speed, 0, math.min(self.speedDecay * tickRate, 1))
  19. self.x = self.x + math.dx(self.speed * tickRate, self.direction)
  20. self.y = self.y + math.dy(self.speed * tickRate, self.direction)
  21. if self.speed < .5 then
  22. self.alpha = math.lerp(self.alpha, 0, math.min(4 * tickRate, 1))
  23. if self.alpha < .01 then
  24. return true
  25. end
  26. end
  27. end
  28. Shell.draw = function(self)
  29. love.graphics.setColor(255, 255, 255, self.alpha * 255)
  30. love.graphics.draw(self.image, self.x, self.y, self.angle, self.scale, self.scale, self.image:getWidth() / 2, self.image:getHeight() / 2)
  31. end
  32. return Shell