gamebox 0.2.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. data/Gemfile +1 -8
  2. data/Rakefile +13 -37
  3. data/TODO.txt +27 -27
  4. data/docs/getting_started.rdoc +2 -2
  5. data/gamebox.gemspec +33 -191
  6. data/lib/gamebox.rb +18 -14
  7. data/lib/gamebox/actor.rb +37 -27
  8. data/lib/gamebox/actor_factory.rb +4 -5
  9. data/lib/gamebox/actor_view.rb +8 -0
  10. data/lib/gamebox/actors/collidable_debugger.rb +2 -2
  11. data/lib/gamebox/actors/curtain.rb +3 -3
  12. data/lib/gamebox/actors/emitter.rb +51 -0
  13. data/lib/gamebox/actors/label.rb +27 -7
  14. data/lib/gamebox/actors/logo.rb +1 -1
  15. data/lib/gamebox/actors/spatial_debugger.rb +25 -10
  16. data/lib/gamebox/arbiter.rb +61 -34
  17. data/lib/gamebox/behavior.rb +3 -3
  18. data/lib/gamebox/behaviors/animated.rb +1 -1
  19. data/lib/gamebox/behaviors/audible.rb +1 -1
  20. data/lib/gamebox/behaviors/collidable.rb +9 -4
  21. data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +26 -1
  22. data/lib/gamebox/behaviors/collidable/circle_collidable.rb +3 -3
  23. data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
  24. data/lib/gamebox/behaviors/graphical.rb +30 -4
  25. data/lib/gamebox/behaviors/layered.rb +1 -1
  26. data/lib/gamebox/behaviors/physical.rb +113 -30
  27. data/lib/gamebox/behaviors/timed.rb +33 -0
  28. data/lib/gamebox/behaviors/updatable.rb +1 -1
  29. data/lib/gamebox/class_finder.rb +1 -21
  30. data/lib/gamebox/console_app.rb +33 -31
  31. data/lib/gamebox/constants.rb +481 -0
  32. data/lib/gamebox/data/config/objects.yml +7 -0
  33. data/lib/gamebox/gamebox_application.rb +10 -33
  34. data/lib/gamebox/gamebox_generator.rb +32 -32
  35. data/lib/gamebox/input_manager.rb +73 -32
  36. data/lib/gamebox/lib/inflector.rb +1 -1
  37. data/lib/gamebox/lib/range_ext.rb +5 -0
  38. data/lib/gamebox/lib/rect.rb +548 -548
  39. data/lib/gamebox/lib/sorted_list.rb +1 -1
  40. data/lib/gamebox/lib/symbol_ext.rb +8 -0
  41. data/lib/gamebox/physical_director.rb +1 -1
  42. data/lib/gamebox/physical_stage.rb +3 -3
  43. data/lib/gamebox/physics.rb +0 -3
  44. data/lib/gamebox/resource_manager.rb +22 -17
  45. data/lib/gamebox/sound_manager.rb +3 -2
  46. data/lib/gamebox/spatial_hash.rb +60 -31
  47. data/lib/gamebox/spatial_stagehand.rb +30 -6
  48. data/lib/gamebox/spec/helper.rb +7 -7
  49. data/lib/gamebox/stage.rb +18 -19
  50. data/lib/gamebox/stage_manager.rb +33 -23
  51. data/lib/gamebox/stagehand.rb +3 -0
  52. data/lib/gamebox/svg_document.rb +1 -1
  53. data/lib/gamebox/tasks/gamebox_tasks.rake +133 -0
  54. data/lib/gamebox/templates/actor.erb +0 -2
  55. data/lib/gamebox/templates/actor_view.erb +1 -3
  56. data/lib/gamebox/templates/template_app/Gemfile +3 -2
  57. data/lib/gamebox/templates/template_app/Rakefile +3 -8
  58. data/lib/gamebox/templates/template_app/config/environment.rb +7 -39
  59. data/lib/gamebox/templates/template_app/src/demo_stage.rb +1 -2
  60. data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -3
  61. data/lib/gamebox/version.rb +2 -2
  62. data/lib/gamebox/viewport.rb +44 -8
  63. data/lib/gamebox/views/graphical_actor_view.rb +22 -16
  64. data/lib/gamebox/wrapped_screen.rb +9 -1
  65. data/script/perf_spatial_hash.rb +49 -58
  66. data/script/perf_struct_vs_array.rb +32 -0
  67. data/spec/actor_factory_spec.rb +61 -0
  68. data/spec/actor_spec.rb +24 -18
  69. data/spec/actor_view_spec.rb +51 -6
  70. data/spec/animated_spec.rb +27 -6
  71. data/spec/arbiter_spec.rb +12 -24
  72. data/spec/backstage_spec.rb +1 -1
  73. data/spec/behavior_spec.rb +3 -3
  74. data/spec/class_finder_spec.rb +13 -0
  75. data/spec/collidable_spec.rb +30 -10
  76. data/spec/emitter_spec.rb +20 -0
  77. data/spec/helper.rb +5 -21
  78. data/spec/input_manager_spec.rb +134 -0
  79. data/spec/label_spec.rb +0 -1
  80. data/spec/physical_spec.rb +114 -5
  81. data/spec/resource_manager_spec.rb +1 -2
  82. data/spec/spatial_hash_spec.rb +23 -7
  83. data/spec/spatial_stagehand_spec.rb +97 -0
  84. data/spec/stage_manager_spec.rb +0 -1
  85. data/spec/stage_spec.rb +2 -2
  86. data/spec/viewport_spec.rb +92 -48
  87. metadata +223 -119
  88. data/.gitignore +0 -11
  89. data/History.txt +0 -80
  90. data/VERSION +0 -1
  91. data/lib/gamebox/event_compat.rb +0 -285
  92. data/lib/gamebox/lib/diy.rb +0 -371
  93. data/lib/gamebox/lib/numbers_ext.rb +0 -3
  94. data/lib/gamebox/tasks/gamebox_tasks.rb +0 -61
  95. data/load_paths.rb +0 -20
