Very basic animations

This commit is contained in:
2023-11-12 18:03:55 +01:00
parent bf56b150cc
commit 526d292fb5
9 changed files with 95 additions and 6 deletions

17
game/systems/animations.c Normal file
View File

@@ -0,0 +1,17 @@
#include "systems.h"
void updateAnimations(ecs_iter_t *it) {
Animation *anim = ecs_field(it, Animation, 1);
TextureRegion *t = ecs_field(it, TextureRegion, 2);
float dt = GetFrameTime();
for (i32 i = 0; i < it->count; i++) {
anim[i].elapsed += dt;
if (anim[i].elapsed < anim[i].frameDuration) continue;
anim[i].currFrame = (anim[i].currFrame + 1) % anim[i].frameCount;
anim[i].elapsed = 0.0f;
t[i].rec.x = anim[i].firstFrame.rec.x + anim[i].currFrame * t[i].rec.width;
}
}

View File

@@ -6,5 +6,6 @@
#include "../components.h"
void renderEntities(ecs_iter_t *it);
void updateAnimations(ecs_iter_t *it);
#endif //PIXELDEFENSE_SYSTEMS_H