gamebox 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/History.txt +14 -0
  2. data/Manifest.txt +40 -37
  3. data/README.txt +2 -2
  4. data/Rakefile +27 -20
  5. data/TODO.txt +8 -8
  6. data/bin/gamebox +7 -1
  7. data/docs/getting_started.rdoc +2 -5
  8. data/docs/logo.png +0 -0
  9. data/lib/gamebox.rb +12 -1
  10. data/lib/gamebox/actor.rb +34 -9
  11. data/lib/gamebox/actor_factory.rb +25 -14
  12. data/lib/gamebox/actor_view.rb +6 -6
  13. data/lib/gamebox/{logo.rb → actors/logo.rb} +0 -0
  14. data/lib/gamebox/{score.rb → actors/score.rb} +2 -1
  15. data/lib/gamebox/{svg_actor.rb → actors/svg_actor.rb} +3 -4
  16. data/lib/gamebox/ai/polaris.rb +2 -0
  17. data/lib/gamebox/behavior.rb +3 -0
  18. data/lib/gamebox/{animated.rb → behaviors/animated.rb} +13 -5
  19. data/lib/gamebox/{graphical.rb → behaviors/graphical.rb} +11 -1
  20. data/lib/gamebox/{layered.rb → behaviors/layered.rb} +14 -0
  21. data/lib/gamebox/{physical.rb → behaviors/physical.rb} +41 -14
  22. data/lib/gamebox/{updatable.rb → behaviors/updatable.rb} +1 -1
  23. data/lib/gamebox/{templates/template_app → data}/config/objects.yml +4 -2
  24. data/lib/gamebox/data/graphics/logo.png +0 -0
  25. data/lib/gamebox/event_compat.rb +285 -0
  26. data/lib/gamebox/ftor.rb +2 -0
  27. data/lib/gamebox/gamebox_application.rb +12 -1
  28. data/lib/gamebox/generators/actor_generator.rb +2 -2
  29. data/lib/gamebox/generators/view_generator.rb +42 -0
  30. data/lib/gamebox/input_manager.rb +88 -21
  31. data/lib/gamebox/{aliasing.rb → lib/aliasing.rb} +0 -0
  32. data/lib/gamebox/{templates/template_app/lib → lib}/diy.rb +0 -0
  33. data/lib/gamebox/{inflections.rb → lib/inflections.rb} +0 -0
  34. data/lib/gamebox/{inflector.rb → lib/inflector.rb} +2 -2
  35. data/lib/gamebox/{linked_list.rb → lib/linked_list.rb} +0 -0
  36. data/lib/gamebox/{metaclass.rb → lib/metaclass.rb} +0 -0
  37. data/lib/gamebox/lib/numbers_ext.rb +3 -0
  38. data/lib/gamebox/{platform.rb → lib/platform.rb} +0 -0
  39. data/lib/gamebox/{publisher_ext.rb → lib/publisher_ext.rb} +0 -0
  40. data/lib/gamebox/{sorted_list.rb → lib/sorted_list.rb} +0 -0
  41. data/lib/gamebox/lib/surface_ext.rb +76 -0
  42. data/lib/gamebox/physical_director.rb +1 -1
  43. data/lib/gamebox/{physical_level.rb → physical_stage.rb} +28 -18
  44. data/lib/gamebox/physics.rb +2 -2
  45. data/lib/gamebox/resource_manager.rb +77 -8
  46. data/lib/gamebox/sound_manager.rb +15 -17
  47. data/lib/gamebox/stage.rb +143 -0
  48. data/lib/gamebox/stage_manager.rb +110 -0
  49. data/lib/gamebox/svg_document.rb +1 -1
  50. data/lib/gamebox/tasks/gamebox_tasks.rb +1 -1
  51. data/lib/gamebox/templates/{test_actor.erb → actor_spec.erb} +2 -2
  52. data/lib/gamebox/templates/actor_view.erb +8 -0
  53. data/lib/gamebox/templates/actor_view_spec.erb +10 -0
  54. data/lib/gamebox/templates/template_app/Rakefile +4 -4
  55. data/lib/gamebox/templates/template_app/config/game.yml +1 -0
  56. data/lib/gamebox/templates/template_app/config/stage_config.yml +2 -0
  57. data/lib/gamebox/templates/template_app/script/generate +2 -1
  58. data/lib/gamebox/templates/template_app/{test → spec}/helper.rb +0 -0
  59. data/lib/gamebox/templates/template_app/src/{demo_level.rb → demo_stage.rb} +5 -3
  60. data/lib/gamebox/templates/template_app/src/game.rb +4 -6
  61. data/lib/gamebox/version.rb +3 -2
  62. data/lib/gamebox/viewport.rb +18 -9
  63. data/lib/gamebox/{graphical_actor_view.rb → views/graphical_actor_view.rb} +13 -1
  64. data/lib/gamebox/wrapped_screen.rb +2 -1
  65. data/spec/actor_spec.rb +57 -0
  66. data/{test/test_animated.rb → spec/animated_spec.rb} +5 -6
  67. data/spec/helper.rb +24 -0
  68. data/{test/test_line_of_site.rb → spec/line_of_site_spec.rb} +1 -1
  69. data/{test/test_physical.rb → spec/physical_spec.rb} +3 -4
  70. data/{test/test_polaris.rb → spec/polaris_spec.rb} +1 -1
  71. data/{test/test_viewport.rb → spec/viewport_spec.rb} +11 -8
  72. metadata +53 -50
  73. data/docs/gamebox04_big.png +0 -0
  74. data/lib/gamebox/level.rb +0 -65
  75. data/lib/gamebox/mode.rb +0 -123
  76. data/lib/gamebox/mode_manager.rb +0 -80
  77. data/lib/gamebox/numbers_ext.rb +0 -3
  78. data/lib/gamebox/surface_ext.rb +0 -37
  79. data/lib/gamebox/templates/template_app/config/mode_level_config.yml +0 -3
  80. data/test/helper.rb +0 -26
  81. data/test/test_actor.rb +0 -36
