Using the Pickup class

After all that hard work implementing the Pickup class, we can now go ahead and write code in the game engine to actually put some pickups into the game.

The first thing we do is add an include directive to the ZombieArena.cpp file:

#include "stdafx.h" 
#include <SFML/Graphics.hpp> 
#include "ZombieArena.h" 
#include "Player.h" 
#include "TextureHolder.h" 
#include "Bullet.h" 
#include "Pickup.h"
using namespace sf;

In the following code, we add two Pickup instances, one called healthPickup and the other called ammoPickup. We pass the values 1 and 2 respectively into the constructor so that they are initialized to the correct type of pickup. Add the highlighted code we have just discussed:

// Hide the mouse pointer and replace it ...

Get Beginning C++ Game Programming 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.