@@ -1,13 +1,11 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'animated'
3
2
 
4
3
  describe 'A new animated behavior' do
5
4
  before do
6
5
  @rm = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'])
7
-
8
- opts = {:stage=>"stage", :input=>"input", :resources=>@rm}
9
- @actor = Actor.new opts
10
- @actor.should_receive(:is?).with(:updatable).and_return(true)
6
+ @actor = Actor.new({})
7
+ @actor.expects(:is?).with(:updatable).returns(true)
8
+ @actor.stubs(:resource_manager).returns(@rm)
11
9
  @animated = Animated.new @actor
12
10
  end
13
11
 
@@ -56,7 +54,30 @@ describe 'A new animated behavior' do
56
54
  @animated.start_animating
57
55
  @animated.animating.should equal(true)
58
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
59
81
 
60
- it 'should set the action and animate accordingly'
61
82
 
62
83
  end
data/spec/arbiter_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'arbiter'
2
+
3
3
 
4
4
  class Arb
5
5
  include Arbiter
@@ -15,39 +15,27 @@ describe 'Arbiter' do
15
15
  @arbiter.should_not be_nil
16
16
  end
17
17
 
18
- describe '#center_x' do
19
- it 'should return the center x for circle'
20
- it 'should return the center x for aabb'
21
- it 'should return the center x for polygon'
22
- end
23
-
24
- describe '#center_y' do
25
- it 'should return the center y for circle'
26
- it 'should return the center y for aabb'
27
- it 'should return the center y for polygon'
28
- end
29
-
30
18
  describe '#collide?' do
31
19
  it 'should call the correct circle circle collision method' do
