begin require 'rubygems' rescue LoadError end require 'lotu' include Lotu require 'silo' require 'explosion' require 'missile' require 'cross_hair' class MissileCommand < Game def initialize super setup_events @info = TextBox.new(:size => 15) @info.text("Press F1 to hide this text | F2 debug info | F3 toggle pause", :size => 24) @info.watch(@systems[FpsSystem], :size => 20) @info.watch(@systems[StalkerSystem], :color => 0xff33ccff) @info.text("Click on screen to launch some missiles!") end def load_resources with_path_from_file(__FILE__) do load_images 'media/images' load_sounds 'media/sounds' load_animations 'media/animations' end end def setup_input set_keys(Gosu::KbEscape => :close, Gosu::KbF1 => [:toggle_info, false], Gosu::KbF2 => [:debug!, false], Gosu::KbF3 => [:pause!, false]) end def setup_systems # It's important to call super here to setup the InputSystem super use(CollisionSystem) use(FpsSystem) use(StalkerSystem, :stalk => [Actor, Silo, Missile, Explosion, TextBox, Object]) end def setup_actors @player = Silo.new(:x => width/2, :width => 100, :stock => 10000, :platform_capacity => 4, :load_time => 0.1, :speed => 100, :missile_speed => 1000, :missile_force => 1000, :missile_mass => 0.5) @player.set_keys(Gosu::KbA => :move_left, Gosu::KbD => :move_right) @cross_hair = CrossHair.new(:keys => {Gosu::MsLeft => [:click, false], Gosu::MsRight => :click}, :rand_color => true, :mode => :additive, :width => 100) @silo_info = TextBox.new(:attach_to => @player, :size => 14) @silo_info.watch(@player) end def setup_events @cross_hair.on :click do |x, y| @player.launch_missile(x, y) end when_colliding(:explosion, :missile) do |e, m| m.die end end def toggle_info @info.toggle! @silo_info.toggle! end end