TheoAllen

Untitled

Dec 30th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. class Particle < Sprite
  2. # Min-Max movement speed
  3. MaxSpeed = 13
  4. MinSpeed = 5
  5.  
  6. # Min-Max amplitude
  7. MaxAmp = 100
  8. MinAmp = 20
  9.  
  10. def initialize
  11. super
  12. self.bitmap = Bitmap.new(32,32)
  13. self.bitmap.fill_rect(bitmap.rect, Color.new(255,255,255))
  14. self.ox = width/2
  15. @amplitude = 1
  16. @speed = 1
  17. @radian = 0.0
  18. restart
  19. end
  20.  
  21. def restart
  22. @amplitude = MinAmp + rand(MaxAmp - MinAmp)
  23. @speed = rand(3) + 1 + rand
  24. @swing_speed = rand * 0.1
  25. @radian = rand + rand
  26. @xpos = rand(Graphics.width)
  27. @ypos = Graphics.height.to_f
  28. @method = [:sin, :cos].shuffle.first
  29. self.y = @ypos
  30. self.x = @xpos
  31. self.zoom_x = self.zoom_y = 1.0
  32. end
  33.  
  34. def update
  35. super
  36. update_movement
  37. restart if self.zoom_x <= 0.0
  38. end
  39.  
  40. def update_movement
  41. @radian += @swing_speed
  42. @ypos -= @speed
  43. self.x = Math.method(@method).call(@radian) * @amplitude + @xpos
  44. self.y = @ypos
  45. self.zoom_x -= 0.01
  46. self.zoom_y -= 0.01
  47. end
  48.  
  49. end
  50.  
  51. $sprite = Particle.new
  52.  
  53. loop do
  54. Graphics.update
  55. Input.update
  56. $sprite.update
  57. end
Advertisement
Add Comment
Please, Sign In to add comment