gamebox 0.3.4 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/README.rdoc +38 -0
  2. data/Rakefile +1 -10
  3. data/TODO.txt +6 -6
  4. data/app_generators/gamebox_generator.rb +95 -0
  5. data/{lib/gamebox/templates/template_app → app_generators/templates}/.gitignore +0 -0
  6. data/app_generators/templates/Gemfile +7 -0
  7. data/app_generators/templates/NEXT_STEPS.txt +1 -0
  8. data/{lib/gamebox/templates/template_app/README → app_generators/templates/README.rdoc} +0 -0
  9. data/{lib/gamebox/templates/template_app → app_generators/templates}/Rakefile +0 -0
  10. data/{lib/gamebox/templates/template_app → app_generators/templates}/config/boot.rb +0 -0
  11. data/app_generators/templates/config/environment.rb +30 -0
  12. data/{lib/gamebox/templates/template_app → app_generators/templates}/config/game.yml +0 -0
  13. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/fonts/FONTS_GO_HERE +0 -0
  14. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/graphics/GRAPHICS_GO_HERE +0 -0
  15. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/music/MUSIC_GOES_HERE +0 -0
  16. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/sounds/SOUND_FX_GO_HERE +0 -0
  17. data/{lib/gamebox/templates → app_generators/templates/script}/actor.erb +0 -0
  18. data/{lib/gamebox/templates → app_generators/templates/script}/actor_spec.erb +0 -0
  19. data/{lib/gamebox/templates → app_generators/templates/script}/actor_view.erb +0 -0
  20. data/{lib/gamebox/templates → app_generators/templates/script}/actor_view_spec.erb +0 -0
  21. data/app_generators/templates/script/generate +12 -0
  22. data/{lib/gamebox/templates/template_app → app_generators/templates}/spec/helper.rb +0 -0
  23. data/app_generators/templates/src/actors/player.rb +8 -0
  24. data/{lib/gamebox/templates/template_app → app_generators/templates}/src/app.rb +0 -0
  25. data/app_generators/templates/src/demo_stage.rb +7 -0
  26. data/bin/gamebox +8 -70
  27. data/component_generators/actor_generator.rb +17 -0
  28. data/docs/CODE_REVIEW +1 -1
  29. data/docs/REFACTOR_NOTES.txt +25 -0
  30. data/docs/getting_started.rdoc +1 -1
  31. data/gamebox.gemspec +7 -4
  32. data/lib/gamebox.rb +6 -3
  33. data/lib/gamebox/actors/collidable_debugger.rb +13 -15
  34. data/lib/gamebox/actors/curtain.rb +44 -43
  35. data/lib/gamebox/actors/emitter.rb +3 -42
  36. data/lib/gamebox/actors/fps.rb +13 -6
  37. data/lib/gamebox/actors/label.rb +42 -34
  38. data/lib/gamebox/actors/logo.rb +2 -4
  39. data/lib/gamebox/actors/score.rb +37 -27
  40. data/lib/gamebox/actors/svg_actor.rb +45 -32
  41. data/lib/gamebox/behaviors/animated.rb +39 -59
  42. data/lib/gamebox/behaviors/audible.rb +14 -14
  43. data/lib/gamebox/behaviors/collidable.rb +65 -36
  44. data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +2 -3
  45. data/lib/gamebox/behaviors/collidable/collidable_shape.rb +6 -4
  46. data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
  47. data/lib/gamebox/behaviors/emitting.rb +48 -0
  48. data/lib/gamebox/behaviors/graphical.rb +22 -56
  49. data/lib/gamebox/behaviors/layered.rb +8 -21
  50. data/lib/gamebox/behaviors/physical.rb +202 -213
  51. data/lib/gamebox/behaviors/positioned.rb +16 -0
  52. data/lib/gamebox/behaviors/projectile.rb +15 -0
  53. data/lib/gamebox/behaviors/visible.rb +16 -0
  54. data/lib/gamebox/core/aabb_helpers.rb +61 -0
  55. data/lib/gamebox/core/aabb_node.rb +118 -0
  56. data/lib/gamebox/core/aabb_tree.rb +137 -0
  57. data/lib/gamebox/core/actor.rb +102 -0
  58. data/lib/gamebox/core/actor_factory.rb +56 -0
  59. data/lib/gamebox/core/actor_view.rb +63 -0
  60. data/lib/gamebox/core/actor_view_factory.rb +40 -0
  61. data/lib/gamebox/{arbiter.rb → core/arbiter.rb} +31 -34
  62. data/lib/gamebox/{backstage.rb → core/backstage.rb} +0 -0
  63. data/lib/gamebox/core/behavior.rb +64 -0
  64. data/lib/gamebox/core/behavior_factory.rb +56 -0
  65. data/lib/gamebox/{class_finder.rb → core/class_finder.rb} +0 -0
  66. data/lib/gamebox/{config_manager.rb → core/config_manager.rb} +1 -1
  67. data/lib/gamebox/core/configuration.rb +39 -0
  68. data/lib/gamebox/core/core.rb +30 -0
  69. data/lib/gamebox/core/deprecated.rb +15 -0
  70. data/lib/gamebox/{director.rb → core/director.rb} +6 -11
  71. data/lib/gamebox/core/font_style.rb +26 -0
  72. data/lib/gamebox/core/font_style_factory.rb +11 -0
  73. data/lib/gamebox/core/game.rb +19 -0
  74. data/lib/gamebox/{hooked_gosu_window.rb → core/hooked_gosu_window.rb} +12 -6
  75. data/lib/gamebox/{input_manager.rb → core/input_manager.rb} +106 -99
  76. data/lib/gamebox/core/physics.rb +22 -0
  77. data/lib/gamebox/{physical_stage.rb → core/physics_manager.rb} +36 -30
  78. data/lib/gamebox/{resource_manager.rb → core/resource_manager.rb} +19 -18
  79. data/lib/gamebox/{sound_manager.rb → core/sound_manager.rb} +9 -7
  80. data/lib/gamebox/{stage.rb → core/stage.rb} +42 -80
  81. data/lib/gamebox/{stage_manager.rb → core/stage_manager.rb} +46 -53
  82. data/lib/gamebox/{stagehand.rb → core/stagehand.rb} +0 -0
  83. data/lib/gamebox/{svg_document.rb → core/svg_document.rb} +0 -0
  84. data/lib/gamebox/core/timer_manager.rb +50 -0
  85. data/lib/gamebox/{viewport.rb → core/viewport.rb} +2 -3
  86. data/lib/gamebox/{wrapped_screen.rb → core/wrapped_screen.rb} +12 -19
  87. data/lib/gamebox/gamebox_application.rb +7 -15
  88. data/lib/gamebox/lib/evented_attributes.rb +51 -0
  89. data/lib/gamebox/{ftor.rb → lib/ftor.rb} +0 -0
  90. data/lib/gamebox/lib/min_max_helpers.rb +10 -0
  91. data/lib/gamebox/lib/rect.rb +112 -54
  92. data/lib/gamebox/lib/yoda.rb +46 -0
  93. data/lib/gamebox/spec/helper.rb +317 -12
  94. data/lib/gamebox/stagehands/spatial_tree_stagehand.rb +61 -0
  95. data/lib/gamebox/version.rb +8 -3
  96. data/lib/gamebox/views/graphical_actor_view.rb +22 -29
  97. data/script/perf_aabb.rb +56 -0
  98. data/script/perf_array_access.rb +16 -0
  99. data/script/perf_collisions.rb +37 -18
  100. data/script/perf_struct_vs_array.rb +7 -7
  101. data/spec/acceptance/animation_spec.rb +65 -0
  102. data/spec/acceptance/basic_actor_lifecycle_spec.rb +92 -0
  103. data/spec/acceptance/built_in_collision_handling_spec.rb +55 -0
  104. data/spec/acceptance/chipmunk_collision_handling_spec.rb +83 -0
  105. data/spec/acceptance/fps_actor_spec.rb +40 -0
  106. data/spec/acceptance/pausing_spec.rb +61 -0
  107. data/spec/acceptance/timer_usage_spec.rb +53 -0
  108. data/spec/actors/emitter_spec.rb +5 -0
  109. data/spec/{label_spec.rb → actors/label_spec.rb} +1 -1
  110. data/spec/behaviors/animated_spec.rb +85 -0
  111. data/spec/behaviors/collidable_spec.rb +134 -0
  112. data/spec/{physical_spec.rb → behaviors/physical_spec.rb} +2 -1
  113. data/spec/behaviors/positioned_spec.rb +6 -0
  114. data/spec/behaviors/projectile_spec.rb +6 -0
  115. data/spec/core/aabb_tree_spec.rb +109 -0
  116. data/spec/core/actor_factory_spec.rb +44 -0
  117. data/spec/core/actor_spec.rb +78 -0
  118. data/spec/core/actor_view_spec.rb +53 -0
  119. data/spec/{arbiter_spec.rb → core/arbiter_spec.rb} +29 -30
  120. data/spec/core/backstage_spec.rb +37 -0
  121. data/spec/core/behavior_factory_spec.rb +50 -0
  122. data/spec/core/behavior_spec.rb +8 -0
  123. data/spec/core/configuration_spec.rb +8 -0
  124. data/spec/core/core_spec.rb +13 -0
  125. data/spec/core/font_style_factory_spec.rb +17 -0
  126. data/spec/core/font_style_spec.rb +41 -0
  127. data/spec/core/hooked_gosu_window_spec.rb +75 -0
  128. data/spec/core/input_manager_spec.rb +285 -0
  129. data/spec/core/physics_manager_spec.rb +11 -0
  130. data/spec/core/resource_manager_spec.rb +12 -0
  131. data/spec/core/stage_manager_spec.rb +140 -0
  132. data/spec/core/stage_spec.rb +73 -0
  133. data/spec/core/timer_manager_spec.rb +89 -0
  134. data/spec/{viewport_spec.rb → core/viewport_spec.rb} +6 -3
  135. data/spec/core/wrapped_screen_spec.rb +26 -0
  136. data/spec/fixtures/game.yml +7 -0
  137. data/spec/fixtures/snelpling/idle/1.png +0 -0
  138. data/spec/fixtures/snelpling/jump/1.png +0 -0
  139. data/spec/fixtures/snelpling/jump/2.png +0 -0
  140. data/spec/fixtures/snelpling/jump/3.png +0 -0
  141. data/spec/helper.rb +8 -0
  142. data/spec/{class_finder_spec.rb → lib/class_finder_spec.rb} +2 -1
  143. data/spec/stagehands/spatial_tree_stagehand_spec.rb +19 -0
  144. data/spec/views/graphical_actor_view_spec.rb +116 -0
  145. metadata +343 -144
  146. data/README.txt +0 -34
  147. data/lib/gamebox/actor.rb +0 -179
  148. data/lib/gamebox/actor_factory.rb +0 -57
  149. data/lib/gamebox/actor_view.rb +0 -44
  150. data/lib/gamebox/actors/spatial_debugger.rb +0 -62
  151. data/lib/gamebox/behavior.rb +0 -70
  152. data/lib/gamebox/behaviors/timed.rb +0 -33
  153. data/lib/gamebox/behaviors/updatable.rb +0 -12
  154. data/lib/gamebox/console_app.rb +0 -41
  155. data/lib/gamebox/gamebox_generator.rb +0 -32
  156. data/lib/gamebox/generators/actor_generator.rb +0 -43
  157. data/lib/gamebox/generators/view_generator.rb +0 -42
  158. data/lib/gamebox/physical_director.rb +0 -17
  159. data/lib/gamebox/physics.rb +0 -32
  160. data/lib/gamebox/spatial_bucket.rb +0 -9
  161. data/lib/gamebox/spatial_hash.rb +0 -194
  162. data/lib/gamebox/spatial_stagehand.rb +0 -80
  163. data/lib/gamebox/templates/template_app/Gemfile +0 -6
  164. data/lib/gamebox/templates/template_app/config/environment.rb +0 -23
  165. data/lib/gamebox/templates/template_app/config/stage_config.yml +0 -2
  166. data/lib/gamebox/templates/template_app/script/generate +0 -7
  167. data/lib/gamebox/templates/template_app/src/demo_stage.rb +0 -11
  168. data/lib/gamebox/templates/template_app/src/game.rb +0 -19
  169. data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -14
  170. data/script/perf_spatial_hash.rb +0 -64
  171. data/spec/actor_factory_spec.rb +0 -61
  172. data/spec/actor_spec.rb +0 -71
  173. data/spec/actor_view_spec.rb +0 -61
  174. data/spec/animated_spec.rb +0 -83
  175. data/spec/backstage_spec.rb +0 -45
  176. data/spec/behavior_spec.rb +0 -28
  177. data/spec/collidable_spec.rb +0 -135
  178. data/spec/emitter_spec.rb +0 -20
  179. data/spec/input_manager_spec.rb +0 -134
  180. data/spec/resource_manager_spec.rb +0 -13
  181. data/spec/spatial_hash_spec.rb +0 -119
  182. data/spec/spatial_stagehand_spec.rb +0 -93
  183. data/spec/stage_manager_spec.rb +0 -25
  184. data/spec/stage_spec.rb +0 -65