data/History.txt CHANGED
@@ -47,3 +47,17 @@
47
47
  * added ./script/generate to generate actors (ie ./script/generate actor Foo)
48
48
  * migrated all test to use rspec
49
49
  * changed clear_hooks to take a listener instance
50
+
51
+ === 0.0.7 / 2009-07-04
52
+
53
+ * New Particle System code in roids
54
+ * Changed license to MIT
55
+ * Bug fixes
56
+ * added OpenGL option for screen (per jacius request)
57
+ * reorganized code
58
+ * changed :parts to :shapes in the physical behavior
59
+ * merged in jacius' new event system
60
+ * new physics playground example
61
+ * new major ruby platformer example
62
+ * merged Mode/Level into Stage
63
+ * added curtain transitions
data/Manifest.txt CHANGED
@@ -4,22 +4,28 @@ README.txt
4
4
  Rakefile
5
5
  TODO.txt
6
6
  bin/gamebox
7
- docs/gamebox04_big.png
8
7
  docs/getting_started.rdoc
9
8
  docs/logo.png
10
9
  lib/gamebox.rb
11
10
  lib/gamebox/actor.rb
12
11
  lib/gamebox/actor_factory.rb
13
12
  lib/gamebox/actor_view.rb
13
+ lib/gamebox/actors/logo.rb
14
+ lib/gamebox/actors/score.rb
15
+ lib/gamebox/actors/svg_actor.rb
14
16
  lib/gamebox/ai/line_of_site.rb
15
17
  lib/gamebox/ai/polaris.rb
16
18
  lib/gamebox/ai/two_d_grid_location.rb
17
19
  lib/gamebox/ai/two_d_grid_map.rb
18
- lib/gamebox/aliasing.rb
19
- lib/gamebox/animated.rb
20
20
  lib/gamebox/behavior.rb
21
+ lib/gamebox/behaviors/animated.rb
22
+ lib/gamebox/behaviors/graphical.rb
23
+ lib/gamebox/behaviors/layered.rb
24
+ lib/gamebox/behaviors/physical.rb
25
+ lib/gamebox/behaviors/updatable.rb
21
26
  lib/gamebox/config_manager.rb
22
27
  lib/gamebox/console_app.rb
28
+ lib/gamebox/data/config/objects.yml
23
29
  lib/gamebox/data/fonts/Asimov.ttf
24
30
  lib/gamebox/data/fonts/GAMEBOX_FONTS_GO_HERE
25
31
  lib/gamebox/data/graphics/GAMEBOX_GRAPHICS_GO_HERE
