snow.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. local Snow = {}
  2. Snow.name = 'Snow'
  3. Snow.code = 'snow'
  4. function Snow:init()
  5. self.x = 0
  6. self.y = 0
  7. self.vx = 400 * (love.math.random() < .5 and -1 or 1)
  8. self.vy = 400 * (love.math.random() < .5 and -1 or 1)
  9. self.dx = love.math.random() < .5 and -1 or 1
  10. self.dy = love.math.random() < .5 and -1 or 1
  11. self.image = data.media.graphics.effects.bgBlizzard
  12. self.image:setWrap('repeat', 'repeat')
  13. self.quad = love.graphics.newQuad(0, 0, love.graphics.getWidth(), love.graphics.getHeight(), self.image:getWidth(), self.image:getHeight())
  14. end
  15. function Snow:update()
  16. self.x = self.x + self.vx * tickRate
  17. self.y = self.y + self.vy * tickRate
  18. self.vx = self.vx + self.dx * love.math.random(50, 100) * tickRate
  19. self.vy = self.vy + self.dy * love.math.random(50, 100) * tickRate
  20. if self.vx > 300 then self.dx = -1
  21. elseif self.vx < -300 then self.dx = 1 end
  22. if self.vy > 300 then self.dy = -1
  23. elseif self.vy < -300 then self.dy = 1 end
  24. end
  25. function Snow:gui()
  26. love.graphics.setColor(255, 255, 255, 90)
  27. local factor = 1
  28. local x, y = (ctx.view.x + ctx.view.width / 2 - self.x), (ctx.view.y + ctx.view.height / 2 - self.y)
  29. for _, z in ipairs({64, 128, 256}) do
  30. local scale = 1 + (ctx.view:convertZ(z) / 500)
  31. self.quad:setViewport(x, y, love.graphics.getWidth(), love.graphics.getHeight())
  32. love.graphics.draw(self.image, self.quad, 0, 0, 0, scale, scale)
  33. factor = factor + .1
  34. end
  35. end
  36. return Snow