void AsteroidManager::update() { std::vector<Asteroid*>::iterator itr = iAsteroids.begin(); for (; itr != iAsteroids.end(); itr++) { (*itr)->update(this, iApplication->getCollisionManager()); } if (markedForSplit != nullptr) { splitAsteroid(markedForSplit); markedForSplit = nullptr; } }
//-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button) { for(int i = 0; i < asteroids.size(); i++) { if(asteroids[i]->getCollision(ofPoint(x, y))) { cout << "Mouse hit Asteroid " << i << endl; splitAsteroid(i); } } }
void Game::checkCollisions() { for (unsigned int i = 0; i < asteroids.size(); ++i) { if (ship->checkCollision(asteroids[i])) { ship->reinitialize(); } } if (ship->bullets.size() > 0) { for (unsigned int i = 0; i < ship->bullets.size(); ++i) { for (unsigned int j = 0; j < asteroids.size(); ++j) { if (ship->bullets[i]->checkCollision(asteroids[j])) { ship->bullets[i]->lifeTime = 0; splitAsteroid(j); } } } } }
//-------------------------------------------------------------- void ofApp::update() { // We get the time that last frame lasted, and use it to update asteroids logic // so their behaviour is independent to the framerate float elapsedTime = ofGetLastFrameTime(); for(int i = 0; i < asteroids.size(); i++) { if (checkCollisions( asteroids[i] ) ) { splitAsteroid(i); continue; } asteroids[i]->update(elapsedTime); } // TODO // Implement calls for logic: // - players // - bullets // - collisions // - game conditions // [...] //Destroying Bullets for (SpaceShip* player : players) player->update(elapsedTime); for(int currentPlayer = 0; currentPlayer < players.size(); currentPlayer++) { for(int currentBullet = 0; currentBullet < players[currentPlayer]->getBullets().size(); currentBullet++) { if(players[currentPlayer]->getBullets()[currentBullet]->isDead()) { //delete players[currentPlayer]->getBullets()[currentBullet]; } } } }