lib/missile.rb in missile-command-ruby-0.0.7 vs lib/missile.rb in missile-command-ruby-0.0.8

- old
+ new

@@ -1,49 +1,46 @@ # -*- coding: utf-8 -*- -class Missile < Actor - use SteeringSystem - use AnimationSystem +class Missile < Actor + #include Wireframe + use_systems :steering, :animation, :interpolation collides_as :missile def initialize(opts={}) super activate(:seek) @last_distance_to_target = nil @target = nil set_image('missile-med.png', opts) + @z = ZOrder::Missile + #build_wireframe Shape.points[:missile] end + def save_init_pos + @init_x = x + @init_y = y + end + + def align_to target + to_target = target - pos + self.heading = to_target.normalize! + end + def update @last_distance_to_target = distance_to_target if @target super # If missile goes past target or is 10 pixels away from it, just die if @target && (distance_to_target < 10 || !facing_target?) die end - return - if @bajando && @factor_y > 0.5 - @factor_y -= dt - else - @bajando = false - end - if !@bajando && @factor_y < 1.0 - @factor_y += dt - else - @bajando = true - end end def draw super color = @color.dup color.saturation = color.value = 0.3 - $lotu.draw_line(@pos.x, @pos.y, color, @target.x, @target.y, color) if @target - end - - def die - super - Explosion.new(:x => @x, :y => @y, :color => @color, :mode => :additive) + #$lotu.draw_line(@pos.x, @pos.y, color, @target.x, @target.y, color) if @target + $lotu.draw_line(@pos.x, @pos.y, color, @init_x, @init_y, color) if @target end def collision_radius @width/2 end