//count = 0 is infinte
void CAudioManager::PlayStream(int id, int count){
  if(m_bValidAudio == false)
    return;

  for(int i = 0; i < m_Stream.size(); i++){
    if(m_Stream[i].AudioID == id){
      FSOUND_Stream_SetLoopCount(m_Stream[i].handle, count);
      FSOUND_Stream_Play(m_Stream[i].AudioID, m_Stream[i].handle);
    }
  }
}
Exemplo n.º 2
0
void StateLevel::handleEvents()
{
	if ( SDL_PollEvent(&event) )
	{
		if ( event.type == SDL_QUIT ) setNextGameState(0);

		if ( event.type == SDL_KEYUP )
		{
            if ( event.key.keysym.sym == SDLK_ESCAPE ) setNextGameState (2);
            if ( event.key.keysym.sym == SDLK_SPACE && ( (o_player.b_die == true) || (o_player.b_win == true )) ) b_go = true;
            if ( event.key.keysym.sym == SDLK_r ) b_restart = true;
		}
            if ( o_player.b_die == false && o_player.b_win == false ) o_player.handleEvents();

        if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_m )
		{
		    if ( b_music == true )
		    {
		        FSOUND_Stream_Stop(song2);

		        b_music = false;
		    }

		    else if ( b_music == false )
		    {
		        FSOUND_Stream_Play( 1, song2 );
                FSOUND_Stream_SetLoopCount(song2,-1);

                b_music = true;

		    }

		}




	}

}
Exemplo n.º 3
0
void StateMenu::handleEvents()
{
	if ( SDL_PollEvent(&event) )
	{

		if ( event.type == SDL_QUIT )
		{
			setNextGameState(0);
		}

		if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_m )
		{
		    if ( b_music == true )
		    {
		        FSOUND_Stream_Stop(song2);

		        b_music = false;
		    }

		    else if ( b_music == false )
		    {
		        FSOUND_Stream_Play( 1, song2 );
                FSOUND_Stream_SetLoopCount(song2,-1);

                b_music = true;

		    }

		}

		if ( event.type == SDL_MOUSEBUTTONUP )
		{
			if ( event.button.button == SDL_BUTTON_LEFT )
			{
				int x,y;
				SDL_GetMouseState(&x,&y);

				Box mouse;
				mouse.x = (float)x;
				mouse.y = (float)y;
				mouse.w = 1;
				mouse.h = 1;

				if ( checkCollisionQuads( mouse, play ) )
				{
					setNextGameState(8);
				}

				else if ( checkCollisionQuads( mouse, select ) )
				{
					setNextGameState(5);
				}

				else if ( checkCollisionQuads( mouse, editor ) )
				{
					setNextGameState(4);
				}

				else if ( checkCollisionQuads( mouse, exit ) )
				{
					setNextGameState(0);
				}
			}
		}

	}

}
Exemplo n.º 4
0
int main ( int argc, char* args[] )
{
	init();

	srand(time(NULL));

	int FPS = 0;

	///////GLOBAL LOADING
	tex_spikes = loadTexture("data/gfx/Spikes.png");
	tex_block1 = loadTexture("data/gfx/block1.png");
	tex_menu = loadTexture("data/gfx/menu.png");
	tex_playgame = loadTexture("data/gfx/playgame.png");
	tex_selectlevel = loadTexture("data/gfx/selectlevel.png");
	tex_editor = loadTexture("data/gfx/editor.png");
	tex_exit = loadTexture("data/gfx/exitmenu.png");
	tex_player1 = loadTexture("data/gfx/player.png");
	tex_door = loadTexture("data/gfx/door.png");
	tex_font = loadTexture("data/gfx/font.png");
	tex_done = loadTexture("data/gfx/ok.png");
	tex_gold = loadTexture("data/gfx/gold.png");
	tex_silver = loadTexture("data/gfx/silver.png");
	tex_bronze = loadTexture("data/gfx/bronze.png");
	tex_eyes = loadTexture("data/gfx/playgame.png");
	tex_arrow = loadTexture("data/gfx/arrow.png");
	tex_info = loadTexture("data/gfx/info.png");


	///////soundsss
	sample_playerJump = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/jump.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerJump, -1,100,-1,-1);
	sample_playerHit = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/hit.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerHit, -1,100,-1,-1);
	sample_playerForce = FSOUND_Sample_Load(FSOUND_UNMANAGED,"data/sfx/force.wav",0,0,0);
	FSOUND_Sample_SetDefaults(sample_playerForce, -1,100,-1,-1);

	song2 = FSOUND_Stream_Open( "data/music/Random-SitgesSavepoint.mp3",FSOUND_LOOP_NORMAL,0,0);

	FSOUND_Stream_Play( 1, song2 );
	FSOUND_Stream_SetLoopCount(song2,-1);

	//FSOUND_SetVolume(1,80);

	std::ifstream file ("data/levels/score.lvl");

	while ( !file.eof() )
	{
		o_scores.push_back(new Score());

		file >> o_scores.back()->i_number;
		file >> o_scores.back()->b_unlocked;
		file >> o_scores.back()->i_highScore;
		file >> o_scores.back()->i_B;
		file >> o_scores.back()->i_S;
		file >> o_scores.back()->i_G;

	}

	file.close();

	//o_scores.pop_back();


	gameState = new StateMenu();
	currentGameState = STATE_MENU;



/*
	for ( int n = 0; n < 100; n++ )
	{
		o_scores.push_back( new Score () );
		o_scores.back()->b_unlocked = true;
		o_scores.back()->i_highScore = 0;
		o_scores.back()->i_B = 0;
		o_scores.back()->i_G = 0;
		o_scores.back()->i_S = 0;
	}*/

	//saving

	FPSA = SDL_GetTicks();

	while ( nextGameState != STATE_EXIT )
	{

		FPS = SDL_GetTicks();

		gameState->handleEvents();

		gameState->logic();

		FPSA = SDL_GetTicks();

		gameState->render();

		changeGameState();



		////////////////////////////
		if ( (SDL_GetTicks() - FPS) < 1000/60 )
		{
			//SDL_Delay( ( 1000/60) - (SDL_GetTicks() - FPS) );
		}
		SDL_Delay(2);

	}

    FSOUND_Stream_Close(song2);
	FSOUND_Close();

	return 0;
}