11.1. The critter Collide method
The cCritter class has a virtual BOOL collide(cCritter *pcritter) method. This method does the following: (a) check if pcritter is touching the caller, and if not, return FALSE, and (b) if pcritter is touching the caller, then execute a collision with pcritter, possibly changing the health, position, and velocity of both pcritter and the caller, and when you’re done return TRUE.
There are three points to get straight right way.
First of all, our collide might better be called ifTouchingDoACollision. But that seems a bit too unwieldy.
Second, to avoid wasting time, and to keep our physics symmetric, we only want to call collide once for each pair <pcritteri, pcritterj>. That is, we intend for the collide code of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access