From 0b338bbd007048551526ab4fa4130d53b414e650 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Wed, 24 Feb 2021 16:38:42 +0100 Subject: fire and movement animations --- gst/fxs.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 gst/fxs.c (limited to 'gst/fxs.c') diff --git a/gst/fxs.c b/gst/fxs.c new file mode 100644 index 0000000..2078a89 --- /dev/null +++ b/gst/fxs.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#include + +void fx_init (fxs *fx) { + fx->bullets = (bullet*)malloc(sizeof(bullet)*1024); + fx->bulletslen = 0; +} + +void fx_add_bullet (fxs *fx, bullet *b) { + fx->bullets[fx->bulletslen] = *b; + fx->bulletslen++; +} + +void fx_process (fxs *fx, float time) { + for (int i=0; ibulletslen; i++) { + bullet *b = fx->bullets+i; + if (time > b->endtime) { + // remove by replacing with last, dont care for order + *b = fx->bullets[fx->bulletslen-1]; + fx->bulletslen--; + } + } +} + + +void fx_render (SDL_Renderer *rend, fxs *fx, float cam[], float time) { + for (int i=0; ibulletslen; i++) { + bullet *b = fx->bullets+i; + float travel_time = b->endtime - b->starttime; + float interval_time = time - b->starttime; + float amt = interval_time / travel_time; + if (amt < 0) amt = 0; if (amt > 1) amt = 1; + float pos[2] = { + b->from[0] *(1-amt) + b->to[0] *amt, + b->from[1] *(1-amt) + b->to[1] *amt + }; + float head[2]; vec2_sub(head, b->from, b->to); + vec2_norm(head); vec2_mul(head, head, 10); + SDL_SetRenderDrawColor(rend, + b->color[0], + b->color[1], + b->color[2], + 255); + SDL_RenderDrawLine(rend, + -cam[0] + pos[0], + -cam[1] + pos[1], + -cam[0] + pos[0] + head[0], + -cam[1] + pos[1] + head[1] + ); + } +} -- cgit v1.2.3-54-g00ecf