@@ -27,68 +33,65 @@ lib/gamebox/data/graphics/logo.png
27
33
  lib/gamebox/data/music/GAMEBOX_MUSIC_GOES_HERE
28
34
  lib/gamebox/data/sounds/GAMEBOX_SOUND_FX_GO_HERE
29
35
  lib/gamebox/director.rb
36
+ lib/gamebox/event_compat.rb
37
+ lib/gamebox/ftor.rb
30
38
  lib/gamebox/gamebox_application.rb
31
39
  lib/gamebox/gamebox_generator.rb
32
40
  lib/gamebox/generators/actor_generator.rb
33
- lib/gamebox/graphical.rb
34
- lib/gamebox/graphical_actor_view.rb
35
- lib/gamebox/inflections.rb
36
- lib/gamebox/inflector.rb
41
+ lib/gamebox/generators/view_generator.rb
37
42
  lib/gamebox/input_manager.rb
38
- lib/gamebox/layered.rb
39
- lib/gamebox/level.rb
40
- lib/gamebox/linked_list.rb
41
- lib/gamebox/logo.rb
42
- lib/gamebox/metaclass.rb
43
- lib/gamebox/mode.rb
44
- lib/gamebox/mode_manager.rb
45
- lib/gamebox/numbers_ext.rb
46
- lib/gamebox/physical.rb
43
+ lib/gamebox/lib/aliasing.rb
44
+ lib/gamebox/lib/diy.rb
45
+ lib/gamebox/lib/inflections.rb
46
+ lib/gamebox/lib/inflector.rb
47
+ lib/gamebox/lib/linked_list.rb
48
+ lib/gamebox/lib/metaclass.rb
49
+ lib/gamebox/lib/numbers_ext.rb
50
+ lib/gamebox/lib/platform.rb
51
+ lib/gamebox/lib/publisher_ext.rb
52
+ lib/gamebox/lib/sorted_list.rb
53
+ lib/gamebox/lib/surface_ext.rb
54
+ lib/gamebox/stage.rb
55
+ lib/gamebox/stage_manager.rb
47
56
  lib/gamebox/physical_director.rb
48
- lib/gamebox/physical_level.rb
57
+ lib/gamebox/physical_stage.rb
49
58
  lib/gamebox/physics.rb
50
- lib/gamebox/platform.rb
51
- lib/gamebox/publisher_ext.rb
52
59
  lib/gamebox/resource_manager.rb
53
- lib/gamebox/score.rb
54
- lib/gamebox/sorted_list.rb
55
60
  lib/gamebox/sound_manager.rb
56
- lib/gamebox/surface_ext.rb
57
- lib/gamebox/svg_actor.rb
58
61
  lib/gamebox/svg_document.rb
59
62
  lib/gamebox/tasks/gamebox_tasks.rb
60
63
  lib/gamebox/templates/actor.erb
64
+ lib/gamebox/templates/actor_spec.erb
65
+ lib/gamebox/templates/actor_view.erb
66
+ lib/gamebox/templates/actor_view_spec.erb
61
67
  lib/gamebox/templates/template_app/README
62
68
  lib/gamebox/templates/template_app/Rakefile
63
69
  lib/gamebox/templates/template_app/config/boot.rb
64
70
  lib/gamebox/templates/template_app/config/environment.rb
65
71
  lib/gamebox/templates/template_app/config/game.yml
66
- lib/gamebox/templates/template_app/config/mode_level_config.yml
67
- lib/gamebox/templates/template_app/config/objects.yml
72
+ lib/gamebox/templates/template_app/config/stage_config.yml
68
73
  lib/gamebox/templates/template_app/data/fonts/FONTS_GO_HERE
69
74
  lib/gamebox/templates/template_app/data/graphics/GRAPHICS_GO_HERE
70
75
  lib/gamebox/templates/template_app/data/music/MUSIC_GOES_HERE
71
76
  lib/gamebox/templates/template_app/data/sounds/SOUND_FX_GO_HERE
72
77
  lib/gamebox/templates/template_app/doc/README_FOR_APP
73
78
  lib/gamebox/templates/template_app/lib/code_statistics.rb
74
- lib/gamebox/templates/template_app/lib/diy.rb
75
79
  lib/gamebox/templates/template_app/lib/platform.rb
