/* ******************************************************************* * Includes * ******************************************************************/ #include "Game.h" #include "Sprite.h" #include "MouseSpr.i" #include "System.h" #include #include /* ******************************************************************* * Defines * ******************************************************************/ /* ******************************************************************* * Types definition * ******************************************************************/ /*****************************************************************//** * * \brief This enum holds different options to be selected * under pause menu. * *********************************************************************/ enum tPauseMenuChoice { PAUSE_MENU_CHOICE_RESUME, /**< Resumes the game. */ PAUSE_MENU_CHOICE_QUIT, /**< Exits the game. */ MAX_PAUSE_MENU_CHOICES, }; /* ******************************************************************* * Global variables definition * ******************************************************************/ /* ******************************************************************* * Local variables definition * ******************************************************************/ /* ******************************************************************* * Local prototypes declaration * ******************************************************************/ static void GameNextFrame(const struct tGameConfig& sGameConfig); static enum tPauseMenuChoice GamePause(void); /* ******************************************************************* * Functions definition * ******************************************************************/ /*****************************************************************//** * * \brief Entry point for gameplay logic. * * \param sGameConfig * Game configuration structure. * *********************************************************************/ void Game(const struct tGameConfig& sGameConfig) { #if 0 Sprite MouseSpr( MouseSprData, INVERT, NOROT, NOFLIP, (X_SCREEN_RESOLUTION >> 1) - 4, (Y_SCREEN_RESOLUTION >> 1) - 4); #endif /* 0 */ do { /* Calculate next frame. */ GameNextFrame(sGameConfig); /* Do not calculate a new frame * until refresh flag is set. */ while (gb.update() == false); } while (GamePause() != PAUSE_MENU_CHOICE_QUIT); } /*****************************************************************//** * * \brief This function calculates a new frame by calling * all handlers. * * \param sGameConfig * Game configuration structure. * *********************************************************************/ static void GameNextFrame(const struct tGameConfig& sGameConfig) { for (uint8_t i = 0; i < sGameConfig.u8NHumanPlayers; i++) { HumanPlayer* pHumanPlayerData = &sGameConfig.pHumanPlayerData[i]; if (pHumanPlayerData != NULL) { pHumanPlayerData->handler(); } } } /*****************************************************************//** * * \brief When C button is pressed, this function evaluates * user actions to determine whether game must be exited. * *********************************************************************/ static enum tPauseMenuChoice GamePause(void) { if (gb.buttons.released(BTN_C) != false) { /* Strings must be individually allocated into * PROGMEM so they can be read correctly by gb.menu(). */ static const char strPauseMenuOption_0[] PROGMEM = "Resume"; static const char strPauseMenuOption_1[] PROGMEM = "Quit"; static const char* const astrPauseMenuOptions[MAX_PAUSE_MENU_CHOICES] PROGMEM = { [PAUSE_MENU_CHOICE_RESUME] = strPauseMenuOption_0, [PAUSE_MENU_CHOICE_QUIT] = strPauseMenuOption_1 }; return (enum tPauseMenuChoice)gb.menu(astrPauseMenuOptions, MAX_PAUSE_MENU_CHOICES); } else { /* C button has not been pressed. Exit. */ } /* Return false since no * actions need to be done yet. */ return PAUSE_MENU_CHOICE_RESUME; }