Adds: Flashing healthbar when low on health
This commit is contained in:
parent
738102b6e6
commit
9286fddd3c
11
src/gui.c
11
src/gui.c
|
@ -189,7 +189,7 @@ gui_create(SDL_Renderer *renderer)
|
||||||
static void
|
static void
|
||||||
set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
||||||
{
|
{
|
||||||
Texture *texture;
|
Texture *texture0, *texture1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
assert(max % 3 == 0);
|
assert(max % 3 == 0);
|
||||||
|
@ -201,14 +201,17 @@ set_max_health(Gui *gui, int max, SDL_Renderer *renderer)
|
||||||
while (gui->health != NULL)
|
while (gui->health != NULL)
|
||||||
sprite_destroy(linkedlist_pop(&gui->health));
|
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) {
|
for (i = 0; i < max/3; ++i) {
|
||||||
Sprite *sprite = sprite_create();
|
Sprite *sprite = sprite_create();
|
||||||
sprite->fixed = true;
|
sprite->fixed = true;
|
||||||
|
sprite->animate = false;
|
||||||
sprite->clip = (SDL_Rect) { 0, 16, 16, 16 };
|
sprite->clip = (SDL_Rect) { 0, 16, 16, 16 };
|
||||||
sprite->pos = (Position) { 16 + (i%8)*16, 16 + ((i-(i%8))/8)*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);
|
linkedlist_append(&gui->health, sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +237,8 @@ set_current_health(Gui *gui, int current)
|
||||||
sprite->clip.x = 64;
|
sprite->clip.x = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprite->animate = current < 9;
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
item = item->next;
|
item = item->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ sprite_create_default(void)
|
||||||
s->renderTimer = timer_create();
|
s->renderTimer = timer_create();
|
||||||
s->texture_index = 0;
|
s->texture_index = 0;
|
||||||
s->fixed = false;
|
s->fixed = false;
|
||||||
|
s->animate = true;
|
||||||
s->hidden = false;
|
s->hidden = false;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
@ -93,7 +94,7 @@ void sprite_render(Sprite *s, Camera *cam)
|
||||||
if (s->hidden)
|
if (s->hidden)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s->textures[1]) {
|
if (s->textures[1] && s->animate) {
|
||||||
if (!timer_started(s->renderTimer))
|
if (!timer_started(s->renderTimer))
|
||||||
timer_start(s->renderTimer);
|
timer_start(s->renderTimer);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef struct Sprite_t {
|
||||||
Timer *renderTimer;
|
Timer *renderTimer;
|
||||||
unsigned int texture_index;
|
unsigned int texture_index;
|
||||||
bool fixed;
|
bool fixed;
|
||||||
|
bool animate;
|
||||||
bool hidden;
|
bool hidden;
|
||||||
} Sprite;
|
} Sprite;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue