summaryrefslogtreecommitdiff
path: root/Game.cpp
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2018-07-10 00:04:16 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2018-07-10 00:04:16 +0200
commit14c12aeea30d59e9c811f1cc8c7019053d646033 (patch)
tree7bff078a702a1b2949c37930adfc6fd2fc45c3cb /Game.cpp
parent188d74cb789f33967daf6daa5af17d41b6f59d4e (diff)
downloadpocketempires-14c12aeea30d59e9c811f1cc8c7019053d646033.tar.gz
More work on Unit/BaseUnit concepts.
Diffstat (limited to 'Game.cpp')
-rw-r--r--Game.cpp56
1 files changed, 51 insertions, 5 deletions
diff --git a/Game.cpp b/Game.cpp
index 175d247..1338e9b 100644
--- a/Game.cpp
+++ b/Game.cpp
@@ -17,10 +17,16 @@
* Types definition
* ******************************************************************/
+/*****************************************************************//**
+ *
+ * \brief This enum holds different options to be selected
+ * under pause menu.
+ *
+ *********************************************************************/
enum tPauseMenuChoice
{
- PAUSE_MENU_CHOICE_RESUME,
- PAUSE_MENU_CHOICE_QUIT,
+ PAUSE_MENU_CHOICE_RESUME, /**< Resumes the game. */
+ PAUSE_MENU_CHOICE_QUIT, /**< Exits the game. */
MAX_PAUSE_MENU_CHOICES,
};
@@ -37,6 +43,7 @@ enum tPauseMenuChoice
* Local prototypes declaration
* ******************************************************************/
+static void GameNextFrame(const struct tGameConfig& sGameConfig);
static enum tPauseMenuChoice GamePause(void);
/* *******************************************************************
@@ -47,8 +54,11 @@ static enum tPauseMenuChoice GamePause(void);
*
* \brief Entry point for gameplay logic.
*
+ * \param sGameConfig
+ * Game configuration structure.
+ *
*********************************************************************/
-void Game(const struct tGameConfig& psGameConfig)
+void Game(const struct tGameConfig& sGameConfig)
{
#if 0
Sprite MouseSpr( MouseSprData,
@@ -61,20 +71,56 @@ void Game(const struct tGameConfig& psGameConfig)
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] = "Resume",
- [PAUSE_MENU_CHOICE_QUIT] = "Quit"
+ [PAUSE_MENU_CHOICE_RESUME] = strPauseMenuOption_0,
+ [PAUSE_MENU_CHOICE_QUIT] = strPauseMenuOption_1
};
return (enum tPauseMenuChoice)gb.menu(astrPauseMenuOptions, MAX_PAUSE_MENU_CHOICES);