Class: Ashton::ParticleEmitter

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

Constant Summary collapse

DEFAULT_MAX_PARTICLES =
1000
DEFAULT_COLOR =
Gosu::Color::WHITE
RANGED_ATTRIBUTES =
[
    :angular_velocity, :center_x, :center_y,
    :fade, :friction, :interval,
    :offset, :scale, :speed, :time_to_live, :zoom
]

Instance Method Summary collapse

Constructor Details

#initialize(x, y, z, options = {}) ⇒ ParticleEmitter

Returns a new instance of ParticleEmitter.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ashton/particle_emitter.rb', line 13

def initialize(x, y, z, options = {})
  # I'm MUCH too lazy to implement a huge options hash manager in C, especially on a constructor.
  max_particles = options[:max_particles] || DEFAULT_MAX_PARTICLES
  initialize_ x, y, z, max_particles

  self.shader = options[:shader]
  self.image = options[:image] || $window.pixel

  self.gravity = options[:gravity] || 0.0
  self.color = options[:color] || DEFAULT_COLOR

  self.angular_velocity = options[:angular_velocity] || 0.0
  self.center_x = options[:center_x] || 0.5
  self.center_y = options[:center_y] || 0.5
  self.fade = options[:fade] || 0.0
  self.friction = options[:friction] || 0.0
  self.interval = options[:interval] || Float::INFINITY
  self.offset = options[:offset] || 0.0
  self.scale = options[:scale] || 1.0
  self.speed = options[:speed] || 0.0
  self.time_to_live = options[:time_to_live] || Float::INFINITY
  self.zoom = options[:zoom] || 0.0
end

Instance Method Details

#colorObject

Gosu::Color



38
39
40
# File 'lib/ashton/particle_emitter.rb', line 38

def color
  Gosu::Color.new color_argb
end

#color=(value) ⇒ Object

Gosu::Color, Integer, Array<Float>


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ashton/particle_emitter.rb', line 43

def color=(value)
  case value
    when Integer
      self.color_argb = value
    when Gosu::Color
      self.color_argb = value.to_i
    when Array
      self.color_argb = Gosu::Color.from_opengl value
    else
      raise TypeError, "Expected argb integer, rgba opengl float array or Gosu::Color"
  end

  value
end

#drawObject



# File 'lib/ashton/particle_emitter.rb', line 82

#empty?Boolean

Returns:

  • (Boolean)


3
# File 'lib/ashton/particle_emitter.rb', line 3

def empty?; count == 0 end

#update(delta) ⇒ Object

Parameters:

  • delta (Float)

    number of seconds to run the simulation for.



# File 'lib/ashton/particle_emitter.rb', line 84