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.
- data/Gemfile +1 -8
- data/Rakefile +13 -37
- data/TODO.txt +27 -27
- data/docs/getting_started.rdoc +2 -2
- data/gamebox.gemspec +33 -191
- data/lib/gamebox.rb +18 -14
- data/lib/gamebox/actor.rb +37 -27
- data/lib/gamebox/actor_factory.rb +4 -5
- data/lib/gamebox/actor_view.rb +8 -0
- data/lib/gamebox/actors/collidable_debugger.rb +2 -2
- data/lib/gamebox/actors/curtain.rb +3 -3
- data/lib/gamebox/actors/emitter.rb +51 -0
- data/lib/gamebox/actors/label.rb +27 -7
- data/lib/gamebox/actors/logo.rb +1 -1
- data/lib/gamebox/actors/spatial_debugger.rb +25 -10
- data/lib/gamebox/arbiter.rb +61 -34
- data/lib/gamebox/behavior.rb +3 -3
- data/lib/gamebox/behaviors/animated.rb +1 -1
- data/lib/gamebox/behaviors/audible.rb +1 -1
- data/lib/gamebox/behaviors/collidable.rb +9 -4
- data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +26 -1
- data/lib/gamebox/behaviors/collidable/circle_collidable.rb +3 -3
- data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
- data/lib/gamebox/behaviors/graphical.rb +30 -4
- data/lib/gamebox/behaviors/layered.rb +1 -1
- data/lib/gamebox/behaviors/physical.rb +113 -30
- data/lib/gamebox/behaviors/timed.rb +33 -0
- data/lib/gamebox/behaviors/updatable.rb +1 -1
- data/lib/gamebox/class_finder.rb +1 -21
- data/lib/gamebox/console_app.rb +33 -31
- data/lib/gamebox/constants.rb +481 -0
- data/lib/gamebox/data/config/objects.yml +7 -0
- data/lib/gamebox/gamebox_application.rb +10 -33
- data/lib/gamebox/gamebox_generator.rb +32 -32
- data/lib/gamebox/input_manager.rb +73 -32
- data/lib/gamebox/lib/inflector.rb +1 -1
- data/lib/gamebox/lib/range_ext.rb +5 -0
- data/lib/gamebox/lib/rect.rb +548 -548
- data/lib/gamebox/lib/sorted_list.rb +1 -1
- data/lib/gamebox/lib/symbol_ext.rb +8 -0
- data/lib/gamebox/physical_director.rb +1 -1
- data/lib/gamebox/physical_stage.rb +3 -3
- data/lib/gamebox/physics.rb +0 -3
- data/lib/gamebox/resource_manager.rb +22 -17
- data/lib/gamebox/sound_manager.rb +3 -2
- data/lib/gamebox/spatial_hash.rb +60 -31
- data/lib/gamebox/spatial_stagehand.rb +30 -6
- data/lib/gamebox/spec/helper.rb +7 -7
- data/lib/gamebox/stage.rb +18 -19
- data/lib/gamebox/stage_manager.rb +33 -23
- data/lib/gamebox/stagehand.rb +3 -0
- data/lib/gamebox/svg_document.rb +1 -1
- data/lib/gamebox/tasks/gamebox_tasks.rake +133 -0
- data/lib/gamebox/templates/actor.erb +0 -2
- data/lib/gamebox/templates/actor_view.erb +1 -3
- data/lib/gamebox/templates/template_app/Gemfile +3 -2
- data/lib/gamebox/templates/template_app/Rakefile +3 -8
- data/lib/gamebox/templates/template_app/config/environment.rb +7 -39
- data/lib/gamebox/templates/template_app/src/demo_stage.rb +1 -2
- data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -3
- data/lib/gamebox/version.rb +2 -2
- data/lib/gamebox/viewport.rb +44 -8
- data/lib/gamebox/views/graphical_actor_view.rb +22 -16
- data/lib/gamebox/wrapped_screen.rb +9 -1
- data/script/perf_spatial_hash.rb +49 -58
- data/script/perf_struct_vs_array.rb +32 -0
- data/spec/actor_factory_spec.rb +61 -0
- data/spec/actor_spec.rb +24 -18
- data/spec/actor_view_spec.rb +51 -6
- data/spec/animated_spec.rb +27 -6
- data/spec/arbiter_spec.rb +12 -24
- data/spec/backstage_spec.rb +1 -1
- data/spec/behavior_spec.rb +3 -3
- data/spec/class_finder_spec.rb +13 -0
- data/spec/collidable_spec.rb +30 -10
- data/spec/emitter_spec.rb +20 -0
- data/spec/helper.rb +5 -21
- data/spec/input_manager_spec.rb +134 -0
- data/spec/label_spec.rb +0 -1
- data/spec/physical_spec.rb +114 -5
- data/spec/resource_manager_spec.rb +1 -2
- data/spec/spatial_hash_spec.rb +23 -7
- data/spec/spatial_stagehand_spec.rb +97 -0
- data/spec/stage_manager_spec.rb +0 -1
- data/spec/stage_spec.rb +2 -2
- data/spec/viewport_spec.rb +92 -48
- metadata +223 -119
- data/.gitignore +0 -11
- data/History.txt +0 -80
- data/VERSION +0 -1
- data/lib/gamebox/event_compat.rb +0 -285
- data/lib/gamebox/lib/diy.rb +0 -371
- data/lib/gamebox/lib/numbers_ext.rb +0 -3
- data/lib/gamebox/tasks/gamebox_tasks.rb +0 -61
- data/load_paths.rb +0 -20
data/spec/animated_spec.rb
CHANGED
@@ -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
|
-
|
9
|
-
@actor
|
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
|
-
|
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.
|
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
|
40
|
-
a = stub(:collidable_shape => :circle)
|
41
|
-
b = stub(:collidable_shape => :polygon)
|
42
|
-
@arbiter.
|
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
|
48
|
-
a = stub(:collidable_shape => :polygon)
|
49
|
-
b = stub(:collidable_shape => :circle)
|
50
|
-
@arbiter.
|
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
|
data/spec/backstage_spec.rb
CHANGED
data/spec/behavior_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
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.
|
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.
|
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
|
data/spec/collidable_spec.rb
CHANGED
@@ -1,14 +1,34 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'helper')
|
2
|
-
|
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 =
|
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.
|
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.
|
44
|
+
@collidable.expects(:width).returns(44)
|
25
45
|
@actor.width.should == 44
|
26
|
-
@collidable.
|
46
|
+
@collidable.expects(:height).returns(45)
|
27
47
|
@actor.height.should == 45
|
28
48
|
|
29
|
-
@collidable.
|
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
|
38
|
-
@collidable.center_y.should
|
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
|
46
|
-
@collidable.center_y.should
|
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
|
-
|
5
|
-
require File.
|
6
|
-
require 'spec'
|
7
|
-
|
8
|
-
|
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
data/spec/physical_spec.rb
CHANGED
@@ -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 '
|
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
|