shell.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. end
  13. Shell.update = function(self)
  14. self.angularVelocity = math.lerp(self.angularVelocity, 0, math.min(4 * tickRate, 1))
  15. self.angle = self.angle + self.angularVelocity * tickRate
  16. self.speed = math.lerp(self.speed, 0, math.min(self.speedDecay * tickRate, 1))
  17. self.x = self.x + math.dx(self.speed * tickRate, self.direction)
  18. self.y = self.y + math.dy(self.speed * tickRate, self.direction)
  19. if self.speed < .5 then
  20. self.alpha = math.lerp(self.alpha, 0, math.min(4 * tickRate, 1))
  21. if self.alpha < .01 then
  22. return true
  23. end
  24. end
  25. end
  26. Shell.draw = function(self)
  27. love.graphics.setColor(255, 255, 255, self.alpha * 255)
  28. love.graphics.draw(self.image, self.x, self.y, self.angle, self.scale, self.scale, self.image:getWidth() / 2, self.image:getHeight() / 2)
  29. end
  30. return Shell