void SFAsset::HandleCollision() { SetNotAlive(); }
void SFAsset::HandleCollision() { health -= 1; if(health <= 0)SetNotAlive(); }
void SFAsset::HandleCollision() { if(SFASSET_PROJECTILE == type || SFASSET_ALIEN == type || SFASSET_PLAYER == type || SFASSET_COIN == type) SetNotAlive(); }
void SFAsset::HandleCollision() { if(SFASSET_PROJECTILE == type || SFASSET_ALIEN == type || SFASSET_COIN == type || SFASSET_RANGER == type || SFASSET_HEALTHPACK == type|| SFASSET_SCOUT == type|| SFASSET_PICKUP == type || SFASSET_EXPLOSION == type|| SFASSET_GAMEOVER == type || SFASSET_PLAYER == type || SFASSET_ALIENFIRE == type || SFASSET_BOSS == type || SFASSET_CLOUD == type ) { SetNotAlive(); } }
// Handing object collisions int SFAsset::HandleCollision() { // Collisions for projectiles if(SFASSET_PROJECTILE == type) { SetNotAlive(); } // Handle collision for the powerup if(SFASSET_POWERUP == type) { SetNotAlive(); } // Collisions for aliens if(SFASSET_ALIEN == type){ int canvas_w, canvas_h; SDL_GetRendererOutputSize(sf_window->getRenderer(), &canvas_w, &canvas_h); // For removing enemy health and checking if it died if(this->GetHealth() > 0){ // Hurt the enemy for 5 HP this->SetHealth(this->GetHealth() - 5); // Get HP as string int tempHP = this->GetHealth(); // Convert the HP to string form string HPTempString; ostringstream HPConvert; HPConvert << tempHP; HPTempString = HPConvert.str(); // Tell player it was hurt cout << "Hurt enemy " << this->GetId() << " for 5 HP. (EnemyHP: " << (this->GetHealth() <= 0 ? "DEAD" : HPTempString) << ")" << endl; // Do another check because we can reach 0, but it won't check until next collision. if(this->GetHealth() <= 0){ // Enemy died, so set new position and health auto pos = Point2(rand() % 600 + 32, rand() % 400 + 600); this->SetPosition(pos); this->SetHealth(10); // Return special condition back to call return 1; } } else{ // Enemy died, so set new position and health auto pos = Point2(rand() % 600 + 32, rand() % 400 + 600); this->SetPosition(pos); this->SetHealth(15); // Tell player cout << "Enemy " << this->GetId() << " died!" << endl; // Return special condition back to call return 1; } } // Collisions for coins if(SFASSET_COIN == type) { // Kill the coin this->SetNotAlive(); } return 0; }