Got a bit further

This commit is contained in:
Linus Probert 2018-09-12 20:56:50 +02:00
parent f246c5751a
commit 02a4407eb4
4 changed files with 68 additions and 21 deletions

View File

@ -25,6 +25,7 @@ typedef enum GameState_t {
SCORE_SCREEN, SCORE_SCREEN,
PLAYING, PLAYING,
IN_GAME_MENU, IN_GAME_MENU,
CHARACTER_MENU,
GAME_OVER, GAME_OVER,
COMPLETED, COMPLETED,
QUIT QUIT

View File

@ -144,6 +144,7 @@ static Gui *gGui = NULL;
static SkillBar *gSkillBar = NULL; static SkillBar *gSkillBar = NULL;
static Menu *mainMenu = NULL; static Menu *mainMenu = NULL;
static Menu *inGameMenu = NULL; static Menu *inGameMenu = NULL;
static Menu *charSelectMenu = NULL;
static Timer *menuTimer = NULL; static Timer *menuTimer = NULL;
static Camera *gCamera = NULL; static Camera *gCamera = NULL;
static Screen *creditsScreen = NULL; static Screen *creditsScreen = NULL;
@ -155,6 +156,7 @@ static unsigned int cLevel = 1;
static float deltaTime = 1.0; static float deltaTime = 1.0;
static double renderScale = 1.0; static double renderScale = 1.0;
static Turn currentTurn = PLAYER; static Turn currentTurn = PLAYER;
static class_t playerClass = WARRIOR;
static GameState gGameState; static GameState gGameState;
static SDL_Rect mainViewport; static SDL_Rect mainViewport;
static SDL_Rect gameViewport; static SDL_Rect gameViewport;
@ -304,9 +306,8 @@ initGame(void)
} }
static void static void
startGame(void *unused) startGame(void)
{ {
UNUSED(unused);
cLevel = 1; cLevel = 1;
gGameState = PLAYING; gGameState = PLAYING;
if (gPlayer) if (gPlayer)
@ -348,6 +349,25 @@ toggleInGameMenu(void *unused)
gGameState = PLAYING; 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 static void
goToMainMenu(void *unused) goToMainMenu(void *unused)
{ {
@ -388,7 +408,7 @@ static void
createInGameGameOverMenu(void) createInGameGameOverMenu(void)
{ {
static TEXT_MENU_ITEM menu_items[] = { static TEXT_MENU_ITEM menu_items[] = {
{ "NEW GAME", startGame }, { "NEW GAME", goToCharacterMenu },
{ "MAIN MENU", goToMainMenu }, { "MAIN MENU", goToMainMenu },
{ "QUIT", exitGame }, { "QUIT", exitGame },
}; };
@ -418,7 +438,7 @@ static void
initMainMenu(void) initMainMenu(void)
{ {
static TEXT_MENU_ITEM menu_items[] = { static TEXT_MENU_ITEM menu_items[] = {
{ "PLAY", startGame }, { "PLAY", goToCharacterMenu },
{ "SCORES", viewScoreScreen }, { "SCORES", viewScoreScreen },
{ "CREDITS", viewCredits }, { "CREDITS", viewCredits },
{ "QUIT", exitGame }, { "QUIT", exitGame },
@ -452,6 +472,9 @@ resetGame(void)
if (mainMenu) if (mainMenu)
menu_destroy(mainMenu); menu_destroy(mainMenu);
mainMenu = NULL; mainMenu = NULL;
if (charSelectMenu)
menu_destroy(charSelectMenu);
charSelectMenu = NULL;
if (creditsScreen) if (creditsScreen)
screen_destroy(creditsScreen); screen_destroy(creditsScreen);
@ -891,10 +914,17 @@ run_menu(void)
map_move_monsters(gMap, gRoomMatrix); map_move_monsters(gMap, gRoomMatrix);
} }
menu_update(mainMenu, &input); if (gGameState != MENU
if (gGameState != MENU && gGameState != CREDITS && gGameState != SCORE_SCREEN) && gGameState != CREDITS
&& gGameState != SCORE_SCREEN
&& gGameState != CHARACTER_MENU)
return; 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_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
SDL_RenderClear(gRenderer); SDL_RenderClear(gRenderer);
SDL_RenderSetViewport(gRenderer, &menuViewport); SDL_RenderSetViewport(gRenderer, &menuViewport);
@ -907,6 +937,8 @@ run_menu(void)
if (gGameState == MENU) if (gGameState == MENU)
menu_render(mainMenu, gCamera); menu_render(mainMenu, gCamera);
if (gGameState == CHARACTER_MENU)
menu_render(charSelectMenu, gCamera);
else if (gGameState == CREDITS) else if (gGameState == CREDITS)
screen_render(creditsScreen, gCamera); screen_render(creditsScreen, gCamera);
else if (gGameState == SCORE_SCREEN) else if (gGameState == SCORE_SCREEN)
@ -962,6 +994,7 @@ run(void)
case MENU: case MENU:
case CREDITS: case CREDITS:
case SCORE_SCREEN: case SCORE_SCREEN:
case CHARACTER_MENU:
run_menu(); run_menu();
break; break;
case QUIT: case QUIT:

View File

@ -84,25 +84,38 @@ menu_create_text_menu(Menu **menu, TEXT_MENU_ITEM *menu_items, unsigned int size
} }
Menu * Menu *
menu_create_character_selector(void (*onCharacterSelect)(const char **)) menu_create_character_selector(void (*onCharacterSelect)(const char *))
{ {
const char *spriteSheets[] = { const char *spriteSheets[] = {
"Comissions/Warrior.png", "Commissions/Warrior.png",
} "Commissions/Rogue.png"
};
char *callbackData[] = {
"warrior",
"rogue"
};
Menu *menu = menu_create(); 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 *s2 = sprite_create();
sprite_set_texture(s1, texturecache_add(), 0); sprite_set_texture(s2, texturecache_add(spriteSheets[i]), 0);
s1->clip = CLIP16(0, 0); s2->clip = CLIP16(0, 48);
s1->dim = DIM(32, 32); s2->dim = DIM(64, 64);
s2->pos = POS((SCREEN_WIDTH + 16)/2, yoffset);
Sprite *s2 = sprite_create(); menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
sprite_set_texture(s2, texturecache_add("Commissions/Warrior.png"), 1); MenuItem *item = linkedlist_get(&menu->items, (Uint32) i);
s2->clip = CLIP16(0, 48); item->button->usrdata = callbackData[i];
s2->dim = DIM(32, 32); yoffset += 100;
}
MenuItem *item
menu_item_add(menu, s1, s2, (void (*)(void *)) onCharacterSelect);
return menu; return menu;
} }

View File

@ -42,7 +42,7 @@ void
menu_create_text_menu(Menu **menu, TEXT_MENU_ITEM *menu_items, unsigned int size, SDL_Renderer *); menu_create_text_menu(Menu **menu, TEXT_MENU_ITEM *menu_items, unsigned int size, SDL_Renderer *);
Menu * Menu *
menu_create_character_selector(void (*onCharacterSelect)(const char **)); menu_create_character_selector(void (*onCharacterSelect)(const char *));
void void
menu_update(Menu*, Input*); menu_update(Menu*, Input*);