class Explosion < Actor attr_reader :collision_radius def initialize(opts={}) super set_image('explosion.png', opts) @initial_radius = 10.0 @end_radius = 100.0 @explosion_time = 3.0 @fade_after = 0.5 interpolate_alpha(:init => 255, :end => 0, :duration => @explosion_time - @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 transforming saturation # alone 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(self, :radius, :init => @initial_radius, :end => @end_radius, :duration => @explosion_time) collides_as :explosion @z = 7 @elapsed_time = 0.0 end def update # Note to self: It's important to call super! super if @elapsed_time > @explosion_time die end @elapsed_time += dt 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