Exercises

Exercise 11.1: Turn off asteroid–asteroid collisions in Spacewar

Turn off the asteroid-to-asteroid collisions in the Spacewar game. To do this, override the cCritterAsteroid::collidesWith(cCritter *pcritterother) method. You’ll need to prototype the method in gamespacewar.h and implement it in gamespacewar.cpp. The implementation code should have these two lines.

if(pcritterother->IsKindOf(RUNTIME_CLASS(cCritterAsteroid))) 
    return cCollider::DONTCOLLIDE; 
return cCritter::collidesWith(pcritterother); 

Does this make the game run faster? Compare speeds before and after, using the Game popup menu to change the number of critters. When you compare the speeds of builds always make sure that both are Debug builds or both are Release builds. ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.