7.3. Force and acceleration

We handle the question of the forces acting on our critters by using the Strategy pattern. That is, we let our critters be composed with cForce *_pforce objects, and we let a critter feel forces by calling _pforce->force(this).

If we hadn’t used the Strategy pattern, we might instead have given the cCritter class a virtual cVector force() method which would give the force acting on the critter at any location and time. But, we want to able to change the kinds of forces that act on a critter without having to derive a whole new child class for each combination of forces. For to derive off critter child classes for the different kinds of forces would lead to a combinatorial explosion of more and more kinds of critter ...

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.