Coding a class for pickups
In this section, 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:
- First, we will code the
Pickup.hfile. This will reveal all the details of the member data and the prototypes for the functions. - Then, we will code the
Pickup.cppfile which, of course, will contain the definitions for all the functions of thePickupclass. As we step through this, I will explain exactly how an object of thePickuptype will work and be controlled. - Finally, we will use the
Pickupclass in themainfunction 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 Solution Explorer and select Add | New Item.... In the Add New Item window, highlight (by left-clicking) Header File (.h), and then, in the Name field, type Pickup.h.
Add and...