Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Math
- # Convert degree to radian
- def self.radian(degree)
- return (degree.to_f/180) * Math::PI
- end
- end
- class Particle < Sprite
- @@degree = 0
- @@method = [:sin, :cos]
- @@bitmap = nil
- def initialize
- super
- unless @@bitmap
- @@bitmap = Bitmap.new(3,3)
- @@bitmap.fill_rect(@@bitmap.rect, Color.new(255,255,255))
- end
- self.bitmap = @@bitmap
- self.ox = width/2
- self.oy = height/2
- @degree = @@degree
- @@degree += 181
- @radius = 2
- @x = Graphics.width/2
- @y = Graphics.height/2
- @x_method = @@method[0]
- @y_method = @@method[1]
- @timeout = 750
- temp = @@method[0]
- @@method[0] = @@method[1]
- @@method[1] = temp
- update_position
- end
- def update_position
- self.x = @x
- self.y = @y
- end
- def update
- super
- @timeout -= 1
- update_spread
- end
- def update_spread
- @degree += 2
- @x += Math.method(@x_method).call(Math.radian(@degree)) * @radius
- @y += Math.method(@y_method).call(Math.radian(@degree)) * @radius
- update_position
- end
- def out?
- !self.x.between?(0,Graphics.width) || !self.y.between?(0,Graphics.height) ||
- @timeout == 0
- end
- end
- class Particles
- def initialize
- @sprites = []
- @time_span = 0
- end
- def update
- if @time_span == 0
- @sprites << Particle.new
- #~ @sprites << Particle.new
- @time_span = 1
- else
- @time_span -= 1
- end
- @sprites.delete_if do |spr|
- spr.update
- spr.dispose if spr.out?
- spr.disposed?
- end
- end
- end
- $particle = Particles.new
- loop do
- Graphics.update
- Input.update
- $particle.update
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement