lib/explosion.rb in missile-command-ruby-0.0.5 vs lib/explosion.rb in missile-command-ruby-0.0.6
- old
+ new
@@ -1,7 +1,8 @@
class Explosion < Actor
- attr_reader :collision_radius
+ use InterpolationSystem
+ collides_as :explosion
def initialize(opts={})
super
set_image('explosion.png', opts)
@initial_radius = 10.0
@@ -9,18 +10,19 @@
@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
+ # 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(self, :radius, :init => @initial_radius, :end => @end_radius, :duration => @explosion_time)
- collides_as :explosion
+
@z = 7
@elapsed_time = 0.0
end
def update
@@ -28,9 +30,13 @@
super
if @elapsed_time > @explosion_time
die
end
@elapsed_time += dt
+ end
+
+ def collision_radius
+ @collision_radius
end
def radius=(radius)
@collision_radius = radius
@factor_x = 2*radius/@image.width