void Sounds::startMusicGameplay() {
	if(Settings::getInstance()->musicEnabled == false)
		return;
	if(s3eIOSBackgroundMusicAvailable() == S3E_TRUE)
		if(s3eIOSBackgroundMusicGetInt(S3E_IOSBACKGROUNDMUSIC_PLAYBACK_STATE) == S3E_IOSBACKGROUNDMUSIC_PLAYBACK_PLAYING)
			return;

	IGLog("Sounds starting gameplay music");
	
	// if gameplay music is already playing, only change song if it's been playing for a full minute
	if(gameplayPlaying) {
		if(s3eTimerGetMs() - gameplayStart <= 60000)
			return;
	}

	gameplayPlaying = true;
	gameplayStart = s3eTimerGetMs();
	stopMusic();
	char buffer[100];
	int randomSong = gameplayMusicNum;
	while(randomSong == gameplayMusicNum)
		randomSong = rand()%3;
	switch(randomSong) {
		default:
		case 0: sprintf(buffer, "gameplay1.mp3"); break;
		case 1: sprintf(buffer, "gameplay2.mp3"); break;
		case 2: sprintf(buffer, "gameplay3.mp3"); break;
	}
	if(s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
		s3eAudioPlay(buffer, 0);
}
Beispiel #2
0
void MainMenu::startGame(CTween* pTween)
{
	// Switch to game scene
	Game* game = (Game*)g_pSceneManager->Find("game");
	g_pSceneManager->SwitchTo(game);

	// Start game music

	s3eAudioPlay("audio/MainTheme.wav", 0);

	// Create new game
}
	void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
	{
		s3eResult result;
		
		result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop);
		
		if ( result == S3E_RESULT_ERROR)
		{
			if (bLoop)
			{
				result = s3eAudioPlay(pszFilePath, 1000000);
			}
			else
			{
				result = s3eAudioPlay(pszFilePath, 0);
			}
		}
		
		if ( result == S3E_RESULT_ERROR) 
		{
			IwAssert(GAME, ("Play music %s Failed. Error Code : %s", pszFilePath, s3eAudioGetErrorString()));
		}
	}
void IntroState::Init()
{
	IwGetResManager()->LoadGroup("introsprites.group");

	m_Splash1 = new Sprite("logo", false);
	m_Splash2 = new Sprite("splash2", false);

	m_TransManager = new TransitionManager();
	m_TransitionState = FADE_IN;

	if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
		s3eAudioPlay("music.mp3", 1);

	printf("IntroState initialized\n");
}
// music
void Sounds::startMusicMenu() {
	if(Settings::getInstance()->musicEnabled == false)
		return;
	if(AIRPLAY_DEVICE == AIRPLAY_DEVICE_IPHONE) {
		if(s3eIOSBackgroundMusicAvailable() == S3E_TRUE)
			if(s3eIOSBackgroundMusicGetInt(S3E_IOSBACKGROUNDMUSIC_PLAYBACK_STATE) == S3E_IOSBACKGROUNDMUSIC_PLAYBACK_PLAYING)
				return;
	}
	
	IGLog("Sounds starting menu music");
	gameplayPlaying = false;
	stopMusic();
	if(s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
		s3eAudioPlay("menu.mp3", 0);
	else
		IGLog("mp3 codec not available on this system");
}
	void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
		std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
		s3eResult result;
		
		result = s3eAudioPlayFromBuffer(g_AudioBuffer, g_AudioFileSize, bLoop ? 0 : 1);
		
		if ( result == S3E_RESULT_ERROR)
		{
			result = s3eAudioPlay(fullPath.c_str(), bLoop ? 0 : 1);
		}
		
		if ( result == S3E_RESULT_ERROR) 
		{
			IwAssert(GAME, ("Play music %s Failed. Error Code : %s", fullPath.c_str(), s3eAudioGetErrorString()));
		}
	}
