O'Reilly logo

Software Engineering and Computer Games by Rudy Rucker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required