Ok sorry it was really long. Well, this is the part of code I think can ralentize more.
I've to say that my game is slow intermittently, 1 sec goes good, 1 sec goes bad
I check for each missile (there can be 1 to 150 at a time) if it's being hit by any of the current bullets casted (1 to 15 aprox)
void Missile_mgr::UpdateAndDrawMissiles(sf::RenderWindow& _window, float elapsedTime) {
bool bHitByBullet;
//////// MISSILE LOOP START ///////
// This could be done with missileList.RemoveAllThatComply_nodeArg() + a condition function... but simplier this way.
for(std::list<Missile>::iterator mIt = missileList.begin(); mIt!=missileList.end(); )
{
mIt->Update(elapsedTime);
bHitByBullet = false;
////// BULLET LOOP START ////////
for(std::list<Bullet>::iterator bIt=pBullet_mgr->bulletList.begin(); bIt!=pBullet_mgr->bulletList.end(); )
{
if(Collision::BoundingBoxTest(mIt->spMissile, bIt->spBullet)) //// BULLET-MISSILE COLLISION.
{
mIt->hp -= pPlayer->damage;
if(mIt->hp <= 0)
{
bHitByBullet=true; // should be bDeadMonster
switch(mIt->type)
{
case Missile::Apple: // DEAD FRUIT -> NO REWARD.
break;
case Missile::Normal:
default:
pLevel_mgr->xpReward+=10;
pLevel_mgr->coinReward+=10;
}
}
pBullet_mgr->bulletList.erase(bIt++);// laser weapon may ignore this line -> go through missiles.
// we can also break, so only 1 bullet is deleted, no 2. Plus we directly delete missile and no need bool bHitByBullet
} else ++bIt;
}
////// BULLET LOOP END ////////
if(bHitByBullet) {
// score already increased in bullet loop. (may hit more than 1 missile)
missileList.erase(mIt++);
} else {
if(Collision::BoundingBoxTest(mIt->spMissile, pPlayer->spPlayer)) //// MISSILE HIT PLAYER
{
switch(mIt->type) {
case Missile::Apple:
pPlayer->Heal(1); // to be updated
break;
case Missile::Normal:
default:
pPlayer->DoDmg(2.5); // to be updated
break;
}
missileList.erase(mIt++);
} else {
if(mIt->spMissile.getPosition().y > GROUND_ALTITUDE) { //// MISSILE HIT GROUND
missileList.erase(mIt++);
} else { // Nothing happens
_window.draw(mIt->spMissile);
++mIt;
}
}
}
} //////// MISSILE LOOP END ///////
}