32
- a = stub(:collidable_shape => :circle)
33
- b = stub(:collidable_shape => :circle)
34
- @arbiter.should_receive(:collide_circle_circle?).with(a,b).and_return(true)
20
+ a = stub(:collidable_shape => :circle, :is? => true)
21
+ b = stub(:collidable_shape => :circle, :is? => true)
22
+ @arbiter.expects(:collide_circle_circle?).with(a,b).returns(true)
35
23
 
36
24
  @arbiter.collide?(a,b).should be_true
37
25
  end
38
26
 
39
- it 'should call the correct circle polygon collision method' do
40
- a = stub(:collidable_shape => :circle)
41
- b = stub(:collidable_shape => :polygon)
42
- @arbiter.should_receive(:collide_circle_polygon?).with(a,b).and_return(true)
27
+ it 'should call the correct circle polygon collis?ion method' do
28
+ a = stub(:collidable_shape => :circle, :is? => true)
29
+ b = stub(:collidable_shape => :polygon, :is? => true)
30
+ @arbiter.expects(:collide_circle_polygon?).with(a,b).returns(true)
43
31
 
44
32
  @arbiter.collide?(a,b).should be_true
45
33
  end
46
34
 
47
- it 'should call the correct polygon circle collision method' do
48
- a = stub(:collidable_shape => :polygon)
49
- b = stub(:collidable_shape => :circle)
50
- @arbiter.should_receive(:collide_circle_polygon?).with(b,a).and_return(true)
35
+ it 'should call the correct polygon circle collis?ion method' do
36
+ a = stub(:collidable_shape => :polygon, :is? => true)
37
+ b = stub(:collidable_shape => :circle, :is? => true)
38
+ @arbiter.expects(:collide_circle_polygon?).with(b,a).returns(true)
51
39
 
52
40
  @arbiter.collide?(a,b).should be_true
53
41
  end
@@ -1,5 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'backstage'
2
+
3
3
 
4
4
  describe 'A new backstage' do
5
5
 
@@ -1,5 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'behavior'
2
+
3
3
 
4
4
  describe 'A new behavior' do
5
5
  before do
@@ -9,14 +9,14 @@ describe 'A new behavior' do
9
9
 
10
10
  it 'should auto-require behaviors that it depends on'
11
11
  it 'should relegate properly' do
12
- @target.should_receive(:foo).and_return(:bar)
12
+ @target.expects(:foo).returns(:bar)
13
13
  @target.relegates :foo
14
14
 
15
15
  @actor.foo.should == :bar
16
16
  end
17
17
 
18
18
  it 'should un-relegate properly' do
19
- @target.should_receive(:foo).and_return(:bar)
19
+ @target.expects(:foo).returns(:bar)
20
20
  @target.relegates :foo
21
21
  @actor.foo.should == :bar
22
22
 
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__),'helper')
2
+ describe ClassFinder do
3
+ describe "::find" do
4
+ it "finds inflected classname" do
5
+ ClassFinder.find(:class_finder).should == ClassFinder
6
+ end
7
+
8
+ it "returns nil if not found" do
9
+ ClassFinder.find(:klass_not_found).should be_nil
10
+ end
11
+ end
12
+
13
+ end
@@ -1,14 +1,34 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'collidable'
2
+
3
+ class SizedActor < Actor
4
+ def width;12;end
5
+ def height;10;end
6
+ end
3
7
 
4
8
  describe 'A new collidable behavior' do
5
9
  before do
6
- @stage = mock(:register_collidable => nil)
10
+ @stage = stub(:register_collidable => nil)
7
11
  @actor_opts = {:actor_type => :actor, :stage=>@stage, :input=>"input", :resources=> :rm}
8
12
  @actor = Actor.new @actor_opts
9
13
  end
10
14
 
11
15
 
