Advertisement
Guest User

Chipmunk Ruby Collisions

a guest
Jul 23rd, 2010
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.30 KB | None | 0 0
  1. it 'can have old style callbacks' do
  2.     space = CP::Space.new
  3.     bod = CP::Body.new 90, 76
  4.     shapy = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
  5.     shapy.collision_type = :foo
  6.  
  7.     bod_one = CP::Body.new 90, 76
  8.     shapy_one = CP::Shape::Circle.new bod_one, 40, CP::ZERO_VEC_2
  9.     shapy_one.collision_type = :bar
  10.     space.add_shape shapy
  11.     space.add_shape shapy_one
  12.  
  13.     called = false
  14.     space.add_collision_func :foo, :bar do |a,b|
  15.       a.should_not be_nil
  16.       b.should_not be_nil
  17.       called = true
  18.       1
  19.     end
  20.  
  21.     space.step 1
  22.     called.should be_true
  23.   end
  24.  
  25.   class CollisionHandler
  26.     attr_reader :begin_called
  27.     def begin(a,b,arbiter)
  28.       @begin_called = [a,b]
  29.     end
  30.   end
  31.  
  32.   it 'can have new style callbacks' do
  33.     ch = CollisionHandler.new
  34.  
  35.     space = CP::Space.new
  36.     bod = CP::Body.new 90, 76
  37.     shapy = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
  38.     shapy.collision_type = :foo
  39.  
  40.     bod_one = CP::Body.new 90, 76
  41.     shapy_one = CP::Shape::Circle.new bod_one, 40, CP::ZERO_VEC_2
  42.     shapy_one.collision_type = :bar
  43.     space.add_shape shapy
  44.     space.add_shape shapy_one
  45.  
  46.     space.add_collision_handler :foo, :bar, ch
  47.  
  48.     space.step 1
  49.    
  50.     ch.begin_called[0].should == shapy
  51.     ch.begin_called[1].should == shapy_one
  52.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement