Add idle animation

This commit is contained in:
2023-12-05 11:25:56 +01:00
parent abc8cf2b48
commit 0d137ffb25
14 changed files with 344 additions and 30 deletions

View File

@@ -20,7 +20,7 @@ void entitySpatialRemoved(ecs_iter_t *it) {
}
void pathRemoved(ecs_iter_t *it) {
void entityPathRemoved(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
BzObjectPool *pool = game->pools.pathData;
Path *path = ecs_field(it, Path, 1);
@@ -34,6 +34,18 @@ void pathRemoved(ecs_iter_t *it) {
}
}
void entitySetAnimationState(ecs_iter_t *it) {
Animation *anim = ecs_field(it, Animation, 1);
AnimationType *animType = ecs_field(it, AnimationType , 2);
for (i32 i = 0; i < it->count; i++) {
EntityType entityType = anim[i].entityType;
AnimationType type = animType[i];
BZ_ASSERT(entityHasAnimation(entityType, type));
anim[i].animType = type;
anim[i].sequence = getEntityAnimation(entityType, type);
}
}
void entityUpdateSpatialID(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Position *position = ecs_field(it, Position, 1);
@@ -109,7 +121,7 @@ void entityFollowPath(ecs_iter_t *it) {
}
}
void updateAnimations(ecs_iter_t *it) {
void entityUpdateAnimation(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Animation *anim = ecs_field(it, Animation, 1);
TextureRegion *t = ecs_field(it, TextureRegion, 2);
@@ -121,9 +133,11 @@ void updateAnimations(ecs_iter_t *it) {
anim[i].elapsed += dt;
if (anim[i].elapsed < anim[i].frameDuration) continue;
anim[i].currFrame = (anim[i].currFrame + 1) % anim[i].frameCount;
anim[i].curFrame = (anim[i].curFrame + 1) % anim[i].sequence.frameCount;
BzTile tile = anim[i].sequence.startFrame + anim[i].curFrame + anim[i].tileset->startID;
t[i].rec = bzTilesetGetTileRegion(anim[i].tileset, tile);
anim[i].elapsed = 0.0f;
t[i].rec.x = anim[i].firstFrame.rec.x + anim[i].currFrame * t[i].rec.width;
}
}