diff options
author | rodri <rgl@antares-labs.eu> | 2023-05-22 09:00:42 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-05-22 09:00:42 +0000 |
commit | e095f65376894dcdef067b63103f2e17e55a1f14 (patch) | |
tree | a941d8ed6b6c6149aa1eee503b11a955fdcf7213 /vfx.c | |
parent | 1baca76aaf266a2d071af4a173aee5b85efeffd6 (diff) | |
download | musw-e095f65376894dcdef067b63103f2e17e55a1f14.tar.gz musw-e095f65376894dcdef067b63103f2e17e55a1f14.tar.bz2 musw-e095f65376894dcdef067b63103f2e17e55a1f14.zip |
improvements to show a bullet's explosion upon ttl consumption.
implemented a vfx subsystem to handle localized, async animations.
Diffstat (limited to 'vfx.c')
-rw-r--r-- | vfx.c | 69 |
1 files changed, 69 insertions, 0 deletions
@@ -0,0 +1,69 @@ +#include <u.h> +#include <libc.h> +#include <ip.h> +#include <mp.h> +#include <libsec.h> +#include <thread.h> +#include <draw.h> +#include <geometry.h> +#include "dat.h" +#include "fns.h" + +static void +vfx_step(Vfx *v, ulong Δt) +{ + if(v->times == 0 && v->a->curframe == 0){ + delvfx(v); + return; + } + + v->a->step(v->a, Δt); + + if(v->times > 0 && v->a->curframe == v->a->nframes-1) + v->times--; +} + +static void +vfx_draw(Vfx *v, Image *dst) +{ + v->a->draw(v->a, dst, v->p); +} + +Vfx * +newvfx(Sprite *spr, Point dp, int repeat) +{ + Vfx *v; + + v = emalloc(sizeof(Vfx)); + v->a = spr; + v->p = dp; + v->times = repeat; + v->step = vfx_step; + v->draw = vfx_draw; + + return v; +} + +void +delvfx(Vfx *v) +{ + v->next->prev = v->prev; + v->prev->next = v->next; + delsprite(v->a); + free(v); +} + +void +addvfx(Vfx *v, Vfx *nv) +{ + nv->prev = v->prev; + nv->next = v; + v->prev->next = nv; + v->prev = nv; +} + +void +initvfx(Vfx *v) +{ + v->next = v->prev = v; +} |