Refactored and fixed some Codacy issues

This commit is contained in:
Linus_Probert 2018-02-06 09:11:04 +01:00
parent 73e300e343
commit 22f6d36375
2 changed files with 34 additions and 34 deletions

View File

@ -221,51 +221,19 @@ set_current_health(Gui *gui, int current)
} }
} }
void static void
gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *renderer) update_xp_bar(Gui *gui, ExperienceData *data)
{ {
// TODO(Linus): Perhaps split this up a bit? unsigned int xp_from_levelup = data->current - data->previousLevel;
// some static functions maybe? unsigned int xp_required_from_last_level = data->nextLevel - data->previousLevel;
float xp_step = ((float)xp_required_from_last_level) / 32; // 4 * 8
float xp_current_step = xp_from_levelup / xp_step;
static unsigned int last_level = 0; unsigned int partial_xp_block = ((unsigned int) xp_current_step) % 4;
static int last_xp = -1; unsigned int full_xp_blocks = (unsigned int) ((xp_current_step - partial_xp_block) / 4);
static double last_gold = -1;
static unsigned int dungeon_level = 0;
static int max_health = -1;
static int current_health = -1;
static int current_potion_sips = -1;
static SDL_Color color = { 255, 255, 255, 255 }; LinkedList *xp_bars = gui->xp_bar;
unsigned int i = 0;
unsigned int xp_from_levelup, xp_required_from_last_level;
float xp_step, xp_current_step;
unsigned int full_xp_blocks, partial_xp_block;
LinkedList *xp_bars;
unsigned int i;
char buffer[200];
ExperienceData data = player_get_xp_data(player);
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
xp_current_step = xp_from_levelup / xp_step;
partial_xp_block = ((unsigned int)xp_current_step) % 4;
full_xp_blocks = (unsigned int)((xp_current_step - partial_xp_block) / 4);
xp_bars = gui->xp_bar;
i = 0;
while (xp_bars != NULL) { while (xp_bars != NULL) {
Sprite *s = xp_bars->data; Sprite *s = xp_bars->data;
s->hidden = false; s->hidden = false;
@ -283,6 +251,39 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render
++i; ++i;
} }
}
void
gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *renderer)
{
// TODO(Linus): Perhaps split this up a bit?
// some static functions maybe?
static unsigned int last_level = 0;
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 int current_potion_sips = -1;
static SDL_Color color = { 255, 255, 255, 255 };
char buffer[200];
ExperienceData data = player_get_xp_data(player);
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) {
update_xp_bar(gui, &data);
} }
if (dungeon_level != (unsigned int) map->level) { if (dungeon_level != (unsigned int) map->level) {

View File

@ -86,13 +86,12 @@ particle_engine_update(float deltaTime)
{ {
check_engine(); check_engine();
LinkedList *current, *last; LinkedList *current, *last;
Particle *particle;
current = engine->particles; current = engine->particles;
last = NULL; last = NULL;
while (current) { while (current) {
particle = current->data; Particle *particle = current->data;
if (particle->movetime) if (particle->movetime)
particle->movetime--; particle->movetime--;