class Core::Particle

Attributes

gravity[RW]
wind[RW]

Public Class Methods

new(x, y, file, lifetime, fade_in, fade_out, sx, sy, angle, color, mode) click to toggle source
# 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

Public Instance Methods

dead?() click to toggle source
# File lib/particles.rb, line 61
def dead?
  return @dead
end
draw(xoff=0, yoff=0) click to toggle source
# 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) click to toggle source
# File lib/particles.rb, line 46
def random_angle(bool)
  angle = 0
  if bool
    angle = rand(360)
  end
  return angle
end
update() click to toggle source
# 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