16
+ describe "aabb shape" do
17
+ before do
18
+ @behavior_opts = {:shape => :aabb,
19
+ :cw_world_points => [
20
+ [-15,10],[15,10],
21
+ [15,-10], [-15,10]
22
+ ]}
23
+ @actor = SizedActor.new @actor_opts
24
+ @collidable = Collidable.new @actor, @behavior_opts
25
+ end
26
+
27
+ it "constructs based on points" do
28
+ @collidable.collidable_shape.should == :aabb
29
+ end
30
+ end
31
+
12
32
  describe "circle shape" do
13
33
  before do
14
34
  @behavior_opts = {:shape => :circle}
@@ -16,17 +36,17 @@ describe 'A new collidable behavior' do
16
36
  end
17
37
 
18
38
  it 'should recalculate_collidable_cache on update' do
19
- @collidable.shape.should_receive(:recalculate_collidable_cache)
39
+ @collidable.shape.expects(:recalculate_collidable_cache)
20
40
  @collidable.update 4
21
41
  end
22
42
 
23
43
  it 'should relegate methods on actor' do
24
- @collidable.should_receive(:width).and_return(44)
44
+ @collidable.expects(:width).returns(44)
25
45
  @actor.width.should == 44
26
- @collidable.should_receive(:height).and_return(45)
46
+ @collidable.expects(:height).returns(45)
27
47
  @actor.height.should == 45
28
48
 
29
- @collidable.should_receive(:collidable_shape).and_return(:circlez)
49
+ @collidable.expects(:collidable_shape).returns(:circlez)
30
50
  @actor.collidable_shape.should == :circlez
31
51
  end
32
52
 
@@ -34,16 +54,16 @@ describe 'A new collidable behavior' do
34
54
  @actor.x = 3
35
55
  @actor.y = 6
36
56
  @collidable = Collidable.new @actor, :shape => :circle, :radius => 20
37
- @collidable.center_x.should be_close(23, 0.001)
38
- @collidable.center_y.should be_close(26, 0.001)
57
+ @collidable.center_x.should be_within(0.001).of(3)
58
+ @collidable.center_y.should be_within(0.001).of(6)
39
59
  end
40
60
  end
41
61
 
42
62
  describe "polygon shape" do
43
63
  it 'should calculate center point for polygon' do
44
64
  @collidable = Collidable.new @actor, :shape => :polygon, :points => [[0,0],[10,7],[20,10]]
45
- @collidable.center_x.should be_close(10, 0.001)
46
- @collidable.center_y.should be_close(5, 0.001)
65
+ @collidable.center_x.should be_within(0.001).of(10)
66
+ @collidable.center_y.should be_within(0.001).of(5)
47
67
  end
48
68
 
49
69
  it 'should translate points to world coords for poly' do
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ describe Emitter do
4
+ before do
5
+ @stage = stub_everything
6
+ # @stage.expects(:sound_manager)
7
+ # @stage.expects(:respond_to?).with(:register_physical_object).returns(true)
8
+ # @stage.expects(:register_physical_object).with(any_args)
9
+
10
+ @emitter = create_actor :emitter, {:stage => @stage}
11
+ end
12
+
13
+ it 'should be' do
14
+ @emitter.should be
15
+ end
16
+
17
+ it 'should add a timer for spawning particle actors' do
18
+ end
19
+
20
+ end
data/spec/helper.rb CHANGED
@@ -1,25 +1,9 @@
1
1
  here = File.dirname(__FILE__)
2
2
  gamebox_root = File.expand_path(File.join(here, '..', 'lib'))
3
3
 
4
- #$LOAD_PATH.unshift File.expand_path(gamebox_root, 'gamebox')
5
- require File.expand_path(File.join(here, '..', 'load_paths'))
6
- require 'spec'
7
-
8
- # TODO this lives in both gamebox.rb and here... seems strange
9
- [
10
- "gamebox",
11
- "gamebox/actors",
12
- "gamebox/ai",
13
- "gamebox/behaviors",
14
- "gamebox/generators",
15
- "gamebox/lib",
16
- "gamebox/tasks",
17
- "gamebox/views"
18
- ].each do |path|
19
- $LOAD_PATH.unshift File.join(gamebox_root,path)
4
+ require 'pry'
5
+ require File.join(File.dirname(__FILE__),'..', 'lib', 'gamebox')
6
+ require File.join(File.dirname(__FILE__),'..', 'lib', 'gamebox', 'spec', 'helper')
7
+ RSpec.configure do |config|
8
+ config.mock_with :mocha
20
9
  end
