Code maintenance and cleanup
This commit is contained in:
parent
fffcac12c0
commit
b08ef10e82
55
src/main.c
55
src/main.c
|
@ -1120,6 +1120,39 @@ run_game(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Menu *
|
||||||
|
get_active_menu(void)
|
||||||
|
{
|
||||||
|
switch (gGameState) {
|
||||||
|
case MENU:
|
||||||
|
return mainMenu;
|
||||||
|
case CHARACTER_MENU:
|
||||||
|
return charSelectMenu;
|
||||||
|
case GAME_SELECT:
|
||||||
|
return gameSelectMenu;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
render_current_screen(void)
|
||||||
|
{
|
||||||
|
switch (gGameState) {
|
||||||
|
case CHARACTER_MENU:
|
||||||
|
screen_render(characterSelectScreen, gCamera);
|
||||||
|
break;
|
||||||
|
case CREDITS:
|
||||||
|
screen_render(creditsScreen, gCamera);
|
||||||
|
break;
|
||||||
|
case SCORE_SCREEN:
|
||||||
|
screen_render(scoreScreen, gCamera);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_menu(void)
|
run_menu(void)
|
||||||
{
|
{
|
||||||
|
@ -1141,12 +1174,8 @@ run_menu(void)
|
||||||
&& gGameState != CHARACTER_MENU)
|
&& gGameState != CHARACTER_MENU)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (gGameState == MENU)
|
|
||||||
menu_update(mainMenu, &input, gCamera);
|
menu_update(get_active_menu(), &input, gCamera);
|
||||||
else if (gGameState == CHARACTER_MENU)
|
|
||||||
menu_update(charSelectMenu, &input, gCamera);
|
|
||||||
else if (gGameState == GAME_SELECT)
|
|
||||||
menu_update(gameSelectMenu, &input, gCamera);
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
||||||
SDL_RenderClear(gRenderer);
|
SDL_RenderClear(gRenderer);
|
||||||
|
@ -1160,18 +1189,8 @@ run_menu(void)
|
||||||
|
|
||||||
SDL_RenderSetViewport(gRenderer, &mainViewport);
|
SDL_RenderSetViewport(gRenderer, &mainViewport);
|
||||||
|
|
||||||
if (gGameState == MENU)
|
render_current_screen();
|
||||||
menu_render(mainMenu, gCamera);
|
menu_render(get_active_menu(), gCamera);
|
||||||
else if (gGameState == CHARACTER_MENU) {
|
|
||||||
screen_render(characterSelectScreen, gCamera);
|
|
||||||
menu_render(charSelectMenu, gCamera);
|
|
||||||
}
|
|
||||||
else if (gGameState == GAME_SELECT)
|
|
||||||
menu_render(gameSelectMenu, gCamera);
|
|
||||||
else if (gGameState == CREDITS)
|
|
||||||
screen_render(creditsScreen, gCamera);
|
|
||||||
else if (gGameState == SCORE_SCREEN)
|
|
||||||
screen_render(scoreScreen, gCamera);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
sprite_render(fpsSprite, gCamera);
|
sprite_render(fpsSprite, gCamera);
|
||||||
|
|
|
@ -229,6 +229,9 @@ redraw_description(Menu *m, SDL_Renderer *renderer)
|
||||||
void
|
void
|
||||||
menu_update(Menu *m, Input *input, Camera *cam)
|
menu_update(Menu *m, Input *input, Camera *cam)
|
||||||
{
|
{
|
||||||
|
if (!m)
|
||||||
|
return;
|
||||||
|
|
||||||
static int lastSelected = -1;
|
static int lastSelected = -1;
|
||||||
|
|
||||||
if (handle_keyboard_input(m, input)) {
|
if (handle_keyboard_input(m, input)) {
|
||||||
|
@ -278,6 +281,9 @@ menu_item_add(Menu *m, Sprite *s1, Sprite *s2, void (*event)(void*))
|
||||||
void
|
void
|
||||||
menu_render(Menu *m, Camera *cam)
|
menu_render(Menu *m, Camera *cam)
|
||||||
{
|
{
|
||||||
|
if (!m)
|
||||||
|
return;
|
||||||
|
|
||||||
LinkedList *items = m->items;
|
LinkedList *items = m->items;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
Loading…
Reference in New Issue