/* checkCurrentScreenForAction - This method should be called once per frame. It checks with the current screen to see if a button event needs to be fired, and fires it if necessary. If a mode is provided that does not match a ScreenGUI index, an exception is thrown. */ bool GameGUI::checkCurrentScreenForAction(Game *game) { // IF THE GAME STATE DOESN'T HAVE A CORRESPONDING, // SCREEN DON'T DO ANYTHING GameStateManager *gsm = game->getGSM(); GameState gameState = gsm->getCurrentGameState(); ScreenGUI *gui = screens[gameState]; if (gui != NULL) { // CASCADE THE CHECK TO THE CURRENT SCREEN return gui->fireButtonCommand(game); } return false; }
/* respondToMouseInput - This method sends the updated cursor position to the GameGUI so that it can update the Button and Cursor states. It then checks to see if the left mouse button is pressed, and if so, it asks the gui to check to see if it needs to fire an event. This should be called once per frame, after input is retrieved. */ void WindowsInput::respondToMouseInput(Game *game) { GameGUI *gui = game->getGUI(); GameStateManager *gsm = game->getGSM(); Viewport *viewport = gui->getViewport(); gui->updateGUIState(mousePoint->x, mousePoint->y, gsm->getCurrentGameState()); if ( (GetAsyncKeyState(VK_LBUTTON) & 0X8000) && (inputState[VK_LBUTTON].isFirstPress)) { if ((gsm->isGameInProgress()) && viewport->areScreenCoordinatesInViewport(mousePoint->x, mousePoint->y)) mouseHandler->handleMousePressEvent(game, mousePoint->x-viewport->getViewportOffsetX(), mousePoint->y-viewport->getViewportOffsetY()); gui->checkCurrentScreenForAction(game); } }
/* addRenderItemsToRenderList - This method cascades this call to the current ScreenGUI. That object will add the appropriate items to the render list. This method should be called once per frame to make sure the current GUI is always rendered. Make sure the mode you provide matches the index of this GUI's screen. If an illegal mode value is provided, an exception is thrown. */ void GameGUI::addRenderItemsToRenderList(Game *game) { GameStateManager *gsm = game->getGSM(); GameState gameState = gsm->getCurrentGameState(); GameGraphics *graphics = game->getGraphics(); RenderList *guiRenderList = graphics->getGUIRenderList(); if (gsm->isAppActive()) { // CASCADE THIS CALL TO THE APPROPRIATE SCREEN screens.at(gameState)->addRenderItemsToRenderList(guiRenderList); } // CASCADE THIS CALL TO THE CURSOR, IF THERE IS ONE if (customCursor != NULL) customCursor->addRenderItemToRenderList(guiRenderList); }
void GameAudio::processSoundEffect() { Game *game = Game::getSingleton(); GameStateManager *gsm = game->getGSM(); GameState gameState = gsm->getCurrentGameState(); if (gameState == GS_GAME_IN_PROGRESS) { //// shoot sound effect processShootSound(); //// money sound effect processMoneySound(); //// punch sound effect processPunchSound(); //// heal sound effect processHealSound(); //// damage sound effect processDamageSound(); } }
void GameAudio::processMusic() { Game *game = Game::getSingleton(); GameStateManager *gsm = game->getGSM(); GameState gameState = gsm->getCurrentGameState(); if (gameState == GS_GAME_IN_PROGRESS) { /// check if the game is over (player is dying or player shooted enemy w/o safety) if (gsm->getLose() == true) { if (currentMusicPlaying != ENUM_MUSIC_GAMEOVER) { if (currentMusicPlaying != ENUM_MUSIC_NONE) stopMusic(currentMusicPlaying); currentMusicPlaying = ENUM_MUSIC_GAMEOVER; gameOverMusicBuffered = false; /// this value will checked in the playMusicOnce() function } playMusicOnce(ENUM_MUSIC_GAMEOVER); } //// game is in progress without game over else { if (currentMusicPlaying != ENUM_MUSIC_INGAME) { if (currentMusicPlaying != ENUM_MUSIC_NONE) stopMusic(currentMusicPlaying); currentMusicPlaying = ENUM_MUSIC_INGAME; } //// not yet have file to play } } else if (gameState == GS_MAIN_MENU || gameState == GS_SPLASH_SCREEN) { //// if currently playing music is not main theme, //// it means that the game was in-game or other states //// need to start the main theme music, and turn the previous music off. //// musicMap[currentMusicPlaying]; if (currentMusicPlaying != ENUM_MUSIC_MAIN_THEME) { //// IF current music exists, then it means the game //// was previously playing other music if (currentMusicPlaying != ENUM_MUSIC_NONE) stopMusic(currentMusicPlaying); currentMusicPlaying = ENUM_MUSIC_MAIN_THEME; } playMusicRepeat(ENUM_MUSIC_MAIN_THEME); } else if (gameState == GS_LEVEL_COMPLETE) { if (currentMusicPlaying != ENUM_MUSIC_LEVEL_COMPLETE) { if (currentMusicPlaying != ENUM_MUSIC_NONE) stopMusic(currentMusicPlaying); levelCompleteMusicBuffered = false; /// this value will checked in the playMusicOnce() function currentMusicPlaying = ENUM_MUSIC_LEVEL_COMPLETE; } playMusicOnce(ENUM_MUSIC_LEVEL_COMPLETE); } else if (gameState == GS_GAME_OVER) { if (currentMusicPlaying != ENUM_MUSIC_GAMEOVER) { if (currentMusicPlaying != ENUM_MUSIC_NONE) stopMusic(currentMusicPlaying); currentMusicPlaying = ENUM_MUSIC_GAMEOVER; } playMusicOnce(ENUM_MUSIC_GAMEOVER); } }
void DirectXGraphics::renderGame(Game *game) { GameStateManager *gsm = game->getGSM(); World *world = gsm->getWorld(); GameText *text = game->getText(); // CHECK TO SEE IF WE STILL HAVE THE GPU HRESULT result = graphicsDevice->TestCooperativeLevel(); // IF WE HAVE THE GPU, RENDER THE GAME if (SUCCEEDED(result)) { // NOW PREPARE TO RENDER THE LISTS USING // BATCH TEXTURE RENDERING startDirectXFrameRendering(); spriteHandler->Begin(D3DXSPRITE_ALPHABLEND); if (gsm->getCurrentGameState() == GS_LEVEL_SELECT) { // RENDER THE GUI RENDER LIST renderGUIRenderList(); // RENDER THE WORLD RENDER LIST renderWorldRenderList(); } else { // RENDER THE WORLD RENDER LIST renderWorldRenderList(); // RENDER THE GUI RENDER LIST renderGUIRenderList(); } // RENDER THE TEXT renderText(text); // WRAP UP RENDERING RESOURCES if (FAILED(spriteHandler->End())) { text->writeDebugOutput("\nspriteHandler->End(): FAILED"); } endDirectXFrameRendering(); } // WE'VE LOST THE GPU, SLEEP UNTIL WE GET IT BACK else if (result == D3DERR_DEVICELOST) { spriteHandler->OnLostDevice(); textFont->OnLostDevice(); Sleep(100); } // WE'VE GOT IT BACK, RELOAD EVERYTHING. NOTE THAT // WE'LL ONLY GET THIS MESSAGE ONCE. else if (result == D3DERR_DEVICENOTRESET) { if (FAILED(graphicsDevice->Reset(&presentParameters))) { game->getText()->writeDebugOutput("\ngraphicsDevice->Reset: FAILED - Reloading GPU images"); game->reloadAllDevices(); } else { spriteHandler->OnResetDevice(); textFont->OnResetDevice(); } } }