From 9286fddd3c216acbbc835741bce28afe75110892 Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Fri, 23 Feb 2018 11:10:50 +0100 Subject: [PATCH] Adds: Flashing healthbar when low on health --- src/gui.c | 11 ++++++++--- src/sprite.c | 3 ++- src/sprite.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui.c b/src/gui.c index ea87fd2..892792a 100644 --- a/src/gui.c +++ b/src/gui.c @@ -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; } diff --git a/src/sprite.c b/src/sprite.c index 21a09e1..711eedf 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -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); diff --git a/src/sprite.h b/src/sprite.h index 38e0ccc..2c95656 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -35,6 +35,7 @@ typedef struct Sprite_t { Timer *renderTimer; unsigned int texture_index; bool fixed; + bool animate; bool hidden; } Sprite;