Class: Core::ParticleEmitter
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#xr ⇒ Object
Returns the value of attribute xr.
-
#y ⇒ Object
Returns the value of attribute y.
-
#yr ⇒ Object
Returns the value of attribute yr.
Instance Method Summary collapse
- #draw(xoff = 0, yoff = 0) ⇒ Object
- #gravity=(g) ⇒ Object
-
#initialize(file, lifetime, fade_in, fade_out, color, delay, angle, mode, xr, yr, xo, yo) ⇒ ParticleEmitter
constructor
A new instance of ParticleEmitter.
- #spawn_particle ⇒ Object
- #update ⇒ Object
- #wind=(w) ⇒ Object
Constructor Details
#initialize(file, lifetime, fade_in, fade_out, color, delay, angle, mode, xr, yr, xo, yo) ⇒ ParticleEmitter
Returns a new instance of ParticleEmitter.
86 87 88 89 90 91 92 93 94 |
# File 'lib/particles.rb', line 86 def initialize(file, lifetime, fade_in, fade_out, color, delay, angle, mode, xr, yr, xo, yo) @lifetime, @fade_in, @fade_out, @color, @angle = lifetime, fade_in, fade_out, color, angle @xoff, @yoff = xo, yo @delay, @file, @mode = delay, file, mode @particles = [] @next = 0 @xr, @yr, = xr, yr @wind = @gravity = 0 end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
85 86 87 |
# File 'lib/particles.rb', line 85 def x @x end |
#xr ⇒ Object
Returns the value of attribute xr.
85 86 87 |
# File 'lib/particles.rb', line 85 def xr @xr end |
#y ⇒ Object
Returns the value of attribute y.
85 86 87 |
# File 'lib/particles.rb', line 85 def y @y end |
#yr ⇒ Object
Returns the value of attribute yr.
85 86 87 |
# File 'lib/particles.rb', line 85 def yr @yr end |
Instance Method Details
#draw(xoff = 0, yoff = 0) ⇒ Object
115 116 117 118 119 |
# File 'lib/particles.rb', line 115 def draw(xoff=0, yoff=0) @particles.each { |p| p.draw(xoff, yoff) } end |
#gravity=(g) ⇒ Object
123 124 125 |
# File 'lib/particles.rb', line 123 def gravity=(g) @gravity = g end |
#spawn_particle ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/particles.rb', line 108 def spawn_particle sx = @xr.to_a.sample sy = @yr.to_a.sample @particles.push(Core::Particle.new(@x+@xoff.to_a.sample, @y+@yoff.to_a.sample, @file, @lifetime, @fade_in, @fade_out, sx, sy, @angle, @color.dup, @mode)) @particles.last.wind = @wind @particles.last.gravity = @gravity end |
#update ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/particles.rb', line 95 def update @next -= 1 if @next <= 0 spawn_particle @next = @delay end @particles.each { |p| p.update if p.dead? @particles.delete(p) end } end |
#wind=(w) ⇒ Object
120 121 122 |
# File 'lib/particles.rb', line 120 def wind=(w) @wind = w end |