21
-
22
- require 'metaclass'
23
- require 'constructor'
24
- require 'actor'
25
-
@@ -0,0 +1,134 @@
1
+ require File.join(File.dirname(__FILE__),'helper')
2
+
3
+ describe InputManager do
4
+ before do
5
+ @config = stub(:[] => nil)
6
+ @window = mock
7
+ @wrapped_screen = stub(:screen => @window)
8
+ end
9
+ let(:subject) { InputManager.new :config_manager => @config, :wrapped_screen => @wrapped_screen }
10
+
11
+ describe "mouse drag event" do
12
+ it "should fire after a mouse down, mouse motion, mouse up" do
13
+ from_x = 40
14
+ from_y = 20
15
+ to_x = 140
16
+ to_y = 120
17
+ @window.stubs(:mouse_x).returns(from_x)
18
+ @window.stubs(:mouse_y).returns(from_y)
19
+
20
+ event_data = {:from => [from_x, from_y],:to => [to_x, to_y]}
21
+ exp_event = {
22
+ :type => :mouse,
23
+ :id => MsLeft,
24
+ :action => :up,
25
+ :callback_key => :mouse_drag,
26
+ :data => event_data
27
+ }
28
+
29
+ subject.stubs(:fire).with(:event_received, any_parameters)
30
+
31
+ subject.expects(:fire).with(:event_received, exp_event)
32
+
33
+ subject._handle_event(MsLeft, :down)
34
+ subject._handle_event(nil, :motion)
35
+ @window.stubs(:mouse_x).returns(to_x)
36
+ @window.stubs(:mouse_y).returns(to_y)
37
+ subject._handle_event(MsLeft, :up)
38
+
39
+ end
40
+ end
41
+
42
+ describe "standard keyboard events" do
43
+ it 'calls the callbacks for the correct events' do
44
+ r_pressed = 0
45
+ y_pressed = 0
46
+ subject.reg :keyboard_down, KbR do
47
+ r_pressed += 1
48
+ end
49
+ subject.reg :keyboard_down, KbY do
50
+ y_pressed += 1
51
+ end
52
+
53
+ subject._handle_event(KbT, :down)
54
+ r_pressed.should == 0
55
+ y_pressed.should == 0
56
+
57
+ subject._handle_event(KbR, :up)
58
+ r_pressed.should == 0
59
+ y_pressed.should == 0
60
+
61
+ subject._handle_event(KbR, :down)
62
+ r_pressed.should == 1
63
+ y_pressed.should == 0
64
+
65
+ subject._handle_event(KbY, :down)
66
+ r_pressed.should == 1
67
+ y_pressed.should == 1
68
+
69
+ subject.clear_hooks self
70
+
71
+ # has now been unregistered
72
+ subject._handle_event(KbR, :down)
73
+ r_pressed.should == 1
74
+
75
+ subject._handle_event(KbY, :down)
76
+ y_pressed.should == 1
77
+ end
78
+
79
+ it 'passes along args'
80
+ end
81
+
82
+ describe "mapping an event id to a boolean" do
83
+ it "should set an ivar to true as long as the event id is down" do
84
+ listener = Struct.new(:left).new
85
+ subject.while_pressed KbLeft, listener, :left
86
+
87
+ listener.left.should be_false
88
+
89
+ subject._handle_event(KbLeft, :down)
90
+ listener.left.should be_true
91
+
92
+ subject._handle_event(GpLeft, :down)
93
+ listener.left.should be_true
94
+
95
+ subject._handle_event(GpLeft, :up)
96
+ listener.left.should be_true
97
+
98
+ subject._handle_event(KbT, :up)
99
+ listener.left.should be_true
100
+
101
+ subject._handle_event(KbLeft, :up)
102
+ listener.left.should be_false
103
+ end
104
+ end
105
+
106
+ describe "mapping multiple keys to a boolean" do
107
+ it "should set an ivar to true as long as ANY of the keys are down" do
108
+ pending
109
+ listener = Struct.new(:left).new
110
+ subject.while_pressed [KbLeft, GpLeft], listener, :left
111
+
112
+ listener.left.should be_false
113
+
114
+ subject._handle_event(KbLeft, :down)
115
+ listener.left.should be_true
116
+
117
+ subject._handle_event(GpLeft, :down)
118
+ listener.left.should be_true
119
+
120
+ subject._handle_event(KbT, :up)
121
+ listener.left.should be_true
122
+
123
+ subject._handle_event(KbP, :down)
124
+ listener.left.should be_true
125
+
126
+ subject._handle_event(GpLeft, :up)
127
+ listener.left.should be_true
128
+
129
+ subject._handle_event(KbLeft, :up)
130
+ listener.left.should be_false
131
+ end
132
+ end
133
+
134
+ end
data/spec/label_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'label'
3
2
 
