Restructured main game loop a bit. Reduced function size

This commit is contained in:
Linus Probert 2018-07-28 14:28:55 +02:00
parent 252955bc8d
commit 18e70221fa
1 changed files with 15 additions and 2 deletions

View File

@ -473,7 +473,7 @@ populateUpdateData(UpdateData *data, float deltatime)
} }
static void static void
run_game(void) run_game_update(void)
{ {
static UpdateData updateData; static UpdateData updateData;
static unsigned int playerLevel = 1; static unsigned int playerLevel = 1;
@ -518,7 +518,11 @@ run_game(void)
currentTurn = PLAYER; currentTurn = PLAYER;
} }
} }
}
static void
run_game_render(void)
{
SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0); SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 0);
SDL_RenderClear(gRenderer); SDL_RenderClear(gRenderer);
@ -531,6 +535,7 @@ run_game(void)
map_render_top_layer(gMap, gCamera); map_render_top_layer(gMap, gCamera);
if (!is_player_dead())
player_render_toplayer(gPlayer, gCamera); player_render_toplayer(gPlayer, gCamera);
if (gPlayer->class == MAGE || gPlayer->class == PALADIN) if (gPlayer->class == MAGE || gPlayer->class == PALADIN)
@ -561,6 +566,14 @@ run_game(void)
pointer_render(gPointer, gCamera); pointer_render(gPointer, gCamera);
SDL_RenderPresent(gRenderer); SDL_RenderPresent(gRenderer);
}
static void
run_game(void)
{
run_game_update();
run_game_render();
if (gGameState == PLAYING && is_player_dead()) { if (gGameState == PLAYING && is_player_dead()) {
camera_shake(VECTOR2D_RIGHT, 800); camera_shake(VECTOR2D_RIGHT, 800);