-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_menu.c
111 lines (88 loc) · 1.85 KB
/
main_menu.c
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
//
// Created by Avihoo on 28/06/2020.
//
#include <stdlib.h>
#include <stdio.h>
#include "menu.h"
#include "main_menu.h"
const char *settingsGetText()
{
static char text[] = "Settings";
return text;
}
void settingsAction(menuAction action)
{
if (action == MENU_PRESS_RETURN)
{
menuState.selectedMenu = SETTINGS_MENU;
}
}
const char *levelGetText()
{
static char levelStr[64];
snprintf(levelStr, sizeof(levelStr), "<Level %d>", gameState.startingLevel + 1);
return levelStr;
}
void levelAction(menuAction action)
{
switch (action)
{
case MENU_PRESS_LEFT:
gameState.startingLevel = (gameState.startingLevel + MAX_LEVEL - 1) % MAX_LEVEL;
break;
case MENU_PRESS_RIGHT:
gameState.startingLevel = (gameState.startingLevel + 1) % MAX_LEVEL;
break;
default:
break;
}
}
const char *newGameGetText()
{
static char text[] = "New Game";
return text;
}
void newGameAction(menuAction action)
{
if (action == MENU_PRESS_RETURN)
{
menuState.isActive = 0;
newGame();
}
}
const char *quitGetText()
{
static char text[] = "Quit";
return text;
}
void quitAction(menuAction action)
{
if (action == MENU_PRESS_RETURN)
{
menuState.wantsToQuit = 1;
}
}
void resumeAction(menuAction action)
{
if (action == MENU_PRESS_RETURN)
{
menuState.isActive = 0;
}
}
const char *resumeGetText()
{
static char text[] = "Resume";
return text;
}
menu createMainMenu()
{
menu result;
result.menuItemCount = MAIN_MENU_ITEM_COUNT;
result.menuItems = malloc(sizeof(menuItem) * MAIN_MENU_ITEM_COUNT);
result.menuItems[0] = createMenuItem(resumeGetText, resumeAction);
result.menuItems[1] = createMenuItem(newGameGetText, newGameAction);
result.menuItems[2] = createMenuItem(levelGetText, levelAction);
result.menuItems[3] = createMenuItem(settingsGetText, settingsAction);
result.menuItems[4] = createMenuItem(quitGetText, quitAction);
return result;
}