12
12
#import " CCPhysics+ObjectiveChipmunk.h"
13
13
14
14
15
- @interface CCPhysicsTests : XCTestCase
15
+ @interface CCPhysicsTests : XCTestCase <CCPhysicsCollisionDelegate>
16
16
17
17
@end
18
18
@@ -307,7 +307,7 @@ -(void)testBasicSequences9
307
307
308
308
TestBasicSequenceHelper (self, physicsNode, parent, node, body);
309
309
}
310
-
310
+
311
311
-(void )testBasicSequences10
312
312
{
313
313
CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
@@ -333,6 +333,78 @@ -(void)testBasicSequences10
333
333
TestBasicSequenceHelper (self, physicsNode, parent, node, body);
334
334
}
335
335
336
+ -(void )testBasicSequences11
337
+ {
338
+ CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
339
+
340
+ CCNode *parent = [CCNode node ];
341
+ parent.contentSize = CGSizeMake (25 , 35 );
342
+ parent.anchorPoint = ccp (0.3 , 0.7 );
343
+ parent.position = ccp (20 , 60 );
344
+ parent.rotation = -15 ;
345
+ parent.scaleX = 1.5 ;
346
+ parent.scaleY = 8.0 ;
347
+
348
+ CCNode *node = [CCNode node ];
349
+ node.contentSize = CGSizeMake (30 , 30 );
350
+ node.anchorPoint = ccp (0 ,0 );
351
+ node.position = ccp (100 , 100 );
352
+ node.rotation = 30 ;
353
+ node.scaleX = 2.0 ;
354
+ node.scaleY = 3.0 ;
355
+
356
+ CCPhysicsBody *body = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
357
+ body.type = CCPhysicsBodyTypeStatic;
358
+
359
+ TestBasicSequenceHelper (self, physicsNode, parent, node, body);
360
+ }
361
+
362
+ -(void )testDynamicAnchorPoint
363
+ {
364
+ CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
365
+
366
+ CCNode *node = [CCNode node ];
367
+ node.contentSize = CGSizeMake (2 , 2 );
368
+ node.anchorPoint = ccp (0.5 , 0.5 );
369
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
370
+
371
+ node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
372
+ node.physicsBody .type = CCPhysicsBodyTypeDynamic;
373
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
374
+
375
+ [physicsNode addChild: node];
376
+ [physicsNode onEnter ];
377
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
378
+
379
+ node.rotation = 90 ;
380
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
381
+
382
+ [physicsNode onExit ];
383
+ }
384
+
385
+ -(void )testStaticAnchorPoint
386
+ {
387
+ CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
388
+
389
+ CCNode *node = [CCNode node ];
390
+ node.contentSize = CGSizeMake (2 , 2 );
391
+ node.anchorPoint = ccp (0.5 , 0.5 );
392
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
393
+
394
+ node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
395
+ node.physicsBody .type = CCPhysicsBodyTypeStatic;
396
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
397
+
398
+ [physicsNode addChild: node];
399
+ [physicsNode onEnter ];
400
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
401
+
402
+ node.rotation = 90 ;
403
+ XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
404
+
405
+ [physicsNode onExit ];
406
+ }
407
+
336
408
-(void )testCollisionGroups
337
409
{
338
410
CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
@@ -360,6 +432,8 @@ -(void)testCollisionGroups
360
432
// Both nodes should be at (0, 0)
361
433
XCTAssertTrue (CGPointEqualToPoint (node1.position , CGPointZero) , @" " );
362
434
XCTAssertTrue (CGPointEqualToPoint (node2.position , CGPointZero) , @" " );
435
+
436
+ [physicsNode onExit ];
363
437
}
364
438
365
439
-(void )testAffectedByGravity
@@ -393,6 +467,8 @@ -(void)testAffectedByGravity
393
467
394
468
// Node2 should stay at (0, 0)
395
469
XCTAssertTrue (node2.position .y == 0.0 , @" " );
470
+
471
+ [physicsNode onExit ];
396
472
}
397
473
398
474
-(void )testAllowsRotation
@@ -474,6 +550,8 @@ -(void)testAllowsRotation
474
550
475
551
XCTAssert (node.physicsBody .body .moment < INFINITY, @" " );
476
552
}
553
+
554
+ [physicsNode onExit ];
477
555
}
478
556
479
557
-(void )testBodyType
@@ -603,6 +681,50 @@ -(void)testBreakingJoints
603
681
XCTAssert (!joint2.valid , @" " );
604
682
XCTAssert (joint3.valid , @" " );
605
683
XCTAssert (joint4.valid , @" " );
684
+
685
+ [physics onExit ];
686
+ }
687
+
688
+ -(BOOL )ccPhysicsCollisionBegin : (CCPhysicsCollisionPair *)pair theStaticOne : (CCNode *)nodeA theDynamicOne : (CCNode *)nodeB
689
+ {
690
+ nodeB.physicsBody .type = CCPhysicsBodyTypeStatic;
691
+
692
+ // TODO not sure if we should hide the deferred nature or not... Hrm.
693
+ XCTAssertEqual (nodeB.physicsBody .type , CCPhysicsBodyTypeDynamic, @" " );
694
+
695
+ return FALSE ;
696
+ }
697
+
698
+ -(void )testBodyTypeCollisions
699
+ {
700
+ CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
701
+ physicsNode.collisionDelegate = self;
702
+ physicsNode.gravity = ccp (0 , -100 );
703
+
704
+ CCNode *node1 = [CCNode node ];
705
+ node1.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
706
+ node1.physicsBody .type = CCPhysicsBodyTypeStatic;
707
+ node1.physicsBody .collisionType = @" theStaticOne" ;
708
+ [physicsNode addChild: node1];
709
+
710
+ CCNode *node2 = [CCNode node ];
711
+ node2.position = ccp (0 , 10 );
712
+ node2.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
713
+ node2.physicsBody .type = CCPhysicsBodyTypeDynamic;
714
+ node2.physicsBody .collisionType = @" theDynamicOne" ;
715
+ [physicsNode addChild: node2];
716
+
717
+ // Force entering the scene to set up the physics objects.
718
+ [physicsNode onEnter ];
719
+
720
+ // Step the physics for a while.
721
+ for (int i=0 ; i<100 ; i++){
722
+ [physicsNode fixedUpdate: 1.0 /100.0 ];
723
+ }
724
+
725
+ XCTAssertEqual (node2.physicsBody .type , CCPhysicsBodyTypeStatic, @" " );
726
+
727
+ [physicsNode onExit ];
606
728
}
607
729
608
730
// TODO
0 commit comments