Add walking animation

This commit is contained in:
2023-12-05 11:32:34 +01:00
parent 0d137ffb25
commit 17a5cee02c
3 changed files with 23 additions and 1 deletions

View File

@@ -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);

View File

@@ -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:
*/

View File

@@ -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);