# -*- coding: utf-8 -*- 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 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 $lotu.draw_line(@pos.x, @pos.y, color, @init_x, @init_y, color) if @target end def collision_radius @width/2 end end