From 671c2cac38ffada7f9185b87ec27b84566db8c2b Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 15 Nov 2024 16:41:59 +0000 Subject: =?UTF-8?q?forgot=20the=20vfx=20units=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vfx.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 vfx.c (limited to 'vfx.c') diff --git a/vfx.c b/vfx.c new file mode 100644 index 0000000..787a67d --- /dev/null +++ b/vfx.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#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) +{ + if(v->times == 0 && v->a->curframe == 0) + return; + + v->a->draw(v->a, dst, subpt(v->p, divpt(subpt(v->a->r.max, v->a->r.min), 2))); +} + +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 +initvfxq(Vfx *v) +{ + v->next = v->prev = v; +} -- cgit v1.2.3