diff options
author | quou <quou@disroot.org> | 2023-05-04 10:15:19 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-04 10:15:19 +1000 |
commit | c4ac81cffcf925963acb0c02584ab22626427a73 (patch) | |
tree | 7d6421405e53a92baada909355c5398f21e91864 /animation_system.c | |
parent | c4ee81da673208fe7b3e3638692fd466acf61c3f (diff) |
Add an animation system.
Diffstat (limited to 'animation_system.c')
-rw-r--r-- | animation_system.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/animation_system.c b/animation_system.c new file mode 100644 index 0000000..22317ac --- /dev/null +++ b/animation_system.c @@ -0,0 +1,33 @@ +#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]; + } + } +} |