The Ship class' Render function

The final changes to the Ship class are in the ship's Render function. Inside this function, we will need to add code that moves and renders the two new particle systems, as well as code that will turn the exhaust on if the ship is accelerating, and off if it isn't. Here is the new version of the function:

void Ship::Render() {
if( m_Alive == false ) {
return;
}
m_Exhaust->Move();
m_Explode->Move();
dest.x = (int)m_X;
dest.y = (int)m_Y;
dest.w = c_Width;
dest.h = c_Height;
src.x = 32 * m_CurrentFrame;
float degrees = (m_Rotation / PI) * 180.0;
int return_code = SDL_RenderCopyEx( renderer, m_SpriteTexture,
&src, &dest,
degrees, NULL, SDL_FLIP_NONE );
if( return_code != 0 ) {
printf("failed to render image: %s\n", IMG_GetError() );
}

if( m_Accelerating == false ) {
m_Exhaust->m_active = false;
}
else {
m_Exhaust->m_active = true;
}
m_Accelerating = false;
}

Take a look at the first block of added code, near the top:

m_Exhaust->Move();
m_Explode->Move();

The call to the Move function on an emitter both moves and renders all of the particles inside of the particle system. It also spawns new particles if it is time for the emitter to do that. At the very end of the function, there is code to handle the exhaust emitter:

if( m_Accelerating == false ) {
m_Exhaust->m_active = false;
}
else {
m_Exhaust->m_active = true;
}
m_Accelerating = false;

This code checks to see if the m_Accelerating flag is false. If it is, we deactivate the exhaust emitter. If the ship is accelerating, we set the m_active flag to true. We don't make a call to the Run function, because we are doing this every frame, and we don't want to start the time to live over on that emitter every time we loop. The last line sets m_Accelerating to false. We do this because we don't have anywhere in our code that detects when a ship stops accelerating. If the ship is accelerating, that flag will be set back to true before we get to this point in the code. If not, it will stay set to false.