diff options
author | rodri <rgl@antares-labs.eu> | 2024-11-15 16:41:59 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-11-15 16:41:59 +0000 |
commit | 671c2cac38ffada7f9185b87ec27b84566db8c2b (patch) | |
tree | 51510f95222a0eb8b2f5eb96fade562618abfcb3 /vfx.c | |
parent | 423e5319e3d3501637fffb11bb5c0acd48c2f424 (diff) | |
download | battleship-671c2cac38ffada7f9185b87ec27b84566db8c2b.tar.gz battleship-671c2cac38ffada7f9185b87ec27b84566db8c2b.tar.bz2 battleship-671c2cac38ffada7f9185b87ec27b84566db8c2b.zip |
forgot the vfx units…
Diffstat (limited to 'vfx.c')
-rw-r--r-- | vfx.c | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -0,0 +1,71 @@ +#include <u.h> +#include <libc.h> +#include <thread.h> +#include <draw.h> +#include <mouse.h> +#include <keyboard.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) +{ + 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; +} |