-
Notifications
You must be signed in to change notification settings - Fork 0
/
title_screen.c
212 lines (174 loc) · 4.97 KB
/
title_screen.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <jo/jo.h>
#include "main.h"
#include "assets.h"
#include "title_screen.h"
#include "objects/player.h"
// globals for menu options
int g_TitleScreenChoice = 0;
int g_TitleScreenCursorColor = 0;
typedef enum _MENU_OPTIONS
{
TITLE_OPTION_GAME_MODE = 0,
TITLE_OPTION_GAME_DIFFICULTY = 1,
TITLE_OPTION_GAME_START = 2,
TITLE_OPTION_MAX,
} MENU_OPTIONS;
static void drawTitle(void);
static void drawMenuCursor(void);
static void drawMenu(void);
// use the players as moving elements in the background
extern PLAYER g_Players[MAX_PLAYERS];
void titleScreen_init(void)
{
// init menu options
g_TitleScreenChoice = 0;
//g_TitleModeChoice = 0;
//g_TitleDifficultyChoice = 1;
g_Game.gameMode = GAME_MODE_PRACTICE;
g_Game.gameDifficulty = GAME_DIFFICULTY_MEDIUM;
// randomize the cursor flag
g_TitleScreenCursorColor = jo_random(COUNTOF(g_Assets.randomizedColors)) - 1;
initTitlePlayers();
return;
}
// handles input for the title screen
// only player one can control the title screen
void titleScreen_input(void)
{
int titleScreenChoice = 0;
if(g_Game.gameState != GAME_STATE_TITLE_SCREEN)
{
return;
}
titleScreenChoice = g_TitleScreenChoice;
if (jo_is_pad1_key_pressed(JO_KEY_UP))
{
if(g_Game.input.pressedUp == false)
{
titleScreenChoice--;
}
g_Game.input.pressedUp = true;
}
else
{
g_Game.input.pressedUp = false;
}
if (jo_is_pad1_key_pressed(JO_KEY_DOWN))
{
if(g_Game.input.pressedDown == false)
{
titleScreenChoice++;
}
g_Game.input.pressedDown = true;
}
else
{
g_Game.input.pressedDown = false;
}
// keep title screen choice in range
sanitizeValue(&titleScreenChoice, 0, TITLE_OPTION_MAX);
g_TitleScreenChoice = titleScreenChoice;
// select an option here
if (jo_is_pad1_key_pressed(JO_KEY_START) ||
jo_is_pad1_key_pressed(JO_KEY_A) ||
jo_is_pad1_key_pressed(JO_KEY_C))
{
if(g_Game.input.pressedStart == false)
{
switch(titleScreenChoice)
{
case TITLE_OPTION_GAME_MODE:
{
g_Game.gameMode++;
sanitizeValue(&g_Game.gameMode, 0, GAME_MODE_MAX);
break;
}
case TITLE_OPTION_GAME_DIFFICULTY:
{
g_Game.gameDifficulty++;
sanitizeValue(&g_Game.gameDifficulty, 0, GAME_DIFFICULTY_MAX);
break;
}
case TITLE_OPTION_GAME_START:
{
transitionState(GAME_STATE_TEAM_SELECT);
break;
}
}
}
g_Game.input.pressedStart = true;
}
else
{
g_Game.input.pressedStart = false;
}
return;
}
void titleScreen_update(void)
{
if(g_Game.gameState != GAME_STATE_TITLE_SCREEN)
{
return;
}
updatePlayers();
return;
}
void titleScreen_draw(void)
{
if(g_Game.gameState != GAME_STATE_TITLE_SCREEN)
{
return;
}
drawPlayers();
drawTitle();
drawMenu();
drawMenuCursor();
return;
}
//
// Title screen helpers
//
// draws title image + version number
static void drawTitle(void)
{
// title graphic
jo_sprite_change_sprite_scale(2);
jo_sprite_draw3D(g_Assets.title, 0, 0, TITLE_SCREEN_Z);
jo_sprite_change_sprite_scale(1);
// version number
jo_printf(20, 28, "%s", VERSION);
}
// Options menu + values
static void drawMenu(void)
{
int xPos = 0;
int yPos = 0;
// game mode (practice, normal, hardcore, time attack)
xPos = -30;
yPos = 90;
jo_sprite_draw3D(g_Assets.mode_s, xPos+2, yPos-2, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.mode, xPos, yPos, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.modes_s[g_Game.gameMode], xPos + 110 +2, yPos-2, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.modes[g_Game.gameMode], xPos + 110, yPos, TITLE_MENU_Z);
// Difficulty: (easy, medium, hard)
yPos = 130;
jo_sprite_draw3D(g_Assets.difficulty_s, xPos+2, yPos-2, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.difficulty, xPos, yPos, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.difficulties_s[g_Game.gameDifficulty], xPos + 196 +2, yPos-2, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.difficulties[g_Game.gameDifficulty], xPos + 196, yPos, TITLE_MENU_Z);
// Start!
yPos = 170;
jo_sprite_draw3D(g_Assets.start_s, xPos + 2, yPos-2, TITLE_MENU_Z);
jo_sprite_draw3D(g_Assets.start, xPos, yPos, TITLE_MENU_Z);
}
// flag used as the menu cursor
static void drawMenuCursor(void)
{
int xPos = 0;
int yPos = 0;
xPos = -160;
yPos = 90 + (g_TitleScreenChoice * 40); // vertical position varies based on selection
jo_sprite_change_sprite_scale(2);
jo_sprite_draw3D(g_Assets.flags2[g_TitleScreenCursorColor], xPos, yPos, TITLE_MENU_Z);
jo_sprite_change_sprite_scale(1);
}