#include "anim.h" #include "camera.h" #include "raygint/display.h" #include "vec.h" #include struct Anim anim_new(bopti_image_t *texture, int x, int y, int frame_width, int frame_duration, int loop) { struct Anim anim; anim.texture = texture; anim.pos = VEC(x, y); #ifdef GINT anim.frame_dim = VEC(frame_width, texture->height); anim.life_ini = frame_duration * texture->width / frame_width; #endif #ifdef RAYLIB anim.frame_dim = VEC(frame_width, frame_width); anim.life_ini = frame_duration * anim.frame_dim.x * 8; #endif anim.frame_duration = frame_duration; anim.frame = 0; anim.life = anim.life_ini; anim.loop = loop; anim.callback = NULL; return anim; } void anim_update(struct Anim *a) { if (!a->life) return; a->life--; if (a->life % a->frame_duration == 0) a->frame++; if (!a->life && a->callback != NULL) a->callback(a); /* loop */ if (!a->life && a->loop) { a->frame = 0; a->life = a->life_ini; } } #ifdef GINT void anim_draw(struct Anim *a) { if (a->life) { const struct Vec off = camera_offset(); const int x = a->pos.x + off.x; const int y = a->pos.y + off.y; const int rx = a->frame * a->frame_dim.x; const int ry = 0; dsubimage(x, y, a->texture, rx, ry, a->frame_dim.x, a->frame_dim.y, DIMAGE_NONE); } } #endif #ifdef RAYLIB void anim_draw(struct Anim *a) { if (a->life) { const struct Vec off = camera_offset(); const int x1 = a->pos.x + off.x; const int y1 = a->pos.y + off.y; const int x2 = x1 + a->frame_dim.x - 1; const int y2 = y1 + a->frame_dim.y - 1; drect(x1, y1, x2, y2, C_BLUE); } } #endif