Changes to projectile_pool.cpp

We don't need to change a lot inside of the ProjectilePool class. In fact, we only need to make two changes to one function. The MoveProjectiles function inside of the ProjectilePool class performs all of the collision detection between projectiles and our two ships. If a ship is destroyed, we run the m_Explode particle emitter on that ship. That will require two new lines of code inside of the hit test condition for each of the ships. Here is the new version of the MoveProjectiles function:

void ProjectilePool::MoveProjectiles() {
Projectile* projectile;
std::vector<Projectile*>::iterator it;
for( it = m_ProjectileList.begin(); it != m_ProjectileList.end(); it++ ) {
projectile = *it;
if( projectile->m_Active ) {
projectile->Move();
if( projectile->m_CurrentFrame == 0 &&
player->m_CurrentFrame == 0 &&
( projectile->HitTest( player ) ||
player->CompoundHitTest( projectile ) ) ) {
player->m_CurrentFrame = 1;
player->m_NextFrameTime = ms_per_frame;
player->m_Explode->Run(); // added
projectile->m_CurrentFrame = 1;
projectile->m_NextFrameTime = ms_per_frame;
}
if( projectile->m_CurrentFrame == 0 &&
enemy->m_CurrentFrame == 0 &&
( projectile->HitTest( enemy ) ||
enemy->CompoundHitTest( projectile ) ) ) {
enemy->m_CurrentFrame = 1;
enemy->m_NextFrameTime = ms_per_frame;
enemy->m_Explode->Run(); // added
projectile->m_CurrentFrame = 1;
projectile->m_NextFrameTime = ms_per_frame;
}
}
}
}

The two lines of code I have added are for the calls to player->m_Explode->Run(); and enemy->m_Explode->Run();These lines execute when the player's ship or the enemy ship collides with one of the projectiles and is destroyed.