Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Particle < Sprite
- # Min-Max movement speed
- MaxSpeed = 13
- MinSpeed = 5
- # Min-Max amplitude
- MaxAmp = 100
- MinAmp = 20
- def initialize
- super
- self.bitmap = Bitmap.new(32,32)
- self.bitmap.fill_rect(bitmap.rect, Color.new(255,255,255))
- self.ox = width/2
- @amplitude = 1
- @speed = 1
- @radian = 0.0
- restart
- end
- def restart
- @amplitude = MinAmp + rand(MaxAmp - MinAmp)
- @speed = rand(3) + 1 + rand
- @swing_speed = rand * 0.1
- @radian = rand + rand
- @xpos = rand(Graphics.width)
- @ypos = Graphics.height.to_f
- @method = [:sin, :cos].shuffle.first
- self.y = @ypos
- self.x = @xpos
- self.zoom_x = self.zoom_y = 1.0
- end
- def update
- super
- update_movement
- restart if self.zoom_x <= 0.0
- end
- def update_movement
- @radian += @swing_speed
- @ypos -= @speed
- self.x = Math.method(@method).call(@radian) * @amplitude + @xpos
- self.y = @ypos
- self.zoom_x -= 0.01
- self.zoom_y -= 0.01
- end
- end
- $sprite = Particle.new
- loop do
- Graphics.update
- Input.update
- $sprite.update
- end
Advertisement
Add Comment
Please, Sign In to add comment