Example #1
0
int main(int argc, char** argv){
    
    // start irrKlang with default parameters
    ISoundEngine* engine = createIrrKlangDevice();
    if (!engine)
        return 0; // error starting up the engine
    
    // play some sound stream, looped
    engine->play2D("Tetris.wav", true);
    
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGBA | GLUT_3_2_CORE_PROFILE);
    
    glutInitWindowSize(windowWidth, windowHeight);
    
    glutCreateWindow("Tetrino");
    
    game = new Game();
    game->init(windowWidth, windowHeight, blocksize);
    
    glutDisplayFunc(display);
    
    glutSpecialFunc(keyboardControl);
    
    glutTimerFunc(timeInterval, gravityMove, 0);
    
    glutIdleFunc(glutPostRedisplay);
    
    glutMainLoop();
    
    //engine->drop(); // delete engine
    
    return 0;
}
Example #2
0
// 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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
0
int main( int argc, char **argv) {
	ISoundEngine* engine = createIrrKlangDevice();
	
    if (!engine)
       return 0; // error starting up the engine
	engine->play2D("./musica/pedro.mp3", true);
	glutInit(&argc,argv);
	if(init(WIN_POSX,WIN_POSY,WIN_WIDTH,WIN_HEIGHT,"ARM Pedro Infante") == -1){
		system("pause");
		return -1;
	}
	glutDisplayFunc(render);
	glutIdleFunc(idle);
	glutReshapeFunc(redimensiona);
    glutSpecialFunc(keyboardSpec);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouseClick);
    glutMotionFunc(mouseDrag);
	defineLuces();
	defineCamaras();
    creaEscena();
	glutMainLoop();
	return 0;
}
Example #6
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();

}
void BasicApp::update()
{

	if (game_state == Game_Demo)
	{

		for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
		{
			itr->Update();

		}

	}
	else if(game_state == GAME_Play)
	{
		for (list<Asteroid>::iterator itr = asteroids.begin(); itr!=asteroids.end(); itr++)
		{
			itr->Update();

		}

		for (list<Bullet>::iterator itr_bullet = currentShip.m_Bullets.begin(); itr_bullet!=currentShip.m_Bullets.end();)
		{

			for (list<Asteroid>::iterator itr_astroid = asteroids.begin(); itr_astroid!=asteroids.end();)
			{
				if(checkCollision(itr_bullet->getCenter(),itr_astroid->getCenter(), itr_bullet->getRadius(), itr_astroid->getRadius()))
				{

					particleManager.Start_Explosion(itr_astroid->getCenter(),10,1.0f,1.0f);
				
					engine->play2D("explode_high.wav");
				

					if(itr_astroid->m_size >= 0.5)
					{
						Asteroid asteroid_1, asteroid_2;

						asteroid_1.m_state = Asteroid_Medium;
						asteroid_1.Init(rand()%2+1, 0.3);
						asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*1.5;
						asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*1.5;
						asteroid_1.m_Pos = itr_astroid->m_Pos;

						asteroid_2.m_state = Asteroid_Medium;
						asteroid_2.Init(rand()%2+1, 0.3);
						asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*1.5;
						asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*1.5;
						asteroid_2.m_Pos = itr_astroid->m_Pos;


						asteroids.push_back(asteroid_1);
						asteroids.push_back(asteroid_2);


						itr_astroid = asteroids.erase(itr_astroid);
						itr_astroid->m_bHit = true;

						score +=100;

					}
					else if(itr_astroid->m_state == Asteroid_Medium)
					{
						Asteroid asteroid_1, asteroid_2;
						asteroid_1.m_state = Asteroid_Small;
						asteroid_1.Init(rand()%2+1, 0.1);
						asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*2;
						asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*2;
						asteroid_1.m_Pos = itr_astroid->m_Pos;
						asteroid_2.m_state = Asteroid_Small;
						asteroid_2.Init(rand()%2+1, 0.1);
						asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*2;
						asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*2;
						asteroid_2.m_Pos = itr_astroid->m_Pos;
						asteroids.push_back(asteroid_1);
						asteroids.push_back(asteroid_2);
						itr_astroid = asteroids.erase(itr_astroid);
						itr_astroid->m_bHit = true;

						score +=100;

					}
					else
					{
						score +=50;
						itr_astroid->m_bHit = true; 
						itr_astroid = asteroids.erase(itr_astroid);
					}

					itr_bullet->m_Hit = true;

					break;
				}
				else
				{
					itr_astroid++;

				}
			}
			if(itr_bullet->m_Hit)
			{
				itr_bullet = currentShip.m_Bullets.erase(itr_bullet);
			}
			else
			{
				itr_bullet++;

			}

		}

		if(shipCollision)
		{
			for (list<Asteroid>::iterator itr_astroid = asteroids.begin(); itr_astroid!=asteroids.end(); )
			{
				if(currentShip.m_state == Ship::Ship_Alive)
				{

					if(checkCollision(itr_astroid->getCenter(), currentShip.getCenter(), itr_astroid->getRadius(), currentShip.getRadius() ))
					{

						particleManager.Start_Explosion(currentShip.getCenter(),10,0.3f,1.0f);
						particleLineManager.Init(currentShip.getCenter());

						engine->play2D("explode_high.wav");

						currentShip.m_state = Ship::Ship_Dead;
						currentShip.m_Pos.x = -getWindowWidth()/2;
						currentShip.m_Pos.y = -getWindowHeight()/2;

						if(ships.size()>0)
						{
							ships.pop_back();
						}

						if(itr_astroid->m_size >= 0.5)
						{
							Asteroid asteroid_1, asteroid_2;

							asteroid_1.m_state = Asteroid_Medium;
							asteroid_1.Init(rand()%2+1, 0.3);
							asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*1.5;
							asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*1.5;
							asteroid_1.m_Pos = itr_astroid->m_Pos;

							asteroid_2.m_state = Asteroid_Medium;
							asteroid_2.Init(rand()%2+1, 0.3);
							asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*1.5;
							asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*1.5;
							asteroid_2.m_Pos = itr_astroid->m_Pos;


							asteroids.push_back(asteroid_1);
							asteroids.push_back(asteroid_2);


							itr_astroid = asteroids.erase(itr_astroid);
							itr_astroid->m_bHit = true;

							score +=100;

						}
						else if(itr_astroid->m_state == Asteroid_Medium)
						{
							Asteroid asteroid_1, asteroid_2;

							asteroid_1.m_state = Asteroid_Small;
							asteroid_1.Init(rand()%2+1, 0.1);
							asteroid_1.m_Vel.y = -itr_astroid->m_Vel.y*2;
							asteroid_1.m_Vel.x = -itr_astroid->m_Vel.x*2;
							asteroid_1.m_Pos = itr_astroid->m_Pos;

							asteroid_2.m_state = Asteroid_Small;
							asteroid_2.Init(rand()%2+1, 0.1);
							asteroid_2.m_Vel.y = itr_astroid->m_Vel.y*2;
							asteroid_2.m_Vel.x = itr_astroid->m_Vel.x*2;
							asteroid_2.m_Pos = itr_astroid->m_Pos;


							asteroids.push_back(asteroid_1);
							asteroids.push_back(asteroid_2);


							itr_astroid = asteroids.erase(itr_astroid);
							itr_astroid->m_bHit = true;

							score +=100;
						}
						else
						{
							score +=50;
							itr_astroid->m_bHit = true; 
							itr_astroid = asteroids.erase(itr_astroid);
						}
						break;
					}
					else
					{
						itr_astroid++;

					} 
				}
				else
				{
					itr_astroid++;
				}
			}	
		}
	 
		currentShip.m_saveField = currentShip.m_state == Ship::Ship_Dead;

		if (currentShip.m_saveField)
		{
			for (list<Asteroid>::iterator itr_astroid = asteroids.begin(); itr_astroid!=asteroids.end(); itr_astroid++) 
			{
				float distance = itr_astroid->getCenter().distance(Vec2f(getWindowWidth() / 2, getWindowHeight() / 2));
				if (distance < 100) 
				{
					currentShip.m_saveField = false;
					break;
				}
			}        
		}

		if(ships.size()<1)
		{
			game_state = GAME_End;
		}
		if(asteroids.size()<1)
		{
			game_state = GAME_End;
		}

		currentShip.Update();
		enemy.Update();
	}


	else if ( game_state == GAME_End)
	{



	}

	Sleep(delay);

}
void BasicApp::keyDown( KeyEvent event )
{


	if(  event.getCode() == KeyEvent::KEY_RIGHT)
	{
		if(game_state == GAME_Play)
		{
		 currentShip.right = true;
		}
	}
	if( event.getCode() == KeyEvent::KEY_LEFT)
	{
		if(game_state == GAME_Play)
		{
		 currentShip.left = true;
		}
	}
	if( event.getCode() == KeyEvent::KEY_UP)
	{
		if(game_state == GAME_Play)
		{
			if(currentShip.m_state == Ship::Ship_Alive)
			{
				engine->play2D("thrust.wav");
				currentShip.m_Thrust = true;
				currentShip.up = true;
			}
		}
	}

	if(event.getCode() ==KeyEvent::KEY_SPACE)
	{

		if(game_state == GAME_Play)
		{
			if(currentShip.m_state == Ship::Ship_Alive)
			{
				engine->play2D("shot.wav");

				if(currentShip.up)
				{
					currentShip.m_Thrust = true;
				}
				currentShip.fire = true;
			}
		}
	}
	if(event.getChar() == KeyEvent::KEY_1)
	{
		delay-=10;
		if(delay<0)
			delay=1;

	}

	if(event.getChar() == KeyEvent::KEY_2)
	{
		delay+=10;

	}

	if(event.getChar()== KeyEvent::KEY_c)
	{
		toggleCircles = !toggleCircles;
	}
	 if(event.getChar()== KeyEvent::KEY_s)
	 {
		 shipCollision =!shipCollision;
	 }
}
Example #10
0
int main(int argc, char** argv)
{
    // We catch any exceptions that might occur below -- see the catch statement for more details.
    try {
        // First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when
        // publishing your application. The Hub provides access to one or more Myos.
        myo::Hub hub("com.example.hello-myo");
        std::cout << "Attempting to find a Myo..." << std::endl;

        // Next, we attempt to find a Myo to use. If a Myo is already paired in Myo Connect, this will return that Myo
        // immediately.
        // waitForAnyMyo() takes a timeout value in milliseconds. In this case we will try to find a Myo for 10 seconds, and
        // if that fails, the function will return a null pointer.
        myo::Myo* myo = hub.waitForMyo(10000);

        // If waitForAnyMyo() returned a null pointer, we failed to find a Myo, so exit with an error message.
        if (!myo) {
            throw std::runtime_error("Unable to find a Myo!");
        }
        // We've found a Myo.
        std::cout << "Connected to a Myo armband!" << std::endl << std::endl;

        // Next we construct an instance of our DeviceListener, so that we can register it with the Hub.
        DataCollector collector;

        // Hub::addListener() takes the address of any object whose class inherits from DeviceListener, and will cause
        // Hub::run() to send events to all registered device listeners.
        hub.addListener(&collector);

        //CALIBRATE FOR SIMULATED SPATIAL LOCATION
        //Copy the start position of the calibration gesture during this time.
        double roll_orient = 0;
        double yaw_orient = 0;
        for(int i=0; i<50; i++) {   //about 1 second of sampling - keep still!
            hub.run(1000/20);
            roll_orient += ROLL;
            yaw_orient += YAW;
        }
        roll_orient /= 50;
        yaw_orient /= 50;

        int hand;

        // 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
        }
        // play some sound stream, looped

        ISound *samples[3];

        samples[0] = engine->play3D("BeatK03B 70-01.wav", vec3df(0,0,0), true, false, true);
        samples[1] = engine->play3D("GrulerK03 70B-01.wav", vec3df(0,0,0), true, false, true);
        samples[2] = engine->play3D("Wind-Mark_DiAngelo-1940285615.wav", vec3df(0,0,0), true, false, true);

        for(int i = 0; i < 3; i++) {
            samples[i]->setPosition(vec3df(0,0,1));
        }

        engine->setListenerPosition(vec3df(0,0,0), vec3df(0,0,1));

        const float radius = 1;
        int currentSample = 0;
        float vol = .5;

        while(1)
        {
            // In each iteration of our main loop, we run the Myo event loop for a set number of milliseconds.
            // In this case, we wish to update our display 20 times a second, so we run for 1000/20 milliseconds.
            hub.run(1000/20);

            // After processing events, we call the print() member function we defined above to print out the values we've
            // obtained from any events that have occurred.
            //
            // printf("Press any key to play some sound, press 'q' to quit.\n");
            // play a single sound
            collector.print();

            vec3df pos3d(radius * 2*cosf(YAW + yaw_orient - M_PI/2), 0, radius * 2*x`sinf(YAW + yaw_orient - M_PI/2));

            (WHICHARM == myo::armLeft ? hand=1 : hand=-1);
            vol = hand*(-ROLL) + roll_orient + 1;

            if (vol > 1)
                vol = 1;
            if (vol < 0)
                vol = 0;

            if (CURRENTPOSE == myo::Pose::fist) {
                if (samples[currentSample]) {
                    samples[currentSample]->setPosition(pos3d);
                }
            }
            if (CURRENTPOSE == myo::Pose::fingersSpread) {
                if (samples[currentSample]) {
                    samples[currentSample]->setVolume(vol);
                }
            }
            if (CURRENTPOSE == myo::Pose::waveIn && WAVEINCOUNTER > THRESHOLD) {
                currentSample += 1;
                currentSample %= 3;
                WAVEINCOUNTER = 1;
            }

            std::cout << '[' << "Sample: " << currentSample << "    Thresh: " << WAVEINCOUNTER << "    Vol: " << vol << "   roll/yaw orient: " << roll_orient << "  " << yaw_orient << "]";

        }
        // If a standard exception occurred, we print out its message and exit.
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        std::cerr << "Press enter to continue.";
        std::cin.ignore();
        return 1;
    }
}
Example #11
0
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;
}