Now that we have looked at the class definitions for our Projectile and ProjectilePool classes, we need to create a projectile.cpp file and a projectile_pool.cpp file to store the function code for those classes. Because this is in Chapter 6, Game Objects and the Game Loop, I would recommend creating a new folder named Chapter06 to hold these files. This code will do the work of pooling our projectiles, requesting an inactive projectile when we need one, and moving and rendering our active projectiles. First, let's look at the code we have in projectile.cpp:
#include "game.hpp"
Projectile::Projectile() {
m_Active = false;
m_X = 0.0;
m_Y = 0.0;
m_VX = 0.0;
m_VY = 0.0;
SDL_Surface *temp_surface = IMG_Load( c_SpriteFile );
if( !temp_surface ) {
printf("failed to load image: %s\n", IMG_GetError...