summaryrefslogtreecommitdiff
path: root/Menu.cpp
blob: 5e11df212cf338c2c8c3d5e58cb8d35cf2b639de (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
/* *******************************************************************
 *  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);
}