#include "animation.h" #include "components.h" #include "world.h" void animation_system(World* world) { int i; unsigned bits; CSprite* sprite; CAnimated* animated; const Animation* animation; for (i = 0; i < world->entity_count; i++) { bits = world->bitmask[i]; if ((bits & ctype_sprite) && (bits & ctype_animated)) { sprite = &world->sprites[i]; animated = &world->animateds[i]; animation = get_animation(animated->id); animated->timer++; if (animated->timer > animation->slowness) { animated->frame++; animated->timer = 0; } if (animated->frame >= animation->frame_count) { animated->frame = 0; animated->timer = 0; } sprite->rect = animation->frames[animated->frame]; } } }