data/README.txt DELETED
@@ -1,34 +0,0 @@
1
- = gamebox
2
-
3
- * http://shawn42.github.com/gamebox/
4
-
5
- == DESCRIPTION:
6
-
7
- A game template for building and distributing Gosu games. See docs/getting_started.rdoc for help getting started.
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- * Quickly generate a game and have it up and running.
12
-
13
- == SYNOPSIS:
14
-
15
- A game template for building and distributing Gosu games.
16
-
17
- == REQUIREMENTS:
18
-
19
- * Gosu
20
- * constructor gem
21
- * publisher gem
22
- * bundler
23
- * rspec (for gamebox tests)
24
- * algorithms gem (optional for line of site and A*)
25
-
26
- == INSTALL:
27
-
28
- * gem install gamebox; gamebox my_cool_game
29
-
30
- == LICENSE:
31
-
32
- (MIT)
33
-
34
- Copyright (c) 2009 Shawn Anderson
data/lib/gamebox/actor.rb DELETED
@@ -1,179 +0,0 @@
1
- # Actor represent a game object.
2
- # Actors can have behaviors added and removed from them. Such as :physical or :animated.
3
- # They are created and hooked up to their optional View class in Stage#create_actor.
4
- class Actor
5
- include Kvo
6
-
7
- attr_accessor :behaviors, :stage, :input_manager,
8
- :resource_manager, :alive, :opts, :visible, :director,
9
- :wrapped_screen,
10
- :actor_type
11
-
12
- # TODO change alive and visible to be KVO
13
- kvo_attr_accessor :x, :y, :alive, :visible
14
-
15
- can_fire_anything
16
-
17
- DEFAULT_PARAMS = {
18
- :x => 0,
19
- :y => 0,
20
- }.freeze
21
-
22
- def initialize(opts={}) # :nodoc:
23
- @opts = DEFAULT_PARAMS.merge opts
24
- self.x = @opts[:x]
25
- self.y = @opts[:y]
26
-
27
- @stage = @opts[:stage]
28
- @input_manager = @opts[:input]
29
- @resource_manager = @opts[:resources]
30
- @director = @opts[:director]
31
- @actor_type = @opts[:actor_type]
32
- @wrapped_screen = @opts[:wrapped_screen]
33
- self.alive = true
34
-
35
- @behaviors = {}
36
-
37
- # add our classes behaviors and parents behaviors
38
- klass = self.class
39
- actor_klasses = []
40
- while klass != Actor
41
- actor_klasses << klass
42
- klass = klass.superclass
43
- end
44
-
45
- behavior_defs = {}
46
- ordered_behaviors = []
47
-
48
- actor_klasses.reverse.each do |actor_klass|
49
- actor_behaviors = actor_klass.behaviors.dup
50
- actor_behaviors.each do |behavior|
51
-
52
- behavior_sym = behavior.is_a?(Hash) ? behavior.keys.first : behavior
53
-
54
- ordered_behaviors << behavior_sym unless ordered_behaviors.include? behavior_sym
55
- behavior_defs[behavior_sym] = behavior
56
- end
57
- end
58
-
59
- ordered_behaviors.each do |behavior|
60
- is behavior_defs[behavior] unless is? behavior
61
- end
62
- setup
63
- end
64
-
65
- # Called at the end of actor/behavior initialization. To be defined by the
66
- # child class.
67
- def setup
68
- end
69
-
70
- # Is the actor still alive?
71
- def alive?
72
- self.alive
73
- end
74
-
75
- def screen
76
- @wrapped_screen
77
- end
78
-
79
- # Tells the actor's Director that he wants to be removed; and unsubscribes
80
- # the actor from all input events.
81
- def remove_self
82
- self.alive = false
83
- fire :remove_me
84
- @input_manager.unsubscribe_all self
85
- end
86
-
87
- # Does this actor have this behavior?
88
- def is?(behavior_sym)
89
- !@behaviors[behavior_sym].nil?
90
- end
91
-
92
- # Adds the given behavior to the actor. Takes a symbol or a Hash.
93
- # act.is(:shootable) or act.is(:shootable => {:range=>3})
94
- # this will create a new instance of Shootable and pass
95
- # :range=>3 to it
96
- # Actor#is does try to require 'shootable' but will not throw an error if shootable cannot be required.
97
- def is(behavior_def)
98
- if behavior_def.is_a?(Hash)
99
- behavior_sym = behavior_def.keys.first
100
- behavior_opts = behavior_def.values.first
101
- else
102
- behavior_sym = behavior_def
103
- behavior_opts = {}
104
- end
105
- klass = Object.const_get Inflector.camelize(behavior_sym)
106
- @behaviors[behavior_sym] = klass.new self, behavior_opts
107
- end
108
-
109
- # removed the behavior from the actor.
110
- def is_no_longer(behavior_sym)
111
- behavior = @behaviors.delete behavior_sym
112
- behavior.removed if behavior
113
- end
114
-
115
- # Calls update on all the actor's behaviors.
116
- def update_behaviors(time)
117
- for behavior in @behaviors.values
118
- behavior.update time
119
- end
120
- end
121
-
122
- # Creates a new actor and returns it. (This actor will automatically be added to the Director.
123
- def spawn(type, args={})
124
- @stage.spawn type, args
125
- end
126
-
127
- # Access to backstage for storage
128
- def backstage
129
- @stage.backstage
130
- end
131
-
132
- # to be defined in child class
133
- def update(time)
134
- # TODO maybe use a callback list for child classes
135
- update_behaviors time
136
- end
137
-
138
- def hide
139
- fire :hide_me if visible?
140
- self.visible = false
141
- end
142
-
143
- def show
144
- fire :show_me unless visible?
145
- self.visible = true
146
- end
147
-
148
- def visible?
149
- self.visible
150
- end
151
-
152
- def viewport
153
- @stage.viewport
154
- end
155
-
156
- def self.behaviors
157
- @behaviors ||= []
158
- end
159
-
160
- def self.has_behaviors(*args)
161
- @behaviors ||= []
162
- for a in args
163
- if a.is_a? Hash
164
- for k,v in a
165
- h = {}
166
- h[k]=v
167
- @behaviors << h
168
- end
169
- else
170
- @behaviors << a
171
- end
172
- end
173
- @behaviors
174
- end
175
-
176
- def self.has_behavior(*args)
177
- has_behaviors *args
178
- end
179
- end
@@ -1,57 +0,0 @@
1
-
2
- # ActorFactory is responsible for loading all Actors. It passes along required params such as
3
- # stage, input_manager, director, resource_manager. It also creates the ActorView
4
- # associated with the Actor and registers it to the Stage be drawn.
5
- class ActorFactory
6
- constructor :input_manager, :wrapped_screen
7
-
8
- attr_accessor :stage_manager, :director
9
-
10
- # Returns a hash of actor params {:model_klass=>k, :view_klass=>v}. This is for performance reasons.
11
- def cached_actor_def(actor)
12
- @actor_cache ||= {}
13
- cached_actor = @actor_cache[actor]
14
- return cached_actor if cached_actor
15
-
16
- model_klass = ClassFinder.find(actor)
17
- raise "#{actor} not found" unless model_klass
18
-
19
- view_klass = ClassFinder.find("#{actor}_view")
20
-
21
- actor_def = {
22
- :model_klass => model_klass,
23
- :view_klass => view_klass
24
- }
25
- @actor_cache[actor] = actor_def
26
- actor_def
27
- end
28
-
29
- # returns the newly created Actor after it and its ActorView has been created.
30
- def build(actor, stage, opts={})
31
- actor_def = cached_actor_def actor
32
-
33
- basic_opts = {
34
- :stage => stage,
35
- :input => @input_manager,
36
- :director => @director,
37
- :resources => stage.resource_manager,
38
- :actor_type => actor,
39
- :wrapped_screen => @wrapped_screen
40
- }
41
- merged_opts = basic_opts.merge(opts)
42
- model = actor_def[:model_klass].new merged_opts
43
-
44
- view_klass = opts[:view]
45
- view_klass ||= actor_def[:view_klass]
46
-
47
- if model.is? :animated or model.is? :graphical or model.is? :physical
48
- view_klass ||= GraphicalActorView
49
- end
50
-
51
- view_klass.new stage, model, @wrapped_screen if view_klass
52
-
53
- model.show unless opts[:hide]
54
-
55
- return model
56
- end
57
- end
@@ -1,44 +0,0 @@
1
- class ActorView
2
- attr_accessor :actor, :stage, :layer, :parallax, :wrapped_screen
3
- def initialize(stage, actor, wrapped_screen)
4
- @stage = stage
5
- @actor = actor
6
- @wrapped_screen = wrapped_screen
7
-
8
- @layer = 0
9
- @parallax = 1
10
- if @actor.is? :layered
11
- @layer = @actor.layer
12
- @parallax = @actor.parallax
13
- end
14
-
15
- actor.when :remove_me do unregister end
16
-
17
- actor.when :hide_me do unregister end
18
-
19
- actor.when :show_me do register end
20
-
21
- setup
22
- end
23
-
24
- def register
25
- @stage.register_drawable self
26
- end
27
-
28
- def unregister
29
- @stage.unregister_drawable self
30
- end
31
-
32
- def setup
33
- end
34
-
35
- def screen_width
36
- @screen_width ||= @wrapped_screen.width
37
- end
38
-
39
- def screen_height
40
- @screen_height ||= @wrapped_screen.height
41
- end
42
-
43
- end
44
-
@@ -1,62 +0,0 @@
1
-
2
-
3
-
4
- class SpatialDebugger < Actor
5
-
6
- has_behavior :updatable
7
-
8
- attr_reader :spatial, :ratio
9
- def setup
10
- @spatial = stage.stagehand(:spatial)
11
- end
12
-
13
- def update(time)
14
- super
15
- if stage.checks && stage.checks > 0
16
- @ratio = "size:#{@spatial.cell_size} #{stage.collisions} / #{stage.checks} ("
17
- @ratio += "#{stage.collisions / stage.checks.to_f})"
18
- else
19
- @ratio = "N/A"
20
- end
21
- end
22
-
23
- end
24
-
25
- class SpatialDebuggerView < ActorView
26
- def setup
27
- # size = 30
28
- # font = "Asimov.ttf"
29
- # @font = @actor.resource_manager.load_font font, size
30
- end
31
-
32
- def draw(target,x_off,y_off, z)
33
- vp = stage.viewport
34
- cell_size = @actor.spatial.cell_size
35
- max = 0
36
- @actor.spatial.buckets.each do |x_bucket,stuff|
37
- stuff.each do |y_bucket,items|
38
- # max = items.size if items.size > max
39
- x = x_bucket * cell_size + x_off
40
- y = y_bucket * cell_size + y_off
41
- target.draw_box x, y, x+cell_size, y+cell_size, [255,25,25], z
42
-
43
- # Yes I know I may be drawing this many times for an actor
44
- items.each do |item|
45
- # puts "#{item.class}: [#{item.center_x}, #{item.center_y}] #{item.collidable_shape}"
46
- parallax = 1
47
- ix = item.center_x + x_off
48
- iy = item.center_y + y_off
49
-
50
- target.draw_box ix, iy, ix + 2, iy + 2, [255,255,255], 10
51
-
52
- # TODO make work for non circles
53
- r = item.radius
54
- target.draw_box ix-r, iy-r, ix + r, iy + r, [255,255,255], 10
55
- end
56
- end
57
- end
58
-
59
- # @text_image = @font.render "#{@actor.ratio} [#{max}]", true, Color[:white]
60
- # @text_image.blit target.screen, [@actor.x, @actor.y]
61
- end
62
- end
@@ -1,70 +0,0 @@
1
- # Behavior is any type of behavior an actor can exibit.
2
- class Behavior
3
- attr_accessor :actor, :opts, :relegated_methods
4
-
5
- def initialize(actor,opts={})
6
- @actor = actor
7
- @opts = opts
8
- @relegated_methods = []
9
-
10
- req_behs = self.class.required_behaviors
11
- req_behs.each do |beh|
12
- unless @actor.is? beh
13
- @actor.is beh
14
- end
15
- end
16
- setup
17
- end
18
-
19
- def setup
20
- end
21
-
22
- def removed
23
- target = self
24
-
25
- @actor.instance_eval do
26
- (class << self; self; end).class_eval do
27
- target.relegated_methods.each do |meth|
28
- remove_method meth
29
- end
30
- end
31
- end
32
- end
33
-
34
- def update(time)
35
- end
36
-
37
- def self.required_behaviors
38
- @required_behaviors ||= []
39
- end
40
-
41
- def self.requires_behaviors(*args)
42
- @required_behaviors ||= []
43
- for a in args
44
- @required_behaviors << a
45
- end
46
- @behaviors
47
- end
48
-
49
- def self.requires_behavior(*args)
50
- requires_behaviors(*args)
51
- end
52
-
53
- def relegates(*methods)
54
- target = self
55
-
56
- @actor.instance_eval do
57
- (class << self; self; end).class_eval do
58
- methods.each do |meth|
59
- # log("redefining #{meth} for #{@actor.class}") if @actor.respond_to? meth
60
- target.relegated_methods << meth
61
-
62
- define_method meth do |*args, &block|
63
- target.send meth, *args, &block
64
- end
65
- end
66
- end
67
- end
68
- end
69
-
70
- end