void MyProgram::createNewEnemy(const float timeDelta) { countNewEnemyTime+=timeDelta; if(countNewEnemyTime>levelTime/2+1) { countNewEnemyTime=0; int num=rand()%numEnemy+numEnemy/2; for (int i = 0 ; i < num ; ++i) { int rFactor0=rand(); int rFactor1=rand(); char name[200]; sprintf(name, "Asteroid%d", countNewEnemy++); Vector3 pos; if(rFactor0%2==0) { if(rFactor1%2==0) pos = Vector3(rFactor0%pXpos, nYpos, -150); else pos = Vector3(rFactor0%pXpos, pYpos, -150); } else { if(rFactor1%2==0) pos = Vector3(nXpos, rFactor0%pYpos, -150); else pos = Vector3(pXpos, rFactor1%pYpos, -150); } Asteroid * asteroid = new Asteroid(_sceneManager, & pos, name,rand()%3,true); asteroid->myPos=pos; asteroid->isAlive=true; asteroid->isBig=true; asteroid->mySpeed=originAsteriodSpeed; asteroid->randomDirection(); allAsteroids.push_back(asteroid); } } }
void MyProgram::rebuildGame() { EleTime = OverlayManager::getSingleton().getOverlayElement("TimeLeft"); myPlayer->myPos.x=0; myPlayer->myPos.y=-100; myPlayer->myPos.z=-150; myPlayer->myFiring=false; myPlayer->myHP=MAXHP; myPlayer->mySceneNode->setPosition(myPlayer->myPos); myPlayer->mySpeed=originPlayerSpeed; myPlayer->myDirection=Vector3(0,1,0); myPlayer->myDirection.normalise(); // set asteriod int start, interval; start = -350; interval = 60; if(gameLevel==0) numEnemy=minEnemy; else if(gameLevel==1) numEnemy=maxEnemy; for (int i = 0 ; i < numEnemy ; ++i) { char name[200]; sprintf(name, "Asteroid%d", countNewEnemy++); Vector3 pos = Vector3(start + i * interval, 80, -150); Asteroid * asteroid = new Asteroid(_sceneManager, & pos, name,rand()%3,true); asteroid->myPos=pos; asteroid->isAlive=true; asteroid->mySpeed=originAsteriodSpeed; asteroid->randomDirection(); asteroid->myTimeDelta=0; allAsteroids.push_back(asteroid); string path2 = "Explode.wav"; //string path4 = "Celebrate.wav"; //string path5 = "GameOver.wav"; // Do this once for every sound you want to play fmodSystem->createSound(path2.c_str(), FMOD_2D, 0, &sound2); //fmodSystem->createSound(path4.c_str(), FMOD_2D, 0, &passSound); //fmodSystem->createSound(path5.c_str(), FMOD_2D, 0, &overSound); soundCount = 0; // Do this to play the sound } Vector3 tempFishPos=Vector3(0, -80, -160); for(int i=0;i<numBullet;++i) { char name[200]; sprintf(name,"Bullet%d",countBullet++); Bullet * bullet = new Bullet(_sceneManager, tempFishPos,name); bullet->used=false; bullet->mySceneNode->setVisible(false); bullet->myPos=myPlayer->myPos; bullet->myDirection=myPlayer->myDirection; bullet->mySpeed=originBulletSpeed; allBullet.push_back(bullet); } // some factor myTimeDelta=0; // for bullet delay explosionTime=0; // for explosion delay isExplosion=false; gameOver=false; // is game over // for player reborn bReborn = true; rebornPause = 60; bMove = true; countNewEnemyTime=0; win = false; if(gameLevel==0) { levelTime=TIME1; flagForShowlevel1=true; } else if(gameLevel==1) { levelTime=TIME2; flagForShowlevel2=true; } time=levelTime; flagForGameLevel=false; }