4
3
  describe 'a new Label' do
5
4
  before do
@@ -1,6 +1,4 @@
1
1
  require File.join(File.dirname(__FILE__),'helper')
2
- require 'physical'
3
- require 'actor'
4
2
 
5
3
  class CircleActor < Actor
6
4
  has_behaviors :physical => {:shape => :circle,
@@ -12,14 +10,125 @@ describe 'A new physical behavior' do
12
10
  before do
13
11
  @stage = stub(:load_animation_set => ['1.png_img_obj','2.png_img_obj'],:register_physical_object => true)
14
12
 
15
- opts = {:stage=>@stage, :input=>"input", :resources=>"rm"}
16
- @actor = CircleActor.new opts
13
+ @opts = {:stage=>@stage, :input=>"input", :resources=>"rm"}
14
+ @actor = CircleActor.new @opts
17
15
  @physical = @actor.physical
18
16
  end
19
17
 
20
18
  it 'should add methods to its actor' do
21
19
  @actor.should.respond_to? :x
22
- pending 'testing this feels dirty...'
20
+ pending 'add shared example for relegates'
21
+ end
22
+
23
+ describe "#pivot" do
24
+ it 'creates a new PivotJoint and adds it to the space' do
25
+ other = CircleActor.new @opts
26
+ v1 = vec2(2,3)
27
+ v2 = vec2(4,5)
28
+ CP::Constraint::PivotJoint.expects(:new).with(@physical.body, other.body, v1, v2).returns(:joint)
29
+ @stage.expects(:register_physical_constraint).with(:joint)
30
+
31
+ @actor.pivot(v1, other, v2).should == :joint
32
+ end
33
+ end
34
+
35
+ describe "#pin" do
36
+ it 'creates a new PinJoint and adds it to the space' do
37
+ other = CircleActor.new @opts
38
+ v1 = vec2(2,3)
39
+ v2 = vec2(4,5)
40
+ CP::Constraint::PinJoint.expects(:new).with(@physical.body, other.body, v1, v2).returns(:joint)
41
+ @stage.expects(:register_physical_constraint).with(:joint)
42
+
43
+ @actor.pin(v1, other, v2).should == :joint
44
+ end
45
+ end
46
+
47
+ describe "#spring" do
48
+ it 'creates a new DampedSpring and adds it to the space' do
49
+ other = CircleActor.new @opts
50
+ v1 = vec2(2,3)
51
+ v2 = vec2(4,5)
52
+ CP::Constraint::DampedSpring.expects(:new).with(@physical.body, other.body, v1, v2, 1,2,3).returns(:spring)
53
+ @stage.expects(:register_physical_constraint).with(:spring)
54
+
55
+ @actor.spring(v1, other, v2, 1, 2, 3).should == :spring
56
+ end
57
+ end
58
+
59
+
60
+
61
+ describe "#groove" do
62
+ it 'creates a new GrooveJoint and adds it to the space' do
63
+ other = CircleActor.new @opts
64
+ v1 = vec2(2,3)
65
+ v2 = vec2(4,5)
66
+ v3 = vec2(9,7)
67
+ CP::Constraint::GrooveJoint.expects(:new).with(@physical.body, other.body, v1, v2, v3).returns(:groove)
68
+ @stage.expects(:register_physical_constraint).with(:groove)
69
+
70
+ @actor.groove(v1, v2, other, v3).should == :groove
71
+ end
72
+ end
73
+
74
+ describe "#rotary_spring" do
75
+ it 'creates a new DampedRotarySpring and adds it to the space' do
76
+ other = CircleActor.new @opts
77
+ CP::Constraint::DampedRotarySpring.expects(:new).with(@physical.body, other.body, 3.14, 10, 50).returns(:rotary_spring)
78
+ @stage.expects(:register_physical_constraint).with(:rotary_spring)
79
+ @actor.rotary_spring(other, 3.14, 10, 50).should == :rotary_spring
80
+ end
81
+ end
82
+
83
+ describe "#rotary_limit" do
84
+ it 'creates a new RotaryLimitJoint and adds it to the space' do
85
+ other = CircleActor.new @opts
86
+ CP::Constraint::RotaryLimitJoint.expects(:new).with(@physical.body, other.body, 0, 3).returns(:rotary_limit)
87
+ @stage.expects(:register_physical_constraint).with(:rotary_limit)
88
+ @actor.rotary_limit(other, 0, 3).should == :rotary_limit
89
+ end
90
+ end
91
+
92
+ describe "#ratchet" do
93
+ it 'creates a new RatchetJoint and adds it to the space' do
94
+ other = CircleActor.new @opts
95
+ CP::Constraint::RatchetJoint.expects(:new).with(@physical.body, other.body, 0, 0.3).returns(:ratchet)
96
+ @stage.expects(:register_physical_constraint).with(:ratchet)
97
+ @actor.ratchet(other, 0, 0.3).should == :ratchet
98
+ end
99
+ end
100
+
101
+ describe "#gear" do
102
+ it 'creates a new GearJoint and adds it to the space' do
103
+ other = CircleActor.new @opts
104
+ CP::Constraint::GearJoint.expects(:new).with(@physical.body, other.body, 0, 0.3).returns(:gear)
105
+ @stage.expects(:register_physical_constraint).with(:gear)
106
+ @actor.gear(other, 0, 0.3).should == :gear
107
+ end
108
+ end
109
+
110
+ describe "#motor" do
111
+ it 'creates a new SimpleMotor and adds it to the space' do
112
+ other = CircleActor.new @opts
113
+ CP::Constraint::SimpleMotor.expects(:new).with(@physical.body, other.body, 40).returns(:motor)
114
+ @stage.expects(:register_physical_constraint).with(:motor)
115
+ @actor.motor(other, 40).should == :motor
116
+ end
117
+ end
118
+
119
+ describe "#slide" do
120
+ it 'creates the slide joint and adds it to the space' do
121
+ other = CircleActor.new @opts
122
+ v1 = vec2(2,3)
123
+ v2 = vec2(4,5)
124
+ min = 2.0
125
+ max = 3.0
126
+ CP::Constraint::SlideJoint.expects(:new).with(@physical.body, other.body, v1, v2, min, max).returns(:joint)
127
+
128
+ @stage.expects(:register_physical_constraint).with(:joint)
129
+
130
+ @actor.slide(v1, other, v2, min, max).should == :joint
131
+ end
23
132
  end
24
133
 
25
134
  end