Got a bit further
This commit is contained in:
parent
f246c5751a
commit
02a4407eb4
|
@ -25,6 +25,7 @@ typedef enum GameState_t {
|
|||
SCORE_SCREEN,
|
||||
PLAYING,
|
||||
IN_GAME_MENU,
|
||||
CHARACTER_MENU,
|
||||
GAME_OVER,
|
||||
COMPLETED,
|
||||
QUIT
|
||||
|
|
45
src/main.c
45
src/main.c
|
@ -144,6 +144,7 @@ static Gui *gGui = NULL;
|
|||
static SkillBar *gSkillBar = NULL;
|
||||
static Menu *mainMenu = NULL;
|
||||
static Menu *inGameMenu = NULL;
|
||||
static Menu *charSelectMenu = NULL;
|
||||
static Timer *menuTimer = NULL;
|
||||
static Camera *gCamera = NULL;
|
||||
static Screen *creditsScreen = NULL;
|
||||
|
@ -155,6 +156,7 @@ static unsigned int cLevel = 1;
|
|||
static float deltaTime = 1.0;
|
||||
static double renderScale = 1.0;
|
||||
static Turn currentTurn = PLAYER;
|
||||
static class_t playerClass = WARRIOR;
|
||||
static GameState gGameState;
|
||||
static SDL_Rect mainViewport;
|
||||
static SDL_Rect gameViewport;
|
||||
|
@ -304,9 +306,8 @@ initGame(void)
|
|||
}
|
||||
|
||||
static void
|
||||
startGame(void *unused)
|
||||
startGame(void)
|
||||
{
|
||||
UNUSED(unused);
|
||||
cLevel = 1;
|
||||
gGameState = PLAYING;
|
||||
if (gPlayer)
|
||||
|
@ -348,6 +349,25 @@ toggleInGameMenu(void *unused)
|
|||
gGameState = PLAYING;
|
||||
}
|
||||
|
||||
static void
|
||||
on_character_select(const char *str)
|
||||
{
|
||||
if (strcmp(str, "warrior") == 0)
|
||||
playerClass = WARRIOR;
|
||||
else if (strcmp(str, "rogue") == 0)
|
||||
playerClass = ROGUE;
|
||||
|
||||
startGame();
|
||||
}
|
||||
|
||||
static void
|
||||
goToCharacterMenu(void *unused)
|
||||
{
|
||||
UNUSED(unused);
|
||||
charSelectMenu = menu_create_character_selector(on_character_select);
|
||||
gGameState = CHARACTER_MENU;
|
||||
}
|
||||
|
||||
static void
|
||||
goToMainMenu(void *unused)
|
||||
{
|
||||
|
@ -388,7 +408,7 @@ static void
|
|||
createInGameGameOverMenu(void)
|
||||
{
|
||||
static TEXT_MENU_ITEM menu_items[] = {
|
||||
{ "NEW GAME", startGame },
|
||||
{ "NEW GAME", goToCharacterMenu },
|
||||
{ "MAIN MENU", goToMainMenu },
|
||||
{ "QUIT", exitGame },
|
||||
};
|
||||
|
@ -418,7 +438,7 @@ static void
|
|||
initMainMenu(void)
|
||||
{
|
||||
static TEXT_MENU_ITEM menu_items[] = {
|
||||
{ "PLAY", startGame },
|
||||
{ "PLAY", goToCharacterMenu },
|
||||
{ "SCORES", viewScoreScreen },
|
||||
{ "CREDITS", viewCredits },
|
||||
{ "QUIT", exitGame },
|
||||
|
@ -452,6 +472,9 @@ resetGame(void)
|
|||
if (mainMenu)
|
||||
menu_destroy(mainMenu);
|
||||
mainMenu = NULL;
|
||||
if (charSelectMenu)
|
||||
menu_destroy(charSelectMenu);
|
||||
charSelectMenu = NULL;
|
||||
|
||||
if (creditsScreen)
|
||||
screen_destroy(creditsScreen);
|
||||
|
@ -891,10 +914,17 @@ run_menu(void)
|
|||
map_move_monsters(gMap, gRoomMatrix);
|
||||
}
|
||||
|
||||
menu_update(mainMenu, &input);
|
||||
if (gGameState != MENU && gGameState != CREDITS && gGameState != SCORE_SCREEN)
|
||||
if (gGameState != MENU
|
||||
&& gGameState != CREDITS
|
||||
&& gGameState != SCORE_SCREEN
|
||||
&& gGameState != CHARACTER_MENU)
|
||||
return;
|
||||
|
||||
if (gGameState == MENU)
|
||||
menu_update(mainMenu, &input);
|
||||
else if (gGameState == CHARACTER_MENU)
|
||||
menu_update(charSelectMenu, &input);
|
||||
|
||||
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(gRenderer);
|
||||
SDL_RenderSetViewport(gRenderer, &menuViewport);
|
||||
|
@ -907,6 +937,8 @@ run_menu(void)
|
|||
|
||||
if (gGameState == MENU)
|
||||
menu_render(mainMenu, gCamera);
|
||||
if (gGameState == CHARACTER_MENU)
|
||||
menu_render(charSelectMenu, gCamera);
|
||||
else if (gGameState == CREDITS)
|
||||
screen_render(creditsScreen, gCamera);
|
||||
else if (gGameState == SCORE_SCREEN)
|
||||
|
@ -962,6 +994,7 @@ run(void)
|
|||
case MENU:
|
||||
case CREDITS:
|
||||
case SCORE_SCREEN:
|
||||
case CHARACTER_MENU:
|
||||
run_menu();
|
||||
break;
|
||||
case QUIT:
|
||||
|
|
41
src/menu.c
41
src/menu.c
|
@ -84,25 +84,38 @@ menu_create_text_menu(Menu **menu, TEXT_MENU_ITEM *menu_items, unsigned int size
|
|||
}
|
||||
|
||||
Menu *
|
||||
menu_create_character_selector(void (*onCharacterSelect)(const char **))
|
||||
menu_create_character_selector(void (*onCharacterSelect)(const char *))
|
||||
{
|
||||
const char *spriteSheets[] = {
|
||||
"Comissions/Warrior.png",
|
||||
}
|
||||
"Commissions/Warrior.png",
|
||||
"Commissions/Rogue.png"
|
||||
};
|
||||
|
||||
char *callbackData[] = {
|
||||
"warrior",
|
||||
"rogue"
|
||||
};
|
||||
|
||||
Menu *menu = menu_create();
|
||||
int yoffset = 100;
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
Sprite *s1 = sprite_create();
|
||||
sprite_set_texture(s1, texturecache_add(spriteSheets[i]), 0);
|
||||
s1->clip = CLIP16(0, 0);
|
||||
s1->dim = DIM(64, 64);
|
||||
s1->pos = POS((SCREEN_WIDTH + 16)/2, yoffset);
|
||||
|
||||
Sprite *s1 = sprite_create();
|
||||
sprite_set_texture(s1, texturecache_add(), 0);
|
||||
s1->clip = CLIP16(0, 0);
|
||||
s1->dim = DIM(32, 32);
|
||||
Sprite *s2 = sprite_create();
|
||||
sprite_set_texture(s2, texturecache_add(spriteSheets[i]), 0);
|
||||
s2->clip = CLIP16(0, 48);
|
||||
s2->dim = DIM(64, 64);
|
||||
s2->pos = POS((SCREEN_WIDTH + 16)/2, yoffset);
|
||||
|
||||
Sprite *s2 = sprite_create();
|
||||
sprite_set_texture(s2, texturecache_add("Commissions/Warrior.png"), 1);
|
||||
s2->clip = CLIP16(0, 48);
|
||||
s2->dim = DIM(32, 32);
|
||||
|
||||
MenuItem *item
|
||||
menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
|
||||
menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
|
||||
MenuItem *item = linkedlist_get(&menu->items, (Uint32) i);
|
||||
item->button->usrdata = callbackData[i];
|
||||
yoffset += 100;
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ void
|
|||
menu_create_text_menu(Menu **menu, TEXT_MENU_ITEM *menu_items, unsigned int size, SDL_Renderer *);
|
||||
|
||||
Menu *
|
||||
menu_create_character_selector(void (*onCharacterSelect)(const char **));
|
||||
menu_create_character_selector(void (*onCharacterSelect)(const char *));
|
||||
|
||||
void
|
||||
menu_update(Menu*, Input*);
|
||||
|
|
Loading…
Reference in New Issue