Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- it 'can have old style callbacks' do
- space = CP::Space.new
- bod = CP::Body.new 90, 76
- shapy = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
- shapy.collision_type = :foo
- bod_one = CP::Body.new 90, 76
- shapy_one = CP::Shape::Circle.new bod_one, 40, CP::ZERO_VEC_2
- shapy_one.collision_type = :bar
- space.add_shape shapy
- space.add_shape shapy_one
- called = false
- space.add_collision_func :foo, :bar do |a,b|
- a.should_not be_nil
- b.should_not be_nil
- called = true
- 1
- end
- space.step 1
- called.should be_true
- end
- class CollisionHandler
- attr_reader :begin_called
- def begin(a,b,arbiter)
- @begin_called = [a,b]
- end
- end
- it 'can have new style callbacks' do
- ch = CollisionHandler.new
- space = CP::Space.new
- bod = CP::Body.new 90, 76
- shapy = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
- shapy.collision_type = :foo
- bod_one = CP::Body.new 90, 76
- shapy_one = CP::Shape::Circle.new bod_one, 40, CP::ZERO_VEC_2
- shapy_one.collision_type = :bar
- space.add_shape shapy
- space.add_shape shapy_one
- space.add_collision_handler :foo, :bar, ch
- space.step 1
- ch.begin_called[0].should == shapy
- ch.begin_called[1].should == shapy_one
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement