void CScene::update(void) { objects_vec testObjects(m_Objects); // make a local copy of vector bool explodeRock, explodeShip; // Crappy collission detection for bullet-rock and ship-rock while ( testObjects.size() > 0 ) { explodeRock = false; explodeShip = false; CGameObject *obj = testObjects[0]; if ((obj->getType() == OBJECT_BULLET || obj == m_Ship) && obj->isDead() == false && obj->isInvulnerable() == false ) { for (objects_vec::iterator it = m_Objects.begin(); it != m_Objects.end(); ++it) { CGameObject *obj2 = *it; if ( obj2->isDead() ) continue; if (obj2->getType() != OBJECT_ROCK) continue; if ( obj->collission(obj2) ) { CRock *rock = (CRock *) obj2; // Cast should be okey if ( rock->isBig() ) { #if USE_SOUND PlaySound( "detpack.wav", NULL, NULL ); #endif explodeRock = true; if (obj->getType() == OBJECT_BULLET) game->addPoints( 100 ); } else { if (obj->getType() == OBJECT_BULLET) game->addPoints( 25 ); } // Remove old rock and object from the scene rock->setDeathTime(-1); obj->setDeathTime(-1); m_NumRocks--; if (obj->getType() == OBJECT_SHIP) { game->loseLive(); explodeShip = true; } } } // Create the small rocks left after the explosion if (explodeRock) { for (int i=0; i < 4 + (rand()&1); i++) { CRock *newRock = new CRock(false); newRock->setOrigin( obj->getOrigin() ); newRock->setDeltaOrigin(D3DXVECTOR3((rand() % 100)/500.0f - 0.05f, (rand() % 100)/500.0f - 0.05f, 0.0f)); newRock->setDeltaRotation(D3DXVECTOR3(0.0f, 0.0f, (rand() % 100)/500.0f - 0.05f)); m_Objects.push_back( newRock ); m_NumRocks++; } } if (explodeShip) { // Some shatters from the ship for (int i=0; i < 4 + (rand()%4); i++) { CSpaceShip *particle = new CSpaceShip(); particle->setOrigin( m_Ship->getOrigin() ); particle->setSize(D3DXVECTOR3(0.02f * (1+rand()%4) / 2.0f, 0.02f * (1+rand()%4) / 2.0f, 0.02f * (rand()%4) / 2.0f)); particle->setDeltaOrigin(D3DXVECTOR3((1+rand() % 100)/500.0f - 0.1f, (1+rand() % 100)/500.0f - 0.1f, 0.0f)); particle->setDeltaRotation(D3DXVECTOR3(0.0f, 0.0f, (1+rand() % 100)/500.0f - 0.025f)); particle->setDecayRotation(1.0f); particle->setDeathTime( 1500 ); m_Objects.push_back( particle ); } // Some bullets for extra effect for (int i=0; i < 4 + (rand()%4); i++) { CBullet *particle = new CBullet(); particle->setOrigin( m_Ship->getOrigin() ); particle->setSize(D3DXVECTOR3(0.02f * (1+rand()%4) / 2.0f, 0.02f * (1+rand()%4) / 2.0f, 0.02f * (1+rand()%4) / 2.0f)); particle->setDeltaOrigin(D3DXVECTOR3((1+rand() % 100)/250.0f - 0.02f, (1+rand() % 100)/250.0f - 0.02f, 0.0f)); //particle->setDeltaRotation(D3DXVECTOR3(0.0f, 0.0f, (rand() % 100)/500.0f - 0.025f)); //particle->setDecayRotation(1.0f); particle->setDeathTime( 500 ); m_Objects.push_back( particle ); } } } testObjects.erase( testObjects.begin() ); } // Call update on objects for (objects_vec::iterator it = m_Objects.begin(); it != m_Objects.end(); ++it) { CGameObject *obj = *it; if ( obj->isDead() ) { // FIXME: // Should remove from list, skip for now continue; } obj->update(); } if (m_NumRocks == 0) game->nextLevel(); }
int main ( int argc, char *argv[] ) { testObjects(); return 0; }