Class: MissileCommand
- Inherits:
-
Game
- Object
- Game
- MissileCommand
- Defined in:
- lib/missile-command-ruby.rb
Instance Method Summary collapse
-
#initialize ⇒ MissileCommand
constructor
A new instance of MissileCommand.
- #load_resources ⇒ Object
- #setup_actors ⇒ Object
- #setup_events ⇒ Object
- #setup_input ⇒ Object
- #toggle_info ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize ⇒ MissileCommand
Returns a new instance of MissileCommand.
66 67 68 69 |
# File 'lib/missile-command-ruby.rb', line 66 def initialize super @acc_dt = 0 end |
Instance Method Details
#load_resources ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/missile-command-ruby.rb', line 88 def load_resources with_path_from_file(__FILE__) do load_images 'media/images' load_sounds 'media/sounds' load_animations 'media/animations' load_songs 'media/songs' end end |
#setup_actors ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/missile-command-ruby.rb', line 104 def setup_actors @background = Background.new( :init_y => 500, :end_color => 0xff800080 ) @enemy_command = EnemyCommand.new( :stock => 50, :attack_every => 3 ) @player = Silo.new(:x => width/2, :width => 100, :stock => 10000, :platform_capacity => 5, :load_time => 0.2, :speed => 100, :missile_speed => 1000, :missile_force => 1000, :missile_mass => 0.5) @cross_hair = CrossHair.new(:keys => {Gosu::MsLeft => [:click, false], Gosu::MsRight => :click}, :rand_color => true, :mode => :additive, :width => 100) @info = TextBox.new(:size => 15) @info.text("Press F1 to hide this text | F2 debug info | F3 toggle pause", :size => 24) @info.watch(lambda{ fps }, :size => 20) @info.watch(@enemy_command) #@info.watch(@systems[StalkerSystem], :color => 0xff33ccff) @info.text("Click on screen to launch some missiles!") @silo_info = TextBox.new(:attach_to => @player, :size => 14) @silo_info.watch(@player) end |
#setup_events ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/missile-command-ruby.rb', line 133 def setup_events @cross_hair.on :click do |x, y| @player.launch_missile(x, y) end when_colliding(:explosion, :enemy_missile) do |e, m| m.die end when_colliding(:enemy_explosion, :silo) do |ex, s| #s.die end end |
#setup_input ⇒ Object
97 98 99 100 101 102 |
# File 'lib/missile-command-ruby.rb', line 97 def setup_input set_keys(Gosu::KbEscape => :close, Gosu::KbF1 => [:toggle_info, false], Gosu::KbF2 => [:debug!, false], Gosu::KbF3 => [:pause!, false]) end |
#toggle_info ⇒ Object
147 148 149 150 |
# File 'lib/missile-command-ruby.rb', line 147 def toggle_info @info.toggle! @silo_info.toggle! end |
#update ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/missile-command-ruby.rb', line 71 def update super @acc_dt += $lotu.dt if @acc_dt > @enemy_command.attack_every @enemy_command.attack! @acc_dt = 0 if rand > 0.5 @enemy_command.attack! end if rand > 0.96 (rand(4)+2).times do @enemy_command.attack! :extra => :speed end end end end |