Skip to content
Browse files

Better initializer code for main application, with code register.

  • Loading branch information...
1 parent f98643c commit 46b1c3a77f2c691b6b06396f61856a362f6eaac7 @mauricioszabo committed Dec 3, 2011
Showing with 20 additions and 3 deletions.
  1. +20 −3 lib/ar_sdl.rb
View
23 lib/ar_sdl.rb
@@ -7,10 +7,23 @@
class ArSDL
PAUSE = 20
- def initialize
- back = Sprite.new :background
+ def initialize(code1, code2)
@scene = Scene.new create_screen
+ require File.expand_path(code1)
+ require File.expand_path(code2)
+ @scene.register_to class_for(code1), :p1
+ @scene.register_to class_for(code2), :p2
+ end
+
+ def class_for(string)
+ const_name = string.gsub(/(^|_)(.)/) { |a,b| a.gsub("_","").upcase }
+ const_name.gsub! /\.rb$/, ''
+ eval const_name
+ end
+ private :class_for
+ def run
+ back = Sprite.new :background
while calculate_events
back.draw_on(@screen, 0, 0)
@scene.update
@@ -52,4 +65,8 @@ def pause_and
private :pause_and
end
-ArSDL.new if __FILE__ == $0
+if __FILE__ == $0
+ code1, code2 = ARGV[0..1]
+ sdl = ArSDL.new code1, code2
+ sdl.run
+end

0 comments on commit 46b1c3a

Please sign in to comment.
Something went wrong with that request. Please try again.