blob: 1338e9bb53dd2c2a2f915ca411c8170ae4cb3866 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/* *******************************************************************
* 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)
{
#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;
}
|