Class: Core::Particle
Instance Attribute Summary collapse
-
#gravity ⇒ Object
Returns the value of attribute gravity.
-
#wind ⇒ Object
Returns the value of attribute wind.
Instance Method Summary collapse
- #dead? ⇒ Boolean
- #draw(xoff = 0, yoff = 0) ⇒ Object
-
#initialize(x, y, file, lifetime, fade_in, fade_out, sx, sy, angle, color, mode) ⇒ Particle
constructor
A new instance of Particle.
- #random_angle(bool) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(x, y, file, lifetime, fade_in, fade_out, sx, sy, angle, color, mode) ⇒ Particle
Returns a new instance of Particle.
39 40 41 42 43 44 45 |
# File 'lib/particles.rb', line 39 def initialize(x, y, file, lifetime, fade_in, fade_out, sx, sy, angle, color, mode) @img = Core.sprite("particles/#{file}") @dead = false @age = 0 @wind = @gravity = 0 @x, @y, @lifetime, @fade_in, @fade_out, @sx, @sy, @angle, @color, @mode = x, y, lifetime, fade_in, fade_out, sx, sy, random_angle(angle), color, mode end |
Instance Attribute Details
#gravity ⇒ Object
Returns the value of attribute gravity.
38 39 40 |
# File 'lib/particles.rb', line 38 def gravity @gravity end |
#wind ⇒ Object
Returns the value of attribute wind.
38 39 40 |
# File 'lib/particles.rb', line 38 def wind @wind end |
Instance Method Details
#dead? ⇒ Boolean
61 62 63 |
# File 'lib/particles.rb', line 61 def dead? return @dead end |
#draw(xoff = 0, yoff = 0) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/particles.rb', line 64 def draw(xoff=0, yoff=0) color = @color if @age < @fade_in a = 125 + ((((@age - @fade_in) * 255) / @lifetime)) a *= 2 elsif @age >= @lifetime - @fade_out a = ((@lifetime - @age) * 255 / @age).to_i else a = 255 end if a > 255 a = 255 elsif a < 0 a = 0 end color.alpha = a.to_i; @img.draw_rot(@x+xoff, @y+yoff, Core::PARTICLE_Z, @angle, 0.5, 0.5, 1, 1, color, @mode) end |
#random_angle(bool) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/particles.rb', line 46 def random_angle(bool) angle = 0 if bool angle = rand(360) end return angle end |
#update ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/particles.rb', line 53 def update @x += @sx + @wind @y += @sy + @gravity @age += 1 if @x > 1024 or @x < -@img.width or @y > 768+@img.height or @y < -@img.height or @age >= @lifetime @dead = true end end |