18.3. Sniffing a trail

Suppose you want to program a car-racing game in which you look down at a track from above and use the controls to steer your car along the track. Lining the track with lots of little walls is an option, but in this section we’ll talk about a different approach. The idea here is to lay down a trail that your critter can move along.

The cCritter::update method takes a CPopView *pactiveview argument. The reason we have this argument is so that the update can feed the pactiveview into the method COLORREF cCritter::sniff(const cVector &snifflocation, CPopView *pactive view). The sniff return value tells you the color of the pixel of the onscreen view corresponding to a given location.

The way to use sniff would be to make ...

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.