133 lines
4.3 KiB
C++
133 lines
4.3 KiB
C++
/* *******************************************************************
|
|
* Includes
|
|
* ******************************************************************/
|
|
|
|
#include "Game.h"
|
|
#include "Sprite.h"
|
|
#include "MouseSpr.i"
|
|
#include "System.h"
|
|
#include <Gamebuino.h>
|
|
#include <Display.h>
|
|
|
|
/* *******************************************************************
|
|
* 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)
|
|
{
|
|
do
|
|
{
|
|
/* Calculate next frame. */
|
|
GameNextFrame(sGameConfig);
|
|
|
|
/* Do not calculate a new frame
|
|
* until refresh flag is set. */
|
|
while (not gb.update());
|
|
} 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 (size_t szHumanPlayer = 0; szHumanPlayer < sGameConfig.u8NHumanPlayers; szHumanPlayer++)
|
|
{
|
|
HumanPlayer* const pHumanPlayerData = &sGameConfig.pHumanPlayerData[szHumanPlayer];
|
|
|
|
if (pHumanPlayerData != NULL)
|
|
{
|
|
/* Execute handler for selected HumanPlayer. */
|
|
pHumanPlayerData->handler();
|
|
}
|
|
else
|
|
{
|
|
/* HumanPlayer handler callback not available. */
|
|
}
|
|
}
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \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 static_cast<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;
|
|
}
|