class Core::ParticleEmitter

Attributes

x[RW]
xr[RW]
y[RW]
yr[RW]

Public Class Methods

new(file, lifetime, fade_in, fade_out, color, delay, angle, mode, xr, yr, xo, yo) click to toggle source
# 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

Public Instance Methods

draw(xoff=0, yoff=0) click to toggle source
# File lib/particles.rb, line 115
def draw(xoff=0, yoff=0)
  @particles.each { |p|
    p.draw(xoff, yoff)
  }
end
gravity=(g) click to toggle source
# File lib/particles.rb, line 123
def gravity=(g)
  @gravity = g
end
spawn_particle() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/particles.rb, line 120
def wind=(w)
  @wind = w
end