void GameWorld::checkCollisionVsEnemyShots(GameObject* go) { Shot* shot; Rect goRect = go->getRectangle(); for (int i = 0; i < m_gameObjectManager->getEnemyShotsInUse(); i++) { shot = m_gameObjectManager->getEnemyShot(i); // Check that the shot is on screen. If not, remove. shot->setActive(shot->collide(m_physicsComponent, m_cameraView)); if (!shot->getActive()) { m_gameObjectManager->removeEnemyShot(i); i--; continue; } if ( shot->collide(m_physicsComponent, goRect) ) { go->Health -= shot->Damage; m_gameObjectManager->removeEnemyShot(i); i--; continue; } } }
void GameWorld::checkCollisionVsPlayersShots(GameObject* go) { Shot* shot; for (int j = 0; j < m_gameObjectManager->getPlayerShotsInUse(); j ++) { shot = m_gameObjectManager->getPlayerShot(j); // Check that the shot is on screen. If not, remove. shot->setActive(shot->collide(m_physicsComponent, m_cameraView)); if (!shot->getActive()) { m_gameObjectManager->removePlayerShot(j); j--; continue; } // check if shot hits enemy. if ( shot->collide(m_physicsComponent, go->getRectangle())) { go->Health -= shot->Damage; m_gameObjectManager->removePlayerShot(j); j--; continue; } } }