76
80
  lib/gamebox/templates/template_app/script/generate
77
81
  lib/gamebox/templates/template_app/src/app.rb
78
- lib/gamebox/templates/template_app/src/demo_level.rb
82
+ lib/gamebox/templates/template_app/src/demo_stage.rb
79
83
  lib/gamebox/templates/template_app/src/game.rb
80
84
  lib/gamebox/templates/template_app/src/my_actor.rb
81
- lib/gamebox/templates/template_app/test/helper.rb
82
- lib/gamebox/templates/test_actor.erb
83
- lib/gamebox/updatable.rb
85
+ lib/gamebox/templates/template_app/spec/helper.rb
84
86
  lib/gamebox/version.rb
85
87
  lib/gamebox/viewport.rb
88
+ lib/gamebox/views/graphical_actor_view.rb
86
89
  lib/gamebox/wrapped_screen.rb
87
90
  script/perf_polaris.rb
88
- test/helper.rb
89
- test/test_actor.rb
90
- test/test_animated.rb
91
- test/test_line_of_site.rb
92
- test/test_physical.rb
93
- test/test_polaris.rb
94
- test/test_viewport.rb
91
+ spec/helper.rb
92
+ spec/actor_spec.rb
93
+ spec/animated_spec.rb
94
+ spec/line_of_site_spec.rb
95
+ spec/physical_spec.rb
96
+ spec/polaris_spec.rb
97
+ spec/viewport_spec.rb
data/README.txt CHANGED
@@ -19,7 +19,7 @@
19
19
  * Rubygame (its dependancies, SDL)
20
20
  * constructor gem
21
21
  * publisher gem
22
- * bacon (for gamebox tests)
22
+ * rsepec (for gamebox tests)
23
23
  * algorithms gem (optional for line of site and A*)
24
24
 
25
25
  == INSTALL:
@@ -28,6 +28,6 @@
28
28
 
29
29
  == LICENSE:
30
30
 
31
- (GPLv2)
31
+ (MIT)
32
32
 
33
33
  Copyright (c) 2009 Shawn Anderson
data/Rakefile CHANGED
@@ -3,22 +3,23 @@ gem 'hoe', '>= 2.3.0'
3
3
  require 'hoe'
4
4
 
5
5
  require File.dirname(__FILE__)+'/lib/gamebox/version'
6
- Hoe.new 'gamebox' do |spec|
7
- spec.developer('Shawn Anderson', 'shawn42@gmail.com')
8
- spec.author = "Shawn Anderson"
9
- spec.description = "Framework for building and distributing games using Rubygame"
10
- spec.email = 'shawn42@gmail.com'
11
- spec.summary = "Framework for building and distributing games using Rubygame"
12
- spec.url = "http://shawn42.github.com/gamebox"
13
- spec.version = Gamebox::VERSION::STRING
14
- spec.changes = spec.paragraphs_of('History.txt', 10..11).join("\n\n")
15
- spec.extra_deps << ['constructor']
16
- spec.extra_deps << ['publisher']
17
- spec.extra_deps << ['rspec']
18
- if spec.extra_rdoc_files
19
- spec.extra_rdoc_files << 'docs/getting_started.rdoc'
6
+ Hoe.spec 'gamebox' do
7
+ developer('Shawn Anderson', 'shawn42@gmail.com')
8
+ developer('Jason Roelofs', 'jameskilton@gmail.com')
9
+ developer('Karlin Fox', 'karlin.fox@gmail.com')
10
+ description = "Framework for building and distributing games using Rubygame"
11
+ email = 'shawn42@gmail.com'
12
+ summary = "Framework for building and distributing games using Rubygame"
13
+ url = "http://shawn42.github.com/gamebox"
14
+ self.version = Gamebox::VERSION::STRING
15
+ changes = paragraphs_of('History.txt', 12..13).join("\n\n")
16
+ extra_deps << ['constructor']
17
+ extra_deps << ['publisher']
18
+ extra_deps << ['rspec']
19
+ if extra_rdoc_files
20
+ extra_rdoc_files << 'docs/getting_started.rdoc'
20
21
  end
21
- spec.remote_rdoc_dir = ' ' # Release to root
22
+ remote_rdoc_dir = ' ' # Release to root
22
23
  end
23
24
 
