O'Reilly logo

Beginning C++ Game Programming by John Horton

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

Coding a class for pickups

We will code a Pickup class that has a Sprite, member as well as other member data and functions. We will add pickups to our game in just a few steps:

  1. First, we will code the Pickup.h file. This will reveal all the details of the member data and the prototypes for the functions.
  2. Then we will code the Pickup.cpp file which, of course, will contain the definitions for all the functions of the Pickup class. As we step through it, I will explain exactly how an object of type Pickup will work and be controlled.
  3. Finally, we will use the Pickup class in the main function to spawn them, update them and draw them.

Let's get started with step 1.

Coding the Pickup header file

To make the new header file, right-click Header Files in 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