13.6. The two-way cCritterArmed/cCritterBullet association

This optional subsection has some information about the somewhat tricky issue of how we maintain a two-way association between objects that can be deleted at any time.

As we mentioned at the start of the chapter, we will allow only some limited number of player bullets to be active at one time. If a player has shot, say, eight bullets and wants to shoot another, what we’ll do is to remove the oldest of the bullets when we shoot a new one. (Of course the number doesn’t have to be exactly eight; you can set it as cCritterArmed::MAXBULLETS.) This design means that the player needs to maintain an array of bullets. We choose an array rather than a list, because we traverse the collection ...

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.