12.2. The listeners
As we mentioned in Chapter 8: Critters, a critter uses the Strategy pattern to farm out the task of listening to its cListener *_plistener member with a call to feellistener.
void cCritter::feellistener(Real dt) { _plistener->listen(dt, this); }
We pass the pointer this to the listener so that it can change the fields of this calling cCritter as required. Because a cListener takes a cGame * argument to its listen method, we can say that the cListener can ‘navigate’ to a cGame. The caller critter’s pgame() holds the cController object that stores all of the keys and mouse actions you need to process.
We pass a dt argument to the plistener->feellistener because the mouse-based listener cListenerCursor needs to know the
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.