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
@@ -1,80 +0,0 @@
1
-
2
-
3
- class SpatialStagehand < Stagehand
4
-
5
- DEFAULT_PARAMS = {
6
- :cell_size => 50
7
- }
8
- def setup
9
- merged_opts = DEFAULT_PARAMS.merge opts
10
- @spatial_actors = SpatialHash.new merged_opts[:cell_size]
11
- # TODO
12
- # delegate :items, :cell_size, :to => @spatial_actors
13
- end
14
-
15
- def cell_size
16
- @spatial_actors.cell_size
17
- end
18
-
19
- def cell_size=(new_size)
20
- @spatial_actors.cell_size = new_size
21
- end
22
-
23
- def auto_resize=(val)
24
- @spatial_actors.auto_resize = val
25
- end
26
-
27
- def auto_resize
28
- @spatial_actors.auto_resize
29
- end
30
-
31
- def moved_items
32
- @spatial_actors.moved_items.values
33
- end
34
-
35
- def items
36
- @spatial_actors.items.values
37
- end
38
-
39
- def buckets
40
- @spatial_actors.buckets
41
- end
42
-
43
- def add(actor)
44
- # TODO change these to one event? position_changed?
45
- # item.when :width_changed do |old_w, new_w|
46
- # item.when :height_changed do |old_h, new_h|
47
-
48
- actor.when :x_changed do |old_x, new_x|
49
- move actor
50
- end
51
- actor.when :y_changed do |old_y, new_y|
52
- move actor
53
- end
54
- actor.when :remove_me do
55
- remove actor
56
- end
57
- @spatial_actors.add actor
58
- end
59
-
60
- def remove(actor)
61
- @spatial_actors.remove actor
62
- end
63
-
64
- def move(actor)
65
- @spatial_actors.move actor
66
- end
67
-
68
- def items_at(x,y)
69
- @spatial_actors.items_at x, y
70
- end
71
-
72
- def items_in(x,y,w,h)
73
- @spatial_actors.items_in x, y, w, h
74
- end
75
-
76
- def neighbors_of(item, dist=1)
77
- @spatial_actors.neighbors_of item, dist
78
- end
79
-
80
- end
@@ -1,6 +0,0 @@
1
- source "http://rubygems.org"
2
- gem 'chipmunk'
3
- gem 'require_all'
4
- gem "gamebox"
5
- gem "diy"
6
- gem "rspec"
@@ -1,23 +0,0 @@
1
- APP_ROOT = "#{File.join(File.dirname(__FILE__),"..")}/"
2
-
3
- CONFIG_PATH = APP_ROOT + "config/"
4
- DATA_PATH = APP_ROOT + "data/"
5
- SOUND_PATH = APP_ROOT + "data/sounds/"
6
- MUSIC_PATH = APP_ROOT + "data/music/"
7
- GFX_PATH = APP_ROOT + "data/graphics/"
8
- FONTS_PATH = APP_ROOT + "data/fonts/"
9
-
10
- require 'gamebox'
11
-
12
- [GAMEBOX_PATH, APP_ROOT, File.join(APP_ROOT,'src')].each{|path| $: << path }
13
- require "gamebox_application"
14
-
15
- require_all Dir.glob("**/*.rb").reject{ |f| f.match("spec") || f.match("src/app.rb")}
16
-
17
- GAMEBOX_DATA_PATH = GAMEBOX_PATH + "data/"
18
- GAMEBOX_SOUND_PATH = GAMEBOX_PATH + "data/sounds/"
19
- GAMEBOX_MUSIC_PATH = GAMEBOX_PATH + "data/music/"
20
- GAMEBOX_GFX_PATH = GAMEBOX_PATH + "data/graphics/"
21
- GAMEBOX_FONTS_PATH = GAMEBOX_PATH + "data/fonts/"
22
-
23
- GAME_NAME = "UntitledGame"
@@ -1,2 +0,0 @@
1
- :stages:
2
- - :demo:
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- app_root = File.join(File.dirname(__FILE__),'..')
4
- $: << app_root
5
- $: << File.join(app_root,'config')
6
- require 'environment'
7
- require 'gamebox_generator'
@@ -1,11 +0,0 @@
1
- class DemoStage < Stage
2
- def setup
3
- super
4
- @my_actor = spawn :my_actor, :x => 10, :y => 10
5
- end
6
-
7
- def draw(target)
8
- super
9
- end
10
- end
11
-
@@ -1,19 +0,0 @@
1
- class Game
2
-
3
- constructor :wrapped_screen, :input_manager, :sound_manager,
4
- :stage_manager
5
-
6
- def setup
7
- @stage_manager.change_stage_to :demo
8
- end
9
-
10
- def update(time)
11
- @stage_manager.update time
12
- draw
13
- end
14
-
15
- def draw
16
- @stage_manager.draw @wrapped_screen
17
- end
18
-
19
- end
@@ -1,14 +0,0 @@
1
- class MyActorView < ActorView
2
- def draw(target, x_off, y_off, z)
3
- target.draw_box @actor.x,@actor.y, 20, 20, [240,45,45,255], 1
4
- end
5
- end
6
-
7
- class MyActor < Actor
8
-
9
- def setup
10
- # TODO setup stuff here
11
- # subscribe for an event or something?
12
- end
13
-
14
- end
@@ -1,64 +0,0 @@
1
- require 'bundler'
2
- Bundler.setup
3
-
4
- require 'constructor'
5
- require 'publisher'
6
- require 'gamebox'
7
- require 'benchmark'
8
-
9
- class Arb
10
- include Arbiter
11
- extend Publisher
12
- can_fire_anything
13
-
14
- def initialize(spatial)
15
- @spatial = spatial
16
- on_collision_of :otherthingy, :thingy do |f,b|
17
- puts "collide"
18
- end
19
- end
20
- def stagehand(name)
21
- @spatial
22
- end
23
-
24
- end
25
-
26
- class Shape
27
- extend Publisher
28
- can_fire_anything
29
- attr_accessor :x,:y,:width,:height,:collidable_shape,:radius
30
- def initialize(*args)
31
- @x,@y,@width,@height,@collidable_shape,@radius = *args
32
- end
33
-
34
- def center_x;self.x;end
35
- def center_y;self.y;end
36
- def actor_type;:thingy;end
37
- end
38
-
39
- actor_count = 100
40
- loop_count = 100
41
- obj_size = 40
42
- cell_size = 80
43
-
44
- hash = SpatialHash.new cell_size#, true
45
- arb = Arb.new hash
46
- actor_count.times do |i|
47
- shape = Shape.new(i*20, i*20, obj_size,obj_size,:circle,obj_size)
48
- arb.register_collidable shape
49
- end
50
-
51
- Benchmark.bm(60) do|b|
52
- #30.times do |i|
53
- hash_cell_size = cell_size #+ 5*i
54
- hash.cell_size = hash_cell_size
55
- b.report("#{actor_count} actors w/ size #{obj_size} cell size #{hash_cell_size} for #{loop_count} update loops") do
56
- loop_count.times do
57
- hash.rehash
58
- arb.find_collisions
59
- end
60
- end
61
- end
62
- #end
63
-
64
- puts "hash auto-size:#{hash.cell_size}"
@@ -1,61 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'helper')
2
- describe ActorFactory do
3
- before do
4
- @input_manager = mock
5
- @screen = mock
6
- @stage = mock
7
- @resource_manager = mock
8
- @stage = mock
9
- @stage.stubs(:resource_manager).returns(@resource_manager)
10
- @director = mock
11
- params = {:input_manager => @input_manager, :wrapped_screen => @screen}
12
- @target = ActorFactory.new params
13
- @target.director = @director
14
- @opts = Actor::DEFAULT_PARAMS.merge({:foo => :bar})
15
- @basic_opts = {
16
- :stage => @stage,
17
- :input => @input_manager,
18
- :director => @director,
19
- :resources => @resource_manager,
20
- :wrapped_screen => @screen,
21
- }
22
- @merged_opts = @basic_opts.merge(@opts)
23
-
24
- end
25
-
26
- describe "#build" do
27
- it "creates an Actor instance and registers the view" do
28
-
29
- view_actor = nil
30
- @stage.expects(:register_drawable).with() do |view|
31
- view.class.should == ActorView
32
- view.stage.should == @stage
33
- view.wrapped_screen.should == @screen
34
- view.actor.class.should == Actor
35
- view_actor = view.actor
36
- end
37
- @merged_opts[:actor_type] = :actor
38
-
39
- act = @target.build :actor, @stage, @opts
40
- act.opts.should == @merged_opts
41
- act.class.should == Actor
42
- act.should == view_actor
43
- end
44
-
45
- it "creates an Actor instance with no view" do
46
- @merged_opts[:actor_type] = :no_view_actor
47
-
48
- act = @target.build :no_view_actor, @stage, @opts
49
- act.opts.should == @merged_opts
50
- act.class.should == NoViewActor
51
- end
52
-
53
- it "nil on actor not found" do
54
- lambda{ @target.build :no_actor, @stage, @opts }.should raise_error("no_actor not found")
55
- end
56
-
57
- end
58
-
59
- class NoViewActor < Actor
60
- end
61
- end
data/spec/actor_spec.rb DELETED
@@ -1,71 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'helper')
2
- describe 'A new actor' do
3
- let(:stage) { mock }
4
- subject {
5
- opts = {:stage=>stage, :input=>"input",
6
- :resources=>"resource", :actor_type => :actor}
7
- Actor.new opts
8
- }
9
-
10
- it 'should be alive' do
11
- subject.alive?.should be_true
12
- end
13
-
14
- it 'should be the correct type' do
15
- subject.actor_type.should == :actor
16
- end
17
-
18
- it 'should be at (0,0)' do
19
- subject.x.should equal(0)
20
- subject.y.should equal(0)
21
- end
22
-
23
- it 'should have access to backstage' do
24
- subject.stage = mock(:backstage => :stuff)
25
- subject.backstage.should == :stuff
26
- end
27
-
28
- it 'should have atts set' do
29
- subject.stage.should == stage
30
- subject.input_manager.should == "input"
31
- subject.resource_manager.should == "resource"
32
- subject.behaviors.size.should equal(0)
33
- end
34
-
35
- it 'should fire anything' do
36
- Proc.new {
37
- subject.when :foofoo_bar do
38
- "blah"
39
- end
40
- }.should_not raise_error
41
- end
42
-
43
- it 'should inherit parents behaviors' do
44
- @shawn = Shawn.new {}
45
- @shawn.is?(:smart).should be_true
46
- end
47
-
48
- it 'should be able to override parents behaviors' do
49
- @james = JamesKilton.new {}
50
- @james.is?(:smart).should be_true
51
- @james.instance_variable_get('@behaviors')[:smart].instance_variable_get('@opts').should == {:really=>true}
52
- end
53
-
54
- describe '#viewport' do
55
- it 'should return the stages viewport' do
56
- stage.stubs(:viewport).returns(:da_viewport)
57
- subject.viewport.should == :da_viewport
58
- end
59
- end
60
-
61
- end
62
-
63
- class Cool < Behavior; end
64
- class Smart < Behavior; end
65
- class Coder < Actor
66
- has_behavior :smart, :cool
67
- end
68
- class Shawn < Coder; end
69
- class JamesKilton < Coder
70
- has_behavior :smart => {:really => true}
71
- end
@@ -1,61 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'helper')
2
-
3
-
4
- describe 'A new actor view' do
5
- before do
6
- @actor = mock
7
- @stage = mock
8
- @actor.stubs :when
9
- end
10
-
11
- it 'should be layered 0/1 by default' do
12
- @actor.expects(:is?).with(:layered).returns(false)
13
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
14
- @test_me.layer.should == 0
15
- @test_me.parallax.should == 1
16
- end
17
-
18
- it 'should call setup on creation' do
19
- ActorView.any_instance.expects :setup
20
- @actor.expects(:is?).with(:layered).returns(false)
21
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
22
- end
23
-
24
- it 'should accept layered behavior params from actor' do
25
- @actor.stubs(:layer => 6, :parallax => 3)
26
- @actor.expects(:is?).with(:layered).returns(true)
27
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
28
-
29
- @test_me.layer.should == 6
30
- @test_me.parallax.should == 3
31
- end
32
-
33
- it 'should register for show events' do
34
- @actor = Actor.new({})
35
-
36
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
37
- @stage.expects(:register_drawable).with(@test_me)
38
-
39
- @actor.send :fire, :show_me
40
- end
41
-
42
- it 'should register for hide events' do
43
- @actor = Actor.new({})
44
-
45
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
46
- @stage.expects(:unregister_drawable).with(@test_me)
47
-
48
- @actor.send :fire, :hide_me
49
- end
50
-
51
- it 'should register for remove events' do
52
- @actor = Actor.new({})
53
-
54
- @test_me = ActorView.new @stage, @actor, :wrapped_screen
55
- @stage.expects(:unregister_drawable).with(@test_me)
56
-
57
- @actor.send :fire, :remove_me
58
- end
59
-
60
- it 'should manage a cached surface for drawing (possibly use record{})'
61
- end
@@ -1,83 +0,0 @@
1
- require File.join(File.dirname(__FILE__),'helper')
2
-
3
- describe 'A new animated behavior' do
4
- before do
5
- @rm = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'])
6
- @actor = Actor.new({})
7
- @actor.expects(:is?).with(:updatable).returns(true)
8
- @actor.stubs(:resource_manager).returns(@rm)
9
- @animated = Animated.new @actor
10
- end
11
-
12
- it 'should define methods on actor' do
13
- @actor.respond_to?(:image).should be(true)
14
- @actor.respond_to?(:start_animating).should be(true)
15
- @actor.respond_to?(:stop_animating).should be(true)
16
- @actor.respond_to?(:action=).should be(true)
17
- @actor.respond_to?(:animated).should be(true)
18
- end
19
-
20
- it 'shouldn\'t update frame for non-animating' do
21
- @animated.stop_animating
22
-
23
- @animated.update @animated.frame_update_time+1
24
-
25
- @animated.frame_time.should equal(0)
26
- @animated.frame_num.should equal(0)
27
- end
28
-
29
- it 'should update frame for animating' do
30
- time_passed = @animated.frame_update_time-1
31
- @animated.update time_passed
32
- @animated.frame_time.should equal(time_passed)
33
- @animated.frame_num.should equal(0)
34
-
35
- time_passed_again = 2
36
- @animated.update time_passed_again
37
- # we rolled over the time
38
- @animated.frame_time.should equal(1)
39
- @animated.frame_num.should equal(1)
40
-
41
- time_passed_again = @animated.frame_update_time
42
- @animated.update time_passed_again
43
- # we rolled over the time
44
- @animated.frame_time.should equal(1)
45
- @animated.frame_num.should equal(0)
46
- end
47
-
48
- it 'should stop animating' do
49
- @animated.stop_animating
50
- @animated.animating.should equal(false)
51
- end
52
-
53
- it 'should start animating' do
54
- @animated.start_animating
55
- @animated.animating.should equal(true)
56
- end
57
-
58
- it 'should return itself for animated' do
59
- @animated.animated.should == @animated
60
- end
61
-
62
- it 'should set the action and animate accordingly for single frame' do
63
- @animated.animating = true
64
- @rm.expects(:load_animation_set).with(@actor, :foo).returns([:frame_one])
65
- @animated.action = :foo
66
-
67
- @animated.animating.should be_false
68
- @animated.frame_num.should == 0
69
- @animated.action.should == :foo
70
- end
71
-
72
- it 'should set the action and animate accordingly for many frames' do
73
- @animated.animating = false
74
- @rm.expects(:load_animation_set).with(@actor, :foo).returns([:frame_one, :frame_two])
75
- @animated.action = :foo
76
-
77
- @animated.animating.should be_true
78
- @animated.frame_num.should == 0
79
- @animated.action.should == :foo
80
- end
81
-
82
-
83
- end