Before we get to the final stretch covering the controls and the rest of the rules engine, we now know enough about our game that we can implement the collision detection, which uses the same contact listener we used in Chapter 5, Brick Breaking Balls with Box2D. We will look at the
update
method in pieces, so we can discuss it along the way:
Filename:
OPPlayfieldLayer.mm
(update
, part 1)
-(void) update: (ccTime) dt { int32 velocityIterations = 30; int32 positionIterations = 30; // Instruct the world to perform a single step world->Step(dt, velocityIterations, positionIterations); // Evaluate all contacts std::vector<b2Body *>toDestroy; std::vector<OPContact>::iterator pos; for (pos = contactListener->_contacts.begin(); pos != contactListener->_contacts.end(); pos++) { OPContact contact = *pos; // Get the bodies involved in this contact b2Body *bodyA = contact.fixtureA->GetBody(); b2Body...