24
25
  STATS_DIRECTORIES = [
@@ -32,11 +33,17 @@ task :stats do
32
33
  end
33
34
 
34
35
  require 'spec/rake/spectask'
35
- desc "Run all specs"
36
- Spec::Rake::SpecTask.new('specs') do |t|
37
- t.spec_opts = ["-r", "./test/helper"]
38
- t.spec_files = FileList['test//test_*.rb']
36
+ desc "Run all rspecs"
37
+ Spec::Rake::SpecTask.new('rspec') do |t|
38
+ t.spec_files = FileList['spec/*_spec.rb']
39
39
  end
40
- task :test => :specs
40
+
41
+ desc "Run rcov rspecs"
42
+ Spec::Rake::SpecTask.new('rcov_rspec') do |t|
43
+ t.spec_files = FileList['spec/*_spec.rb']
44
+ t.rcov = true
45
+ t.rcov_opts = ['--exclude', 'examples']
46
+ end
47
+ task :default => :rspec
41
48
 
42
49
  # vim: syntax=Ruby
data/TODO.txt CHANGED
@@ -1,4 +1,7 @@
1
1
  planned features:
2
+ add network manager stub
3
+ highscore upload system (use from chingu)
4
+ FIX:add some kind of fade in/out for actors w/ smooth interpolation
2
5
  add basic generator for things like actors/levels/etc with tests
3
6
  add while key down K_UP callback?
4
7
 
@@ -6,17 +9,17 @@ allow easy pausing of game and physics
6
9
  - fire :pause event w/ a new Director of actors?
7
10
  change Polaris to return partial path when step max is reached
8
11
  update physical objects to use chipmunk_object.rb
9
- allow for repeating actors (tiles)
10
- allow overriding of animation timing
11
- make complex Phyiscal behaviors (made up by a group of shapes/bodies pinned together?)
12
- physical objects should have bodies and shapes body/shape should be shorthand for bodies.first/shapes.first
12
+
13
+ make complex Phyiscal behaviors
14
+ - made up by a group of bodies pinned together
15
+ - easy joints
16
+ physical objects should have bodies and shapes body/shape should be shorthand for bodies.first/shapes.first
13
17
 
14
18
  - solidify rdocs (including tutorial)
15
19
  SVGS
16
20
  create a DynamicPhysicalActor that can be built from external verts
17
21
  add nice actor debugging
18
22
  add Extra; actor with a short time to live (TTL); useful for special effects (maybe as a behavior)
19
- add some kind of fade in/out for actors w/ smooth interpolation
20
23
 
21
24
  static deployment bundles (crate, love-clone; custom C project)
22
25
  ruby
@@ -27,7 +30,4 @@ AI
27
30
  state machine
28
31
  rule based
29
32
  optional GUI via rubygoo
30
- particle system? ParticleGroupActor?
31
- network manager
32
- highscore upload system
33
33
  gamebox server (content server?)
data/bin/gamebox CHANGED
@@ -7,6 +7,7 @@ require File.dirname(__FILE__) + '/../lib/gamebox/version'
7
7
  def print_version
8
8
  puts "Gamebox #{Gamebox::VERSION::STRING}"
9
9
  end
10
+
10
11
  def print_usage
11
12
  print_version
12
13
  puts "Usage:"
@@ -42,7 +43,7 @@ PROJECT_NAME = ARGV[0]
42
43
  TARGET_DIR = File.expand_path(Dir.pwd + "/" + PROJECT_NAME)
43
44
  SOURCE_DIR = File.expand_path(File.dirname(__FILE__) + "/../lib/gamebox/templates")
44
45
 
45
- Dir.mkdir(TARGET_DIR)
46
+ Dir.mkdir(TARGET_DIR) unless File.exist?(TARGET_DIR) && File.directory?(TARGET_DIR)
46
47
 
47
48
  # Generate the directory structure for the new application
48
49
  # Gems does not pull in empty directories so template_app only
@@ -71,3 +72,8 @@ Dir.glob("**/*").each do |file|
71
72
  end
72
73
  end
73
74
 
75
+ new_file = TARGET_DIR + "/config/gamebox_generator_version.yml"
76
+ File.open(new_file,"w+") do |f|
77
+ f.write Gamebox::VERSION::ARRAY.to_yaml
78
+ end
79
+
@@ -31,8 +31,7 @@ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing com
31
31
  | |-- boot.rb
32
32
  | |-- environment.rb
33
33
  | |-- game.yml
34
- | |-- mode_level_config.yml
35
- | `-- objects.yml
34
+ | `-- stage_config.yml
36
35
  |-- data
37
36
  | |-- fonts
38
37
  | | `-- FONTS_GO_HERE
@@ -40,14 +39,12 @@ The reason I wrote Gamebox is twofold: first, to aid in 48 hour game writing com
40
39
  | | `-- GRAPHICS_GO_HERE
41
40
  | |-- music
42
41
  | | `-- MUSIC_GOES_HERE
43
- | |-- sound
44
42
  | `-- sounds
45
43
  | `-- SOUND_FX_GO_HERE
46
44
  |-- doc
47
45
  | `-- README_FOR_APP
48
46
  |-- lib
49
47
  | |-- code_statistics.rb
50
- | |-- diy.rb
51
48
  | `-- platform.rb
52
49
  |-- script
53
50
  |-- src
@@ -135,6 +132,6 @@ The animation will cycle through all the numbered png files for the current acti
135
132
  Animated and Updatable are just two behaviors available in Gamebox. Other include graphical, layered, and physical. You can easily add your own game specific behaviors by extending Behavior. (see Wanderer in rague example).
136
133
 
137
134
  == Levels
138
- == Modes
135
+ == Stages
139
136
  == Physics
140
137
  == SVG Levels
data/docs/logo.png CHANGED
Binary file
data/lib/gamebox.rb CHANGED
@@ -1,4 +1,15 @@
1
- $: << File.dirname(__FILE__)+"/gamebox"
1
+ [
2
+ "gamebox",
3
+ "gamebox/actors",
4
+ "gamebox/ai",
5
+ "gamebox/behaviors",
6
+ "gamebox/generators",
7
+ "gamebox/lib",
8
+ "gamebox/tasks",
9
+ "gamebox/views"
10
+ ].each do |path|
11
+ $: << File.dirname(__FILE__)+"/"+path
12
+ end
2
13
 
3
14
  GAMEBOX_PATH = File.join(File.dirname(__FILE__),"gamebox/")
4
15
  require 'gamebox_application'
data/lib/gamebox/actor.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'publisher'
2
2
  # Actor represent a game object.
3
3
  # Actors can have behaviors added and removed from them. Such as :physical or :animated.
4
- # They are created and hooked up to their optional View class in Level#create_actor.
4
+ # They are created and hooked up to their optional View class in Stage#create_actor.
5
5
  class Actor
6
6
  extend Publisher
7
7
  can_fire_anything
8
8
 
9
- attr_accessor :behaviors, :x, :y, :level, :input_manager,
9
+ attr_accessor :behaviors, :x, :y, :stage, :input_manager,
10
10
  :resource_manager, :alive, :opts, :sound_manager, :visible,
11
11
  :director
12
12
 
@@ -17,7 +17,7 @@ class Actor
17
17
  @y = @opts[:y]
18
18
  @x ||= 0
19
19
  @y ||= 0
20
- @level = opts[:level]
20
+ @stage = opts[:stage]
21
21
  @input_manager = opts[:input]
22
22
  @sound_manager = opts[:sound]
23
23
  @resource_manager = opts[:resources]
@@ -25,10 +25,31 @@ class Actor
25
25
  @alive = true
26
26
 
27
27
  @behaviors = {}
28
- # add our classes behaviors
29
- class_behaviors = self.class.behaviors.dup
30
- for behavior in class_behaviors
31
- is behavior
28
+
29
+ # add our classes behaviors and parents behaviors
30
+ klass = self.class
31
+ actor_klasses = []
32
+ while klass != Actor
33
+ actor_klasses << klass
34
+ klass = klass.superclass
35
+ end
36
+
37
+ behavior_defs = {}
38
+ ordered_behaviors = []
39
+
40
+ actor_klasses.reverse.each do |actor_klass|
41
+ actor_behaviors = actor_klass.behaviors.dup
42
+ actor_behaviors.each do |behavior|
43
+
44
+ behavior_sym = behavior.is_a?(Hash) ? behavior.keys.first : behavior
45
+
46
+ ordered_behaviors << behavior_sym unless ordered_behaviors.include? behavior_sym
47
+ behavior_defs[behavior_sym] = behavior
48
+ end
49
+ end
50
+
51
+ ordered_behaviors.each do |behavior|
52
+ is behavior_defs[behavior]
32
53
  end
33
54
  setup
34
55
  end
@@ -75,7 +96,8 @@ class Actor
75
96
 
76
97
  # removed the behavior from the actor.
77
98
  def is_no_longer(behavior_sym)
78
- @behaviors.delete behavior_sym
99
+ behavior = @behaviors.delete behavior_sym
100
+ behavior.removed if behavior
79
101
  end
80
102
 
81
103
  # Calls update on all the actor's behaviors.
@@ -87,7 +109,7 @@ class Actor
87
109
 
88
110
  # Creates a new actor and returns it. (This actor will automatically be added to the Director.
89
111
  def spawn(type, args={})
90
- @level.create_actor type, args
112
+ @stage.create_actor type, args
91
113
  end
92
114
 
93
115
  # Plays a sound via the SoundManager. See SoundManager for
@@ -141,5 +163,8 @@ class Actor
141
163
  end
142
164
  @behaviors
143
165
  end
166
+ define_method( :has_behavior ) do |*args|
167
+ has_behaviors *args
168
+ end
144
169
  end
145
170
  end
@@ -1,31 +1,41 @@
1
1
  require 'actor'
2
2
  require 'graphical_actor_view'
3
+
4
+ # ActorFactory is responsible for loading all Actors. It passes along required params such as
5
+ # stage, input_manager, sound_manager, director, resource_manager. It also creates the ActorView
6
+ # associated with the Actor and registers it to the Stage be drawn.
3
7
  class ActorFactory
4
8
  constructor :input_manager, :sound_manager
5
9
 
6
- attr_accessor :mode_manager, :director
10
+ attr_accessor :stage_manager, :director
7
11
 
8
- # returns a hash of actor params
12
+ # Returns a hash of actor params {:model_klass=>k, :view_klass=>v}. This is for performance reasons.
9
13
  def cached_actor_def(actor)
10
14
  @actor_cache ||= {}
11
15
  cached_actor = @actor_cache[actor]
12
16
  return cached_actor if cached_actor
13
17
 
18
+
19
+ model_klass_name = Inflector.camelize actor
14
20
  begin
15
- require actor.to_s
16
- require actor.to_s+"_view"
17
- rescue LoadError => ex
18
- # maybe its included somewhere else
21
+ model_klass = Object.const_get model_klass_name
22
+ rescue NameError
23
+ # not there yet
24
+ begin
25
+ require actor.to_s
26
+ require actor.to_s+"_view"
27
+ rescue LoadError => ex
28
+ # maybe its included somewhere else
29
+ ensure
30
+ model_klass = Object.const_get model_klass_name
31
+ end
19
32
  end
20
- model_klass_name = Inflector.camelize actor
21
- model_klass = Object.const_get model_klass_name
22
33
 
23
34
  begin
24
35
  view_klass = Object.const_get model_klass_name+"View"
25
36
  rescue Exception => ex
26
37
  # hrm...
27
38
  end
28
-
29
39
  actor_def = {
30
40
  :model_klass => model_klass,
31
41
  :view_klass => view_klass
@@ -34,16 +44,16 @@ class ActorFactory
34
44
  actor_def
35
45
  end
36
46
 
37
-
38
- def build(actor, level, opts={})
47
+ # returns the newly created Actor after it and its ActorView has been created.
48
+ def build(actor, stage, opts={})
39
49
  actor_def = cached_actor_def actor
40
50
 
41
51
  basic_opts = {
42
- :level => level,
52
+ :stage => stage,
43
53
  :input => @input_manager,
44
54
  :sound => @sound_manager,
45
55
  :director => @director,
46
- :resources => level.resource_manager
56
+ :resources => stage.resource_manager
47
57
  }
48
58
  merged_opts = basic_opts.merge(opts)
49
59
 
@@ -55,7 +65,8 @@ class ActorFactory
55
65
  if model.is? :animated or model.is? :graphical or model.is? :physical
56
66
  view_klass ||= GraphicalActorView
57
67
  end
58
- view_klass.new @mode_manager.current_mode, model if view_klass
68
+
69
+ view_klass.new stage, model if view_klass
59
70
 
60
71
  model.show unless opts[:hide]
61
72