# -*- coding: utf-8 -*- class Missile < Actor attr_reader :collision_radius def initialize(opts={}) super use(SteeringSystem, opts) activate(:seek) collides_as :missile @last_distance_to_target = nil @target = nil set_image('missile-med.png', opts) 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) end def collision_radius @width/2 end end