RogueLife/src/comp/visible.c

47 lines
1007 B
C

#include "comp/entity.h"
#include "comp/physical.h"
#include "comp/visible.h"
void visible_set_anim(entity_t *e, anim_t const *anim, int priority)
{
visible_t *v = getcomp(e, visible);
if(priority < v->anim_priority)
return;
if(anim == NULL) {
v->anim.frame = NULL;
return;
}
int anim_index = 0;
physical_t *p = getcomp(e, physical);
if(p && anim->directions == 2) {
anim_index = (p->facing == RIGHT);
}
else if(p && anim->directions == 4) {
anim_index = p->facing;
}
if(anim_in(v->anim.frame, anim, anim_index))
return;
v->anim.frame = anim ? anim->start[anim_index] : NULL;
v->anim.elapsed = 0;
v->anim_priority = priority;
}
void visible_update(entity_t *e, fixed_t dt)
{
visible_t *v = getcomp(e, visible);
if(v->anim.frame == NULL)
return;
if(anim_state_update(&v->anim, dt))
v->anim_priority = 0;
if(v->anim.frame == NULL)
v->anim_priority = 0;
}