13.5. Armed players and armed robots

In this section we discuss the cCritterArmedPlayer and cCritterArmedRobot child classes of cCritterArmed.

The cCritterArmedPlayer objects shoot when the user presses the spacebar or left-clicks the mouse. We implement this by deriving our players from the cCritterArmedPlayer class and letting cCritterArmedPlayer override the feellistener(Real dt) method so as use the left button or the spacebar to fire its gun. That is, as we already mentioned in Chapter 12: Listeners, we’ll have an override something like this.

 void cCritterArmedPlayer::feellistener(Real dt) { cCritter::feellistener(dt); _bshooting = (pgame()->keystate(VK_SPACE) == cController::KEYON); if (pgame()->keystate(VK_LBUTTON) == cController::KEYON) ...

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.