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

- old
+ new

@@ -1,15 +1,15 @@ class Silo < Actor + collides_as :silo attr_accessor :stock def initialize(opts={}) super - set_image 'silo2.png', opts + set_image 'silo-b.png', opts @factor = @width / @image.width @y = $lotu.height - @height/2 - @z = 5 - @speed = opts[:speed] + @z = ZOrder::Silo @platform = [] # How many missiles in stock? @stock = opts[:stock] # How many missiles on platform? @@ -26,22 +26,26 @@ # If negative, it adds some initial delay @elapsed_time = -2 # Platform configuration in pixels - @head_width = 75 * @factor - @tail_width = 35 * @factor - @platform_height = 70 * @factor + @left_padding = 13 * @factor + @right_padding = 24 * @factor + @bottom_padding = 18 * @factor - @missile_image_width = 22.0 + @missile_image_width = 26 @missile_animation_width = @missile_image_width * 20 / 15 @slot_width = platform_width/@platform_capacity end + def collision_radius + 50 + end + def platform_width - @width - @head_width - @tail_width + @width - @left_padding - @right_padding end def update super load_platform @@ -58,55 +62,51 @@ end end end def new_missile - missile = Missile.new(:mass => @missile_conf[:mass], + missile = PlayerMissile.new(:mass => @missile_conf[:mass], :max_force => @missile_conf[:force], :max_speed => @missile_conf[:speed], - :rand_color => true, :width => @missile_image_width*@factor) - missile.pos.x = initial_place(missile) - missile.pos.y = @y + @height/2 - missile.height/2 - @platform_height + missile.x = initial_place(missile) + missile.y = @y + @height/2 - missile.height/2 - @bottom_padding + missile.interpolate(missile, :y, :init => missile.y+20, :end => missile.y, :duration => 0.5) missile end def initial_place(missile) - res = @x - @width/2 + @head_width + missile.width/2 + (@platform_capacity - 1) * @slot_width + res = @x - @width/2 + @left_padding + missile.width/2 + (@platform_capacity - 1) * @slot_width res += (@slot_width - missile.width) res -= @elapsed_time / @load_time * @slot_width res end def place_missiles @platform.each_with_index do |missile, i| - place_to_be = @x - @width/2 + @head_width + missile.width/2 + i * @slot_width + place_to_be = @x - @width/2 + @left_padding + missile.width/2 + i * @slot_width place_to_be += i/(@platform_capacity-1) * (@slot_width - missile.width) - if missile.pos.x > initial_place(missile) - missile.pos.x = initial_place(missile) + if missile.x > initial_place(missile) + missile.x = initial_place(missile) end - if missile.pos.x > place_to_be - missile.pos.x -= @slot_width * dt / @load_time + if missile.x > place_to_be + missile.x -= @slot_width * dt / @load_time end - if missile.pos.x <= place_to_be - missile.pos.x = place_to_be + if missile.x <= place_to_be + missile.x = place_to_be end end end def launch_missile(x, y) if m = @platform.shift - m.target = Vector2d.new(x,y) + m.save_init_pos + m.stop_interpolations + target = Vector2d.new(x,y) + m.align_to target + m.target = target m.play_animation('missile.png', :width => @missile_animation_width*@factor) end - end - - def move_left - @x -= @speed * dt - end - - def move_right - @x += @speed * dt end def to_s ["@platform.length: #{@platform.length}", "Missiles in stock: #{@stock}",