From 9550840a7aaab3681c1864c9fc732d54e13dd6f0 Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Thu, 1 Feb 2018 09:04:19 +0100 Subject: [PATCH] Fixed compiler warnings --- src/gui.c | 25 ++++++++++++++++++------- src/gui.h | 6 ------ src/main.c | 13 +------------ src/player.c | 2 ++ 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/gui.c b/src/gui.c index 8f7fc24..631c432 100644 --- a/src/gui.c +++ b/src/gui.c @@ -148,8 +148,8 @@ gui_create(SDL_Renderer *renderer) return gui; } -void -gui_set_max_health(Gui *gui, int max, SDL_Renderer *renderer) +static void +set_max_health(Gui *gui, int max, SDL_Renderer *renderer) { Texture *texture; int i; @@ -175,8 +175,8 @@ gui_set_max_health(Gui *gui, int max, SDL_Renderer *renderer) } } -void -gui_set_current_health(Gui *gui, int current) +static void +set_current_health(Gui *gui, int current) { int partial = current % 3; int full = (current - partial)/3; @@ -211,6 +211,8 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render static int last_xp = -1; static double last_gold = -1; static unsigned int dungeon_level = 0; + static int max_health = -1; + static int current_health = -1; static SDL_Color color = { 255, 255, 255, 255 }; @@ -223,7 +225,16 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render ExperienceData data = player_get_xp_data(player); - if (last_xp != data.current) { + if (max_health != player->stats.maxhp) { + max_health = player->stats.maxhp; + set_max_health(gui, max_health, renderer); + } + if (current_health != player->stats.hp) { + current_health = player->stats.hp; + set_current_health(gui, current_health); + } + + if (last_xp != (int) data.current) { xp_from_levelup = data.current - data.previousLevel; xp_required_from_last_level = data.nextLevel - data.previousLevel; xp_step = ((float)xp_required_from_last_level) / 32; // 4 * 8 @@ -253,7 +264,7 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render } } - if (dungeon_level != map->level) { + if (dungeon_level != (unsigned int) map->level) { m_sprintf(buffer, 200, "Dungeon level: %d", map->level); texture_load_from_text(gui->labels[DUNGEON_LEVEL_LABEL]->textures[0], buffer, color, renderer); dungeon_level = (unsigned int) map->level; @@ -265,7 +276,7 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render last_gold = player->gold; } - if (last_xp != data.current) { + if (last_xp != (int) data.current) { m_sprintf(buffer, 200, "XP: %u / %u", data.current, data.nextLevel); texture_load_from_text(gui->labels[CURRENT_XP_LABEL]->textures[0], buffer, color, renderer); last_xp = data.current; diff --git a/src/gui.h b/src/gui.h index 6448a0b..48dd537 100644 --- a/src/gui.h +++ b/src/gui.h @@ -31,12 +31,6 @@ typedef struct { Gui* gui_create(SDL_Renderer *renderer); -void -gui_set_max_health(Gui*, int max, SDL_Renderer*); - -void -gui_set_current_health(Gui*, int current); - void gui_update_player_stats(Gui*, Player*, Map*, SDL_Renderer*); diff --git a/src/main.c b/src/main.c index 842c437..2b36e1a 100644 --- a/src/main.c +++ b/src/main.c @@ -201,9 +201,6 @@ check_next_level(void) static void run_game(void) { - static unsigned int player_max_hp = 0; - static unsigned int player_current_hp = 0; - SDL_RenderSetViewport(gRenderer, NULL); map_clear_dead_monsters(gMap); map_clear_collected_items(gMap); @@ -212,16 +209,8 @@ run_game(void) &gPlayer->sprite->pos); roommatrix_build_lightmap(gRoomMatrix); - gui_update_player_stats(gGui, gPlayer, gMap, gRenderer); - if (player_max_hp != (unsigned int) gPlayer->stats.maxhp) { - gui_set_max_health(gGui, gPlayer->stats.maxhp, gRenderer); - player_max_hp = gPlayer->stats.maxhp; - } - if (player_current_hp != (unsigned int) gPlayer->stats.hp) { - gui_set_current_health(gGui, gPlayer->stats.hp); - player_current_hp = gPlayer->stats.hp; - } + gui_update_player_stats(gGui, gPlayer, gMap, gRenderer); if (gPlayer->steps >= gPlayer->stats.speed) { player_reset_steps(gPlayer); diff --git a/src/player.c b/src/player.c index 6629695..08bf5b8 100644 --- a/src/player.c +++ b/src/player.c @@ -26,6 +26,8 @@ player_levelup(Player *player) // Limit health to 3 rows of hearts if (player->stats.maxhp > 72) player->stats.maxhp = 72; + + player->stats.hp = player->stats.maxhp; } static unsigned int