Sha256: 50b0f072b7c7bd4487ba7b1f51ec7129654cf1c75336f01e5d687d893a2cf162

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

class Explosion < Actor
  use_systems :interpolation
  collides_as :explosion

  def initialize(opts={})
    super
    set_image('explosion.png', opts)
    @initial_radius = opts[:initial_radius] || 10.0
    @final_radius = opts[:final_radius] || 100.0
    @duration = opts[:duration] || 3.0
    @fade_after = opts[:fade_after] || 2.5

    interpolate_alpha(:init => 255, :end => 0, :duration => @duration - @fade_after, :start_in => @fade_after)
    interpolate_saturation(:init => 0.0, :end => 1.0, :duration => 0.1, :loop => true)
    # Don't know why gosu changes my hue when only transforming
    # saturation so we keep it fixed, or give it a little space for
    # change
    interpolate_hue(:init => @color.hue-50, :end => @color.hue+50, :loop => true, :duration => 0.5)

    self.radius = @initial_radius
    # Expand or shrink the explosion
    interpolate_my( :radius, :init => @initial_radius, :end => @final_radius, :duration => @duration )

    @z = ZOrder::Explosion
    @elapsed_time = 0.0
  end

  def update
    # Note to self: It's important to call super!
    super
    if @elapsed_time > @duration
      die
    end
    @elapsed_time += dt
  end

  def collision_radius
    @collision_radius
  end

  def radius=(radius)
    @collision_radius = radius
    @factor_x = 2*radius/@image.width
    @factor_y = 2*radius/@image.height
  end

  def to_s
    ["@elapsed_time #{format('%.2f', @elapsed_time)}",
     "@color.alpha #{@color.alpha}",
     "@color.hue #{format('%.2f', @color.hue)}",
     "@color.saturation #{format('%.2f', @color.saturation)}",
     "@color.value #{format('%.2f', @color.value)}"]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
missile-command-ruby-0.0.8 lib/explosion.rb