Adds: Flashing healthbar when low on health

This commit is contained in:
Linus_Probert 2018-02-23 11:10:50 +01:00
parent 738102b6e6
commit 9286fddd3c
3 changed files with 11 additions and 4 deletions

View File

@ -189,7 +189,7 @@ gui_create(SDL_Renderer *renderer)
static void
set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
{
Texture *texture;
Texture *texture0, *texture1;
int i;
assert(max % 3 == 0);
@ -201,14 +201,17 @@ set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
while (gui->health != NULL)
sprite_destroy(linkedlist_pop(&gui->health));
texture = add_texture(gui, "GUI/GUI0.png", renderer);
texture0 = add_texture(gui, "GUI/GUI0.png", renderer);
texture1 = add_texture(gui, "GUI/GUI1.png", renderer);
for (i = 0; i < max/3; ++i) {
Sprite *sprite = sprite_create();
sprite->fixed = true;
sprite->animate = false;
sprite->clip = (SDL_Rect) { 0, 16, 16, 16 };
sprite->pos = (Position) { 16 + (i%8)*16, 16 + ((i-(i%8))/8)*16 };
sprite_set_texture(sprite, texture, 0);
sprite_set_texture(sprite, texture0, 0);
sprite_set_texture(sprite, texture1, 1);
linkedlist_append(&gui->health, sprite);
}
}
@ -234,6 +237,8 @@ set_current_health(Gui *gui, int current)
sprite->clip.x = 64;
}
sprite->animate = current < 9;
++count;
item = item->next;
}

View File

@ -32,6 +32,7 @@ sprite_create_default(void)
s->renderTimer = timer_create();
s->texture_index = 0;
s->fixed = false;
s->animate = true;
s->hidden = false;
return s;
@ -93,7 +94,7 @@ void sprite_render(Sprite *s, Camera *cam)
if (s->hidden)
return;
if (s->textures[1]) {
if (s->textures[1] && s->animate) {
if (!timer_started(s->renderTimer))
timer_start(s->renderTimer);

View File

@ -35,6 +35,7 @@ typedef struct Sprite_t {
Timer *renderTimer;
unsigned int texture_index;
bool fixed;
bool animate;
bool hidden;
} Sprite;