for(Uint16 n = 0 ;n < bulletSprites.size(); n++) { if(bulletSprites.at(n).dir == MINUS) bulletSprites.at(n).y -= 7; else bulletSprites.at(n).y += 7; bulletSprites.at(n).sprite->addToSurface(0, bulletSprites.at(n).x, bulletSprites.at(n).y); //Check if a bullet hits an Object if( (col = checkSpriteCollision(bulletSprites.at(n).sprite->getCurPosition(), bulletSprites.at(n).owner)) != -1 ) { printf("bullet = %i\n", bulletSprites.at(n).y + bulletSprites.at(n).sprite->getCurPosition()->h); printf("plane = %i\n", sprites.at(col).y); //Substitude the energie from the object sprites.at(col).energie -= bulletSprites.at(n).energie; //Buffer the bullerSprite Sprite bufSprite = *bulletSprites.at(n).sprite; //Remove the bulletSprite from the vector bulletSprites.erase(it); //Use the Buffer to draw a blank image of the bullet bufSprite.addToSurface(3, bufSprite.getCurPosition()->x, bufSprite.getCurPosition()->y); if(sprites.at(col).energie <= 0) { //If the sprite, that had been hit, has no energy left, then //start a thread, which animates the explosion, and removes //the object from its vector. if(col != 0) explodeThread = SDL_CreateThread(startExplode, &col); else explodeThread = SDL_CreateThread(startPlayerPlaneExplosion, &col); } } else { if(bulletSprites.at(n).y + bulletSprites.at(n).sprite->getCurPosition()->h >= 0 && !bulletSprites.at(n).sprite->isOutOfScreen()){ it++; } else { //Buffer the bulletSprite Sprite bufSprite = *bulletSprites.at(n).sprite; //Remove the bulletSprite from the vector bulletSprites.erase(it); //Use the Buffer to draw a blank image of the bullet bufSprite.addToSurface(3, bufSprite.getCurPosition()->x, bufSprite.getCurPosition()->y); } } }