diff --git a/game/main.c b/game/main.c index 70f0580..50e0a12 100644 --- a/game/main.c +++ b/game/main.c @@ -151,6 +151,7 @@ bool init(void *userData) { ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Rotation, Velocity, AngularVelocity, SteeringOutput); ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Position, Rotation, Velocity, AngularVelocity, SteeringOutput, Path); + ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Velocity, AnimationType); ECS_SYSTEM(ECS, entityUpdateAnimation, EcsOnUpdate, Animation, TextureRegion); ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path); diff --git a/game/systems.h b/game/systems.h index 4f38c0e..9979ab8 100644 --- a/game/systems.h +++ b/game/systems.h @@ -25,10 +25,11 @@ void entityPathRemoved(ecs_iter_t *it); /* Observer (for updating animation state) * 1: Animation - * 2: EntityState + * 2: AnimationType */ void entitySetAnimationState(ecs_iter_t *it); + /* * 0: Game (singleton) for entity map * 1: Position @@ -59,6 +60,11 @@ void entityUpdateKinematic(ecs_iter_t *it); */ void entityFollowPath(ecs_iter_t *it); +/* + * 1: Velocity + * 2: AnimationType + */ +void entityUpdateAnimationState(ecs_iter_t *it); /* * 0: * 1: Animation @@ -66,6 +72,7 @@ void entityFollowPath(ecs_iter_t *it); */ void entityUpdateAnimation(ecs_iter_t *it); + /* * 0: */ diff --git a/game/systems_entity.c b/game/systems_entity.c index ba7e3b0..cc529e7 100644 --- a/game/systems_entity.c +++ b/game/systems_entity.c @@ -121,6 +121,20 @@ void entityFollowPath(ecs_iter_t *it) { } } +void entityUpdateAnimationState(ecs_iter_t *it) { + Velocity *velocity = ecs_field(it, Velocity, 1); + //AnimationType *animType = ecs_field(it, AnimationType , 2); + for (i32 i = 0; i < it->count; i++) { + f32 len = Vector2Length(velocity[i]); + + ecs_entity_t entity = it->entities[i]; + AnimationType type = ANIM_IDLE; + if (len > 1.0f) + type = ANIM_WALK; + + ecs_set(it->world, entity, AnimationType, {type}); + } +} void entityUpdateAnimation(ecs_iter_t *it) { Game *game = ecs_singleton_get_mut(ECS, Game); Animation *anim = ecs_field(it, Animation, 1);