Sha256: 87ceaa16a1645d2ee42d4919ce870d9ecd8778cfcc08b7f6783fdd1e584122b1

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# -*- coding: utf-8 -*-
class Missile < Actor
  use SteeringSystem
  use AnimationSystem

  collides_as :missile

  def initialize(opts={})
    super
    activate(:seek)
    @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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
missile-command-ruby-0.0.7 lib/missile.rb
missile-command-ruby-0.0.6 lib/missile.rb