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,6 +221,38 @@ set_current_health(Gui *gui, int current)
} }
} }
static void
update_xp_bar(Gui *gui, ExperienceData *data)
{
unsigned int xp_from_levelup = data->current - data->previousLevel;
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;
unsigned int partial_xp_block = ((unsigned int) xp_current_step) % 4;
unsigned int full_xp_blocks = (unsigned int) ((xp_current_step - partial_xp_block) / 4);
LinkedList *xp_bars = gui->xp_bar;
unsigned int i = 0;
while (xp_bars != NULL) {
Sprite *s = xp_bars->data;
s->hidden = false;
xp_bars = xp_bars->next;
if (i < full_xp_blocks) {
s->clip.x = 6 * 16;
}
else if (i == full_xp_blocks && partial_xp_block != 0) {
s->clip.x = (6 * 16) + (16 * (4 - partial_xp_block));
}
else {
s->hidden = true;
}
++i;
}
}
void void
gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *renderer) gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *renderer)
{ {
@ -237,11 +269,6 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render
static SDL_Color color = { 255, 255, 255, 255 }; static SDL_Color color = { 255, 255, 255, 255 };
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]; char buffer[200];
ExperienceData data = player_get_xp_data(player); ExperienceData data = player_get_xp_data(player);
@ -256,33 +283,7 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render
} }
if (last_xp != (int) data.current) { if (last_xp != (int) data.current) {
xp_from_levelup = data.current - data.previousLevel; update_xp_bar(gui, &data);
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) {
Sprite *s = xp_bars->data;
s->hidden = false;
xp_bars = xp_bars->next;
if (i < full_xp_blocks) {
s->clip.x = 6 * 16;
}
else if (i == full_xp_blocks && partial_xp_block != 0) {
s->clip.x = (6 * 16) + (16 * (4 - partial_xp_block));
}
else {
s->hidden = true;
}
++i;
}
} }
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--;