Class: Core::ParticleEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/particles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



85
86
87
# File 'lib/particles.rb', line 85

def x
  @x
end

#xrObject

Returns the value of attribute xr.



85
86
87
# File 'lib/particles.rb', line 85

def xr
  @xr
end

#yObject

Returns the value of attribute y.



85
86
87
# File 'lib/particles.rb', line 85

def y
  @y
end

#yrObject

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_particleObject



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

#updateObject



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