// Now lets start with irrKlang 3D sound engine example 01, demonstrating simple 2D sound. // Start up the sound engine using createIrrKlangDevice(). You can specify several // options as parameters when invoking that function, but for this example, the default // parameters are enough. int main(int argc, const char** argv) { // start the sound engine with default parameters ISoundEngine* engine = createIrrKlangDevice(); if (!engine) { printf("Could not startup engine\n"); return 0; // error starting up the engine } // To play a sound, we only to call play2D(). The second parameter // tells the engine to play it looped. // play some sound stream, looped engine->play2D("../../media/getout.ogg", true); // In a loop, wait until user presses 'q' to exit or another key to // play another sound. printf("\nHello World!\n"); do { printf("Press any key to play some sound, press 'q' to quit.\n"); // play a single sound engine->play2D("../../media/bell.wav"); } while(getch() != 'q'); // After we are finished, we have to delete the irrKlang Device created earlier // with createIrrKlangDevice(). Use ::drop() to do that. In irrKlang, you should // delete all objects you created with a method or function that starts with 'create'. // (an exception is the play2D()- or play3D()-method, see the documentation or the // next example for an explanation) // The object is deleted simply by calling ->drop(). engine->drop(); // delete engine return 0; }
// irrKlang 3D sound engine example 03, // demonstrating playing sounds directly from memory int main(int argc, const char** argv) { // start the sound engine with default parameters ISoundEngine* engine = createIrrKlangDevice(); if (!engine) return 0; // error starting up the engine #ifdef __BIG_ENDIAN__ printf("This example won't work on Power-PCs because the way we are "\ "storing the wave data in this example source file. Sorry."); return 0; #endif // To make irrKlang know about the memory we want to play, we register // the memory chunk as a sound source. We specify the name "testsound.wav", so // we can use the name later for playing back the sound. Note that you // could also specify a better fitting name like "ok.wav". // The method addSoundSource() also returns a pointer to the created sound source, // it can be used as parameter for play2D() later, if you don't want to // play sounds via string names. engine->addSoundSourceFromMemory(memorySoundData, memorySoundDataSize, "testsound.wav"); // now play the sound until user presses escape printf("\nPlaying sound from memory.\n"); printf("Press any key to play, ESCAPE to end program.\n"); while(true) // endless loop until user exits { // play the sound we added to memory engine->play2D("testsound.wav"); if (getch() == 27) break; // user pressed ESCAPE key, cancel } engine->drop(); // delete engine return 0; }
int main( void ) { mFx2D.Initial(); mFx2D.mPasser.bind( keytest ); ISoundEngine* sound = createIrrKlangDevice(); sound->play2D( "data/bgm.mp3", true); LOGO.init(); while( mFx2D.run() ) { mFx2D.Render( LOGO.canvas, WHITE ); if ( THREAD.status == 0 ) { THREAD.lock(); mFx2D.Render( LOGO.segs.lines ); THREAD.unlock(); } mFx2D.Render( LOGO.turtle, LOGO.curcolor ); mFx2D.fonts.Print( mFx2D.mPasser.cmd, 13.75, 15, LOGO.curcolor ); if ( mFx2D.mPasser.listen( 294 ) ) { if ( STATUS.status == 0 ) { STATUS.lock(); char cmdd[256]; strcpy( cmdd, mFx2D.mPasser.cmd.c_str() ); mFx2D.CreateThread( event, cmdd ); } } mFx2D.Updata(); } mFx2D.Release(); sound->drop(); return 0; }
int main () { // Main device // IrrlichtDevice * pMainDevice = createDevice ( video::EDT_OPENGL , core::dimension2d < u32 > ( X_SIDE, Y_SIDE ), 16, false, false, false ); if ( ! pMainDevice ) return EXIT_FAILURE; // Main audio device // ISoundEngine * pSoundEngine = createIrrKlangDevice (); if ( ! pSoundEngine ) return EXIT_FAILURE; // Initializing application context structure // sApplicationContext context; context.m_pMainDevice = pMainDevice; context.m_counter = 0; context.isInGame = false; // Initializing receiver // Global::myEventReceiver = new MyEventReceiver(&context); pMainDevice->setEventReceiver ( Global::myEventReceiver ); // Adding receiver to device pMainDevice->setWindowCaption ( L"Space Battle" ); // Text on the top of the application pMainDevice->setResizable ( false ); // Disabling window resizing // Getting all main controll componets // // Static part // Global::spVideoDriver = pMainDevice->getVideoDriver (); // Other part // scene::ISceneManager * pSceneManager = pMainDevice->getSceneManager (); scene::ICameraSceneNode * pCamera = pSceneManager->addCameraSceneNode (); gui::IGUIEnvironment * pGUIEnvironment = pMainDevice->getGUIEnvironment(); // Vector for controling all animators // std::vector < scene::ISceneNodeAnimator * > pAnimators; // Setting the main menu audio // //pSoundEngine->play2D ( "audio\\ophelia.mp3", true ); // Random number for choosing an enemie texture // srand ( time ( NULL ) ); // Camera positioning and targeting // pCamera->setPosition ( core::vector3df ( 0, 0, 200 ) ); pCamera->setTarget ( core::vector3df ( 0, 0, 0 ) ); ////////////////////////////// f32 fov = pCamera->getFOV (); leftBorder = pCamera->getPosition ().Z * tan ( fov / 2 ); rightBorder = - leftBorder; ////////////////////////////// // Background cube // scene::IMeshSceneNode * pCube = pSceneManager->addCubeSceneNode ( 1, nullptr, -1, core::vector3df ( 0, 0, -15 ) ); pCube->setScale ( core::vector3df ( X_SIDE / 2, Y_SIDE / 2, 0.1f ) ); pCube->setMaterialFlag ( video::EMF_LIGHTING, false ); video::ITexture * pTexture = Global::spVideoDriver->getTexture ( "export\\background.tga" ); pCube->setMaterialTexture ( 0, pTexture ); // Border for rockets // // for fighter scene::IMeshSceneNode * pWorldBorder = pSceneManager->addCubeSceneNode ( X_SIDE, nullptr, -1, irr::core::vector3df ( 0, 220, 0 ), irr::core::vector3df ( 0, 0, 0 ), irr::core::vector3df ( X_SIDE, 0.001f, 2 ) ); // For enemies scene::IMeshSceneNode * pWorldBorderEnemieRockets = pSceneManager->addCubeSceneNode ( X_SIDE , nullptr, -1 , irr::core::vector3df ( 0, -220, 0 ) , irr::core::vector3df ( 0, 0, 0 ) , irr::core::vector3df ( X_SIDE, 0.001f, 2 ) ); // Rockets manager set // // for fighter rockets cRocketManager rockets ( pSceneManager, pMainDevice, "export\\rocket.X", pWorldBorder ); // for enemies rockets cRocketManager enemieRockets ( pSceneManager, pMainDevice, "export\\rocket.X" , pWorldBorderEnemieRockets, false ); // Fighter set // cFighterSceneNode * pFighter = new cFighterSceneNode ( pSceneManager, "export\\fighter.X", 3, MOVEMENT_SPEED, core::vector3df ( 0, downBorder, 0 ), // Position core::vector3df ( 0, 180, 0 ), // Rotation core::vector3df ( 1.0f, 1.0f, 1.0f ) ); // Scale pFighter->setTexture ( "export\\fighter.tga", Global::spVideoDriver ); // Enemie set // cEnemieNodeManager enemieManager ( pMainDevice ); enemieManager.addEnemieType ( "export\\enemies_01" ); enemieManager.addEnemieType ( "export\\enemies_02" ); enemieManager.addEnemieType ( "export\\enemies_03" ); enemieManager.addEnemieType ( "export\\enemies_04" ); // For statisctic. Font, billboard text // gui::IGUIFont * pFont = pGUIEnvironment->getFont ( "export\\fonthaettenschweiler.bmp" ); scene::IBillboardTextSceneNode * pTextVictory = pSceneManager->addBillboardTextSceneNode ( pFont , L"You won!" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 40, 10 ) ); scene::IBillboardTextSceneNode * pTextToExit = pSceneManager->addBillboardTextSceneNode ( pFont , L"Press ESCAPE to exit" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, -20, 10 ) ); scene::IBillboardTextSceneNode * pTextEnemiesKilled = pSceneManager->addBillboardTextSceneNode ( pFont , L"temp" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 20, 10 ) ); scene::IBillboardTextSceneNode * pTextRocketsLaunched = pSceneManager->addBillboardTextSceneNode ( pFont , L"temp" , nullptr, core::dimension2df ( 100, 10 ), core::vector3df ( 0, 0, 10 ) ); pTextVictory->setVisible ( false ); pTextToExit->setVisible ( false ); pTextEnemiesKilled->setVisible ( false ); pTextRocketsLaunched->setVisible ( false ); // Createing the main menu // MainMenu* mainMenu = new MainMenu(pGUIEnvironment); // Before the main loop starts // bool isPressed = false; bool isLaunched = false; // for rocket bool isEnemieRocketLauched = false; // for enemie rockets bool isEnd = false; // For drawing stats bool isThrusterSoundActive = false; unsigned int currentSelectedGameLevel = 0; bool isLevelFinished = false; bool isEnemiesCreated = false; // Cheking if enemies creation, to avoid multiple creation of enemies group int rocketsCount = 0; int rocketsArraySize = rockets.getArraySize(); wchar_t buf [25]; cTimer timer ( pMainDevice ); // Prepearing sound source // ISound * pSoundThruster = nullptr; enemieRockets.cleareRocketsAnimators (); enemieRockets.addAnimatorsToRockets ( pFighter, pWorldBorderEnemieRockets ); /////////////// Main loop /////////////// while ( pMainDevice->run () ) { //if ( pMainDevice->isWindowActive () ) { if ( context.isInGame ) // is game started { #if !defined(_DEBUG) // Start playing the thrusters sound // if ( ! isThrusterSoundActive ) { pSoundThruster = nullptr; pSoundThruster = pSoundEngine->play2D ( "audio\\140582__lg__a320-engines-running-111228.wav" , true, false, true ); isThrusterSoundActive = true; } #endif isEnemiesCreated = (currentSelectedGameLevel == context.currentLevel) && !isLevelFinished; if ( ! isEnemiesCreated && ! isEnd ) { enemieManager.clearEnemiesVector (); setEnemiesFleeet ( & pAnimators, & enemieManager, pSceneManager, &context ); rockets.cleareRocketsAnimators (); rockets.addAnimatorsToRockets ( & enemieManager, pWorldBorder ); currentSelectedGameLevel = context.currentLevel; isLevelFinished = false; } // Cheking if victory and showing stats if ( enemieManager.getVectorSize () == 0 ) { rockets.reload (); if ( ! isEnd ) { isEnd = true; isLevelFinished = true; pTextVictory->setText ( L"You won!!!" ); pTextToExit->setText ( L"Press ESCAPE to exit" ); // enemie killed count swprintf ( buf, 20, L"Enemies killed: %d" , enemieManager.getNEnemiesKilled () ); pTextEnemiesKilled->setText ( buf ); * buf = '\0'; // String clear // rockets launched count swprintf ( buf, 25, L"Rockrets launched: %d" , pFighter->getNRocketsLaunched () ); pTextRocketsLaunched->setText ( buf ); * buf = '\0'; // String clear enemieManager.reloadNEnemiesKilled (); pFighter->reloadNRocketsLaunched (); pTextVictory->setVisible ( true ); pTextToExit->setVisible ( true ); pTextEnemiesKilled->setVisible ( true ); pTextRocketsLaunched->setVisible ( true ); } } // If exiting make all invisible // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_ESCAPE ) && isEnd ) { context.isInGame = false; isLevelFinished = true; isEnd = false; pTextVictory->setText ( L"" ); pTextToExit->setText ( L"" ); pTextEnemiesKilled->setText ( L"" ); pTextRocketsLaunched->setText ( L"" ); pTextVictory->setVisible ( false ); pTextToExit->setVisible ( false ); pTextEnemiesKilled->setVisible ( false ); pTextRocketsLaunched->setVisible ( false ); pFighter->getMeshSceneNode ()->setPosition ( core::vector3df ( 0, downBorder, 0 ) ); for ( int i = 0; i < rockets.getArraySize (); i++ ) rockets.getRockets()->at ( i )->getMeshSceneNode ()->setPosition ( core::vector3df ( 0, upBorder + 100, 0 ) ); // Pausing thrusters sound // if(pSoundThruster) { pSoundThruster->stop (); pSoundThruster->drop (); pSoundThruster = nullptr; } isThrusterSoundActive = false; continue; } if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_ESCAPE ) && ! isEnd ) { context.isInGame = false; #if !defined(_DEBUG) // Pausing thrusters sound // pSoundThruster->stop (); pSoundThruster->drop (); pSoundThruster = nullptr; isThrusterSoundActive = false; #endif } float currentSpeed = pFighter->getSpeed (); // getting the cuurrent speed of the fighter // Ghange!!! core::vector3df nodePosition = pFighter->getMeshSceneNode ()->getPosition (); // getting fighter position // Side movement // if ( ! isEnd ) { float deltaTime = (f32)timer.getDeltaTime() / 100; if ( Global::myEventReceiver->IsKeyDown(irr::KEY_KEY_A) || Global::myEventReceiver->IsKeyDown(irr::KEY_LEFT) ) { nodePosition.X += currentSpeed * deltaTime; } if ( Global::myEventReceiver->IsKeyDown(irr::KEY_KEY_D) || Global::myEventReceiver->IsKeyDown(irr::KEY_RIGHT)) { nodePosition.X -= currentSpeed * deltaTime; } if ( nodePosition.X < leftBorder && nodePosition.X > rightBorder ) pFighter->getMeshSceneNode ()->setPosition ( nodePosition ); // Collison cheking // int animatorCount = collisionChek ( & rockets ); if (!(animatorCount == -1 || animatorCount == 0 )) { enemieManager.increaseNEnemiesKilled (); core::vector3df collisionPosition = enemieManager.getEnemie ( animatorCount - 1 )-> getMeshSceneNode ()->getPosition (); addExplosion ( collisionPosition, core::vector3df ( 0, 0, 0 ) , 10, pSceneManager, core::plane3df ( 1, 0, 0, 0, 0, 0 ), nullptr ); pSoundEngine->play2D ( "audio\\explosion.flac", false ); enemieManager.getEnemie ( animatorCount - 1 )->getMeshSceneNode ()->setVisible ( false ); enemieManager.getEnemie ( animatorCount - 1 )->drop (); enemieManager.getVector()->erase ( enemieManager.getVector ()->begin () + animatorCount - 1 ); rockets.cleareRocketsAnimators (); rockets.addAnimatorsToRockets ( & enemieManager, pWorldBorder ); } animatorCount = collisionChek ( & enemieRockets ); if (!( animatorCount == 0 || animatorCount == -1 )) { addExplosion ( pFighter->getMeshSceneNode()->getPosition () , core::vector3df ( 0, 0, 0 ), 10 , pSceneManager, core::plane3df ( 1, 0, 0, 0, 0, 0 ), nullptr ); pSoundEngine->play2D ( "audio\\explosion.flac", false ); pTextVictory->setText ( L"You Lose!!!" ); isEnd = true; isEnemiesCreated = true; // enemie killed count swprintf ( buf, 20, L"Enemies killed: %d" , enemieManager.getNEnemiesKilled () ); pTextEnemiesKilled->setText ( buf ); * buf = '\0'; // String clear // rockets launched count swprintf ( buf, 25, L"Rockrets launched: %d" , pFighter->getNRocketsLaunched () ); pTextRocketsLaunched->setText ( buf ); * buf = '\0'; // String clear enemieManager.reloadNEnemiesKilled (); pFighter->reloadNRocketsLaunched (); pTextToExit->setText ( L"Press ESCAPE to exit" ); pTextVictory->setVisible ( true ); pTextToExit->setVisible ( true ); pTextEnemiesKilled->setVisible ( true ); pTextRocketsLaunched->setVisible ( true ); } // Fire // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && ! isLaunched ) { isLaunched = true; printf ( "Fighter: rocket %d launched on %f, %f, %f\n", rocketsCount++, pFighter->getMeshSceneNode()->getPosition ().X, pFighter->getMeshSceneNode()->getPosition ().Y, pFighter->getMeshSceneNode()->getPosition ().Z ); pFighter->launch ( & rockets, Global::spVideoDriver ); pSoundEngine->play2D ( "audio\\rocket_launch.mp3" ); } else if ( ! Global::myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && isLaunched ) isLaunched = false; /*if ( myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && ! isLaunched ) { isLaunched = true; printf ( "Fighter: rocket %d launched on %f, %f, %f\n", rocketsCount++, pFighter->getMeshSceneNode()->getPosition ().X, pFighter->getMeshSceneNode()->getPosition ().Y, pFighter->getMeshSceneNode()->getPosition ().Z ); pFighter->launch ( & rockets, pVideoDriver ); } else if ( ! myEventReceiver->IsKeyDown ( irr::KEY_SPACE ) && isLaunched ) isLaunched = false;*/ if ( rockets.getUsed () == rocketsArraySize ) { rockets.reload (); //rocketsCount = 0; } if ( timer.calculateDeltaTime () > 1000 && enemieManager.getVectorSize () != 0 ) { /*if ( myEventReceiver->IsKeyDown ( irr::KEY_KEY_Q ) ) printf ( "DEBUG: debugin stop\n" );*/ timer.calculateTime (); int i = rand () % enemieManager.getVectorSize (); // misstake enemieManager.getEnemie ( i )->launch ( & enemieRockets, Global::spVideoDriver ); } else if ( enemieManager.getVectorSize () == 0 ) printf ( "DEBUG: vector size = %d\n", enemieManager.getVectorSize () ); } } // is game started // DEBUG // if ( Global::myEventReceiver->IsKeyDown ( irr::KEY_KEY_G ) && ! isPressed ) { isPressed = true; printf ( "DEBUG: Fighter position - %f\n", pFighter->getMeshSceneNode()->getPosition().X ); } if ( ! Global::myEventReceiver->IsKeyDown ( irr::KEY_KEY_G ) && isPressed ) isPressed = false; // Drawing // Global::spVideoDriver->beginScene ( true, true, video::SColor ( 0, 255, 255, 255 ) ); if ( context.isInGame ) { pSceneManager->drawAll (); } else { pGUIEnvironment->drawAll (); } // Drawing stoped // Global::spVideoDriver->endScene (); } } /////////////// Main loop /////////////// delete mainMenu; // Clrearing // pFighter->drop (); pSoundEngine->drop (); pMainDevice->drop (); /// ------- /// return EXIT_SUCCESS; }
void BasicApp::shutdown() { engine->drop(); }
int main(int argc, const char** argv) { /* - deviceType: Type of the device. This can currently be the Null-device, one of the two software renderers, D3D8, D3D9, or OpenGL. In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL. */ MyEventReceiver receiver; ISoundEngine* music = createIrrKlangDevice(); IrrlichtDevice *device = createDevice( EDT_DIRECT3D9, dimension2d<u32>(640, 480), 32, false, false, false, &receiver); music->play2D("../media/MUSIC/Dark Impetus.mp3",true,false,true); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); IGUIEnvironment* guienv = device->getGUIEnvironment(); ICameraSceneNode *camera = smgr->addCameraSceneNode(); IGUIFont* font = device->getGUIEnvironment()->getFont("../media/fonthaettenschweiler.bmp"); camera->setFarValue(900); IAnimatedMesh* map = smgr->getMesh(DC_01); IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode(map); mapnode->setMaterialFlag(EMF_LIGHTING,false); IAnimatedMesh* player1 = smgr->getMesh(SORA); IAnimatedMeshSceneNode* p1node = smgr->addAnimatedMeshSceneNode(player1); p1node->setMaterialFlag(EMF_LIGHTING, false); p1node->setScale(SORA_VECTOR3D); IAnimatedMesh* player2 = smgr->getMesh(AQUA); IAnimatedMeshSceneNode* p2node = smgr->addAnimatedMeshSceneNode(player2); p2node->setMaterialFlag(EMF_LIGHTING, false); p2node->setScale(NORMAL_VECTOR3D); vector3df Position = p1node->getPosition(); vector3df P2Pos = p2node->getPosition(); vector3df PosCam = p1node->getPosition(); vector3df Rotate = p1node->getPosition(); int CurrentHP = 300; int MaxHP = 400; int HeartP = 10; bool LockOn = false; bool LockCheck = false; stringw CoorCheck; while(device->run()) { CoorCheck +=L"Your position\nX:"; CoorCheck +=Position.X; CoorCheck +=L"\nY:"; CoorCheck +=Position.Y; CoorCheck +=L"\nZ:"; CoorCheck +=Position.Z; CoorCheck +=L"\n\nTarget Position:"; CoorCheck +=P2Pos.X; if(LockCheck != true){ if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = true; LockCheck = true;}} else{ if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = false;LockCheck = false;}} //3D Rendering. MaximizeKey(receiver,device); GetCaption(driver,device); driver->beginScene(true, true, SColor(255,100,101,140)); p1node->setPosition(Position); camera->setPosition(vector3df(PosCam.X,PosCam.Y+2,PosCam.Z+3)); if(LockOn != false){camera->setTarget(P2Pos);} else{camera->setTarget(Position);} smgr->drawAll(); //2D Rendering. if(CurrentHP<=0){font->draw(L"You are dead!!!",rect<s32>(120,140,250,210),SColor(255,255,255,255));} else{if(receiver.IsKeyDown(KEY_KEY_L)){--CurrentHP;}} if(CurrentHP>=MaxHP){}else{if(receiver.IsKeyDown(KEY_KEY_K)){++CurrentHP;}} if(receiver.IsKeyDown(KEY_KEY_N)){++MaxHP;} if(receiver.IsKeyDown(KEY_KEY_M) && CurrentHP<MaxHP){--MaxHP;} if(HeartP>=86){}else{ if(receiver.IsKeyDown(KEY_KEY_F)){++HeartP;}} font->draw (L"Press O for full screen.\nPress Up-Down-Left-right to move.\nPress L to hurt the character.\nPress K to heal the character.\nPress N to increase Max HP.\nPress M to decrease Max HP.\nPress F to fill the Heart gauge.",rect<s32>(20,40,150,110),SColor(255,0,0,0)); font->draw(CoorCheck,rect<s32>(20,140,150,110),SColor(255,0,0,0)); //Button detection. if(receiver.IsKeyDown(KEY_UP)){ Position.Z -= 0.1f; PosCam.Z = Position.Z; p1node->setRotation(vector3df(Rotate.X,Rotate.Y = 0,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_DOWN)){ Position.Z += 0.1f; PosCam.Z = Position.Z; p1node->setRotation(vector3df(Rotate.X,Rotate.Y -180,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_LEFT)){ Position.X += 0.1f; PosCam.X = Position.X; p1node->setRotation(vector3df(Rotate.X,Rotate.Y -90,Rotate.Z)); p1node->setPosition(Position);} if(receiver.IsKeyDown(KEY_RIGHT)){ Position.X -= 0.1f; PosCam.X = Position.X; p1node->setRotation(vector3df(Rotate.X,Rotate.Y +90,Rotate.Z)); p1node->setPosition(Position);} HUD_Display(device,driver,receiver,font,CurrentHP,MaxHP,HeartP); guienv->drawAll(); CoorCheck = L""; driver->endScene(); } music->drop(); device->drop(); return 0; }