133 lines
3.9 KiB
C++
133 lines
3.9 KiB
C++
/* *******************************************************************
|
|
* Includes
|
|
* ******************************************************************/
|
|
|
|
#include "Menu.h"
|
|
#include "HumanPlayer.h"
|
|
#include "Game.h"
|
|
#include "System.h"
|
|
#include "Sprite.h"
|
|
#include <Gamebuino.h>
|
|
#include <Arduino.h>
|
|
|
|
/* *******************************************************************
|
|
* Defines
|
|
* ******************************************************************/
|
|
|
|
#define GAME_NAME "Pocket Empires"
|
|
|
|
/* *******************************************************************
|
|
* Types definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Global variables definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Local variables definition
|
|
* ******************************************************************/
|
|
|
|
/* *******************************************************************
|
|
* Local prototypes declaration
|
|
* ******************************************************************/
|
|
|
|
static void MainMenuSinglePlayer(void);
|
|
|
|
/* *******************************************************************
|
|
* Functions definition
|
|
* ******************************************************************/
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Video game entry point. Main menu is shown, allowing
|
|
* the user to choose an option.
|
|
*
|
|
*********************************************************************/
|
|
void MainMenu(void)
|
|
{
|
|
enum
|
|
{
|
|
CHOICE_SINGLE_PLAYER_GAME,
|
|
CHOICE_MULTI_PLAYER_GAME,
|
|
CHOICE_OPTIONS,
|
|
|
|
MAX_CHOICES
|
|
};
|
|
|
|
/* Strings must be individually allocated into
|
|
* PROGMEM so they can be read correctly by gb.menu(). */
|
|
static const char strMainMenuOptions_0[] PROGMEM = "Single player game";
|
|
static const char strMainMenuOptions_1[] PROGMEM = "Multiplayer game";
|
|
static const char strMainMenuOptions_2[] PROGMEM = "Options";
|
|
|
|
static const char* const astrMainMenuOptions[MAX_CHOICES] PROGMEM =
|
|
{
|
|
[CHOICE_SINGLE_PLAYER_GAME] = strMainMenuOptions_0,
|
|
[CHOICE_MULTI_PLAYER_GAME] = strMainMenuOptions_1,
|
|
[CHOICE_OPTIONS] = strMainMenuOptions_2
|
|
};
|
|
|
|
/* Show video game name on
|
|
* Gamebuino default title screen. */
|
|
gb.titleScreen(F(GAME_NAME));
|
|
|
|
/* Choose which module should be
|
|
* executed depending on user input. */
|
|
switch (gb.menu(astrMainMenuOptions, MAX_CHOICES))
|
|
{
|
|
case CHOICE_SINGLE_PLAYER_GAME:
|
|
MainMenuSinglePlayer();
|
|
break;
|
|
|
|
case CHOICE_MULTI_PLAYER_GAME:
|
|
/* Not implemented yet. Fall through. */
|
|
case CHOICE_OPTIONS:
|
|
/* Not implemented yet. Fall through. */
|
|
default:
|
|
/* Undefined choice. Exit. */
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*****************************************************************//**
|
|
*
|
|
* \brief Executes single player mode.
|
|
*
|
|
*********************************************************************/
|
|
static void MainMenuSinglePlayer(void)
|
|
{
|
|
enum
|
|
{
|
|
/* Maximum number of characters for
|
|
* player name, as specified on
|
|
* Gamebuino documentation. */
|
|
GAMEBUINO_MAX_PLAYER_NAME = 10
|
|
};
|
|
|
|
char strName[GAMEBUINO_MAX_PLAYER_NAME] = {0};
|
|
|
|
/* Fill strName with default user name. */
|
|
gb.getDefaultName(strName);
|
|
|
|
Camera cam;
|
|
|
|
/* Declare 1 human player instance. */
|
|
HumanPlayer h(strName, cam);
|
|
|
|
const struct tGameConfig c =
|
|
{
|
|
.pHumanPlayerData = &h,
|
|
.u8NHumanPlayers = 1,
|
|
.cam = cam
|
|
};
|
|
|
|
/* Set global camera for sprites. */
|
|
Sprite::setCamera(&c.cam);
|
|
|
|
BaseUnit::setCamera(&c.cam);
|
|
|
|
/* Initialize game with defined configuration. */
|
|
Game(c);
|
|
}
|