Beispiel #7
0
bool CIwGameAudio::PlayMusic(const char* name, int repeat_count)
{
	if (!Available)
		return false;

	// Only play music is on
	if (!IW_GAME_AUDIO->isMusicOn())
		return false;

	// Use s3eAudio to play our music using the devices music player
	if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
	{
		if (s3eAudioPlay(name, repeat_count) != S3E_RESULT_SUCCESS)
			return false;
	}
	else
		return false;

	return true;
}
Beispiel #8
0
bool MarmaladeAmplifier::playMusic( const ConstString & _resourceMusic, float _pos, bool _looped )
{
    if( m_play == true )
    {
        this->stop();
    }

    m_loop = _looped;

    ResourceMusicPtr resourceMusic = RESOURCE_SERVICE( m_serviceProvider )
                                     ->getResourceReferenceT<ResourceMusicPtr>( _resourceMusic );

    if( resourceMusic == nullptr )
    {
        LOGGER_ERROR( m_serviceProvider )("Amplifier::playMusic can't found resource '%s'"
                                          , _resourceMusic.c_str()
                                         );

        return false;
    }

    const ConstString & category = resourceMusic->getCategory();
    const FilePath & path = resourceMusic->getPath();
    const ConstString & codec = resourceMusic->getCodec();
    bool external = resourceMusic->isExternal();
    float volume = resourceMusic->getVolume();

    m_volume = volume;

    if( external == false )
    {
        InputStreamInterfacePtr stream = FILE_SERVICE(m_serviceProvider)
                                         ->openInputFile( category, path, false );

        if( stream == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: invalid open sound '%s:%s'"
                                            , category.c_str()
                                            , path.c_str()
                                           );

            return false;
        }


        m_audioMemory = Helper::createMemoryStream( m_serviceProvider, stream );

        if( m_audioMemory == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: invalid create memory '%s:%s'"
                                            , category.c_str()
                                            , path.c_str()
                                           );

            return false;
        }

        void * buffer_memory = m_audioMemory->getMemory();
        size_t buffer_size = m_audioMemory->getSize();

        s3eResult result_play = s3eAudioPlayFromBuffer( const_cast<void *>(buffer_memory), buffer_size, 1 );

        if( result_play == S3E_RESULT_ERROR )
        {
            s3eAudioError s3eAudio_error = s3eAudioGetError();
            const char * s3eAudio_string = s3eAudioGetErrorString();

            LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't play internal audio '%s:%s' error %d [%s]"
                                            , category.c_str()
                                            , path.c_str()
                                            , s3eAudio_error
                                            , s3eAudio_string
                                           );

            return false;
        }
    }
    else
    {
        const Char * str_path = path.c_str();

        s3eResult result_play = s3eAudioPlay( str_path, 1 );

        if( result_play == S3E_RESULT_ERROR )
        {
            s3eAudioError s3eAudio_error = s3eAudioGetError();
            const char * s3eAudio_string = s3eAudioGetErrorString();

            LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't play external audio '%s' error %d [%s]"
                                            , path.c_str()
                                            , s3eAudio_error
                                            , s3eAudio_string
                                           );

            return false;
        }
    }

    int32 s3e_pos = (int32)_pos;

    if( s3e_pos != 0 )
    {
        // W/o this, there is sound bugs during playback on iOS.
        s3eDeviceYield( 0 );

        s3eResult result_position = s3eAudioSetInt( S3E_AUDIO_POSITION, s3e_pos );

        if( result_position == S3E_RESULT_ERROR )
        {
            s3eAudioError s3eAudio_error = s3eAudioGetError();
            const char * s3eAudio_string = s3eAudioGetErrorString();

            LOGGER_ERROR(m_serviceProvider)("Amplifier::play_: can't '%s:%s' set pos %d error %d [%s]"
                                            , category.c_str()
                                            , path.c_str()
                                            , s3e_pos
                                            , s3eAudio_error
                                            , s3eAudio_string
                                           );
        }
    }

    float commonVolume = SOUND_SERVICE( m_serviceProvider )
                         ->mixCommonVolume();

    float musicVolume = SOUND_SERVICE( m_serviceProvider )
                        ->mixMusicVolume();

    int32 s3e_volume = (int32)(m_volume * commonVolume * musicVolume * float( S3E_AUDIO_MAX_VOLUME ));

    s3eResult result = s3eAudioSetInt( S3E_AUDIO_VOLUME, s3e_volume );

    if( result == S3E_RESULT_ERROR )
    {
        s3eAudioError s3eAudio_error = s3eAudioGetError();
        const char * s3eAudio_string = s3eAudioGetErrorString();

        LOGGER_ERROR( m_serviceProvider )("Amplifier::onSoundChangeVolume invalid set S3E_AUDIO_VOLUME %d error %d [%s]"
                                          , s3e_volume
                                          , s3eAudio_error
                                          , s3eAudio_string
                                         );
    }

    return true;
}
Beispiel #9
0
void Audio::PlayMusic(const char* filename, bool repeat)
{
    // We only support play back of MP3 music
    if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
        s3eAudioPlay(filename, repeat ? 0 : 1);
}
void Update()
{
	// Allow device OS time to do its processing
	s3eDeviceYield(0);

	// Update pointer (actually touch screen!) inputs
	s3ePointerUpdate();

	// Read current touch screen inputs and use them to update Button states
	uint32 lTouchState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT);
	int32 x = s3ePointerGetX();
	int32 y = s3ePointerGetY();
	for (uint32 i = 0; i < BUTTON_COUNT; i++)
	{
		gButton[i]->Update(lTouchState, x, y);
	}

	// Check for button presses
	if (gButton[BUTTON_AUDIO_MUSIC]->IsReleased())
	{
		s3eAudioPlay("black-hole.mp3");
	}
	else if (gButton[BUTTON_AUDIO_SFX]->IsReleased())
	{
		if (gpGunBattleSound)
			gpGunBattleSound->Play();
	}
	else if (gButton[BUTTON_AUDIO_SPEECH]->IsReleased())
	{
		if (gpFemaleCountingSound)
			gpFemaleCountingSound->Play();
	}
	else if (gButton[BUTTON_AUDIO_OFF]->IsReleased())
	{
		s3eAudioStop();
		s3eSoundStopAllChannels();
	}

	if (gButton[BUTTON_FILTER_OFF]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_FALSE);
		}
	}
	else if (gButton[BUTTON_FILTER_MUSIC]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(MUSIC);
		}
	}
	else if (gButton[BUTTON_FILTER_MOVIE]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(MOVIE);
		}
	}
	else if (gButton[BUTTON_FILTER_GAME]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(GAME);
		}
	}
	else if (gButton[BUTTON_FILTER_VOICE]->IsReleased())
	{
		if (gDolbyInitialised)
		{
			s3eDolbyAudioSetEnabled(S3E_TRUE);
			s3eDolbyAudioSetProfile(VOICE);
		}
	}
}
void MusicPlayer::play(const char* filename)
{
	s3eAudioPlay(filename, 0);
}
Beispiel #12
0
/**
* Constructor
*/
Game::Game():

	physicsHz(60),
	timeStep(1.0f/physicsHz),
	velocityIterations(10),
	positionIterations(8),
	g_accumulator(0.0f),
	g_prevTime(s3eTimerGetMs()),
	loadCheckpoint(false), 
	mPaused(false),
	mMultiplayer(false),
	mBytesRecieved(-1),
	timeSinceLastSend(0),
	mRDXVel(0),
	mRecRDXVel(0),
	mDiff(1),
	mTimeSinceLastRequest(0),
	mSelectedLevel("1"),
	mPlayersFinished(0),
	FACEBOOK_APP_ID("160040267492274"),
	FACEBOOK_APP_SECRET("b7d69cf0ef9e50a344d892df3c8c7fe6") {

		mRequestBuffer = NULL;
		mHost = true;
		mSock = NULL;
		mPlayerFound = false;
		mPlayersInLobby = 0;
		mStage = Constants::MAINMENU;
		ServerUrl = "http://10.40.3.237:28003";
		g_GetUID = NULL;
		g_AddScore = NULL;
		mLevel = NULL;
		g_SelectedLvlScore = 0;
		g_Selectedlvl = "tutorial";
		PostScoreRequest = NULL;
		mTimeTaken = 0.0f;
		mPlayerDeaths = 0;
		g_CurrentSession = NULL;

		crateSpawned = true;
		maxCrates = 1;

		moveLeftBtn = Iw2DCreateImage("Images/ArrowLeft.png");
		moveRightBtn = Iw2DCreateImage("Images/ArrowRight.png");
		jumpBtn = Iw2DCreateImage("Images/ArrowJump.png");
		kickBtn = Iw2DCreateImage("Images/kick.png");
		punchBtn = Iw2DCreateImage("Images/punch.png");

		mMenuSystem = new MenuSystem();
		mMenuSystem->init(this);

		mCollListener = new MyContactListener();
		mCollListener->setGame(this);

		// Prepare the iwgxfont resource for rendering using Iw2D
		mFont = Iw2DCreateFontResource("font_large");

		if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3)) {
			s3eAudioPlay("Audio/MainMenu.mp3", 0);
		}

		mMusic.push_back("Audio/gameMusic1.mp3");
		mMusic.push_back("Audio/gameMusic2.mp3");

		srand((unsigned)time(0));
}
void GameplayState::Init()
{
	IwGetResManager()->LoadGroup("sprites.group");
	m_Portraits[DAVE] = new Sprite("dave_port", true);
	m_PortraitsNot[DAVE] = new Sprite("dave_port_b", true);
	m_Portraits[DAVE]->SetPosition(CIwFVec2(130,0));
	m_PortraitsNot[DAVE]->SetPosition(CIwFVec2(130,0));

	m_Portraits[NIGEL] = new Sprite("nigel_port", true);
	m_PortraitsNot[NIGEL] = new Sprite("nigel_port_b", true);
	m_Portraits[NIGEL]->SetPosition(CIwFVec2(210,0));
	m_PortraitsNot[NIGEL]->SetPosition(CIwFVec2(210,0));

	m_Portraits[MANDY] = new Sprite("mandy_port", true);
	m_PortraitsNot[MANDY] = new Sprite("mandy_port_b", true);
	m_Portraits[MANDY]->SetPosition(CIwFVec2(290,0));
	m_PortraitsNot[MANDY]->SetPosition(CIwFVec2(290, 0));

	n_guiButtons[0] = new Sprite("touchScreenMoveL", true);
	n_guiButtons[0]->SetPosition(CIwFVec2(0, 260));

	n_guiButtons[1] = new Sprite("touchScreenMoveR", true);
	n_guiButtons[1]->SetPosition(CIwFVec2(414, 260));

	m_throwingTarget = new Sprite("target_sprite", true);

	screenHeight = Iw2DGetSurfaceHeight();
	screenWidth = Iw2DGetSurfaceWidth();

	m_CharacterIndex = 0;
	m_ThrowingTargetSide = 0;
	m_isThrowing = false;
	m_canThrow = false;
	m_SpacePressed = false;
	m_gameOver = false;
	m_MouseClicked = false;
	m_ClickLocation = CIwFVec2(0,0);
	m_Level = new TileMap("levelproto1.txt", "levelrelationships1.txt");
	m_Cam = new Camera(screenWidth, screenHeight);
	m_Cam->SetPosition(CIwSVec2(0, 0));
	m_Cam->Position = CIwSVec2(0, 0);
	m_Cam->SetLevelBounds(m_Level->GetLevelBounds());
	SpawnCharacters();

	m_Layers[0] = new Sprite("layer1", false);
	m_Layers[1] = new Sprite("layer2", false);
	m_Layers[2] = new Sprite("layer3", false);
	m_Layers[3] = new Sprite("layer4", false);

	m_Cranes[0] = new GameObject("clamp_back", Scenerary, false);
	m_Cranes[0]->SetPosition(CIwFVec2(100, 0));
	m_Cranes[0]->SetMovSpeed(CIwFVec2(-0.15, 0));
	m_Cranes[1] = new GameObject("clamp_mid", Scenerary, false);
	m_Cranes[1]->SetPosition(CIwFVec2(210, 0));
	m_Cranes[1]->SetMovSpeed(CIwFVec2(-0.35, 0));
	m_Cranes[2] = new GameObject("clamp_front", Scenerary, false);
	m_Cranes[2]->SetPosition(CIwFVec2(m_Cranes[2]->GetWidth() + 10, 0));
	m_Cranes[2]->SetMovSpeed(CIwFVec2(-1, 0));

	if (s3eAudioIsCodecSupported(S3E_AUDIO_CODEC_MP3))
		s3eAudioPlay("bgmusic.mp3", 0);

	m_ThrowingSound = new SoundEffect("dave_throw");
	m_ThrowingNigelSound = new SoundEffect("nigel_throw");

	m_TerminalSound = new SoundEffect("terminal_selected");
	doorSound = static_cast<CIwSoundSpec*>(IwGetResManager()->GetResNamed("locked_door", "CIwSoundSpec"));
	doorSoundInst = NULL;

	buttonSoundCount = 0;

	m_LayerVals[0] = 0;
	m_LayerVals[1] = 0.025;
	m_LayerVals[2] = 0.05;
	m_LayerVals[3] = 0.075;
	printf("GameplayState initialized\n");
}