Game Development Reference
In-Depth Information
1 #!/usr/bin/env ruby
2
3 require 'gosu'
4
5 root_dir = File . dirname( __FILE__ )
6 require_pattern = File . join(root_dir, '**/*.rb' )
7 @failed = []
8
9 # Dynamically require everything
10 Dir . glob(require_pattern) . each do | f |
11 nextif f . end_with?( '/main.rb' )
12 begin
13 require_relative f . gsub( " #{ root_dir } /" , '' )
14 rescue
15 # May fail if parent class not required yet
16 @failed << f
17 end
18 end
19
20 # Retry unresolved requires
21 @failed . each do | f |
22 require_relative f . gsub( " #{ root_dir } /" , '' )
23 end
24
25 $window = GameWindow . new
26 GameState . switch( MenuState . instance)
27 $window . show
Finally, we made some improvements to main.rb - it now recursively requires all *.rb
files within same directory, so we don't have to worry about it in other classes.
05-refactor/utils.rb
1 module Utils
2 def self . media_path (file)
3
File . join( File . dirname( File . dirname(
__FILE__ )), 'media' , file)
4
5 end
6
7 def self . track_update_interval
8 now = Gosu . milliseconds
9 @update_interval = (now - ( @last_update ||= 0 )) . to_f
10 @last_update = now
11 end
12
13 def self . update_interval
Search WWH ::




Custom Search