Add walking animation
This commit is contained in:
@@ -151,6 +151,7 @@ bool init(void *userData) {
|
|||||||
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Rotation, Velocity, AngularVelocity, SteeringOutput);
|
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Rotation, Velocity, AngularVelocity, SteeringOutput);
|
||||||
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Position, Rotation, Velocity, AngularVelocity, SteeringOutput, Path);
|
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, entityUpdateAnimation, EcsOnUpdate, Animation, TextureRegion);
|
||||||
|
|
||||||
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ void entityPathRemoved(ecs_iter_t *it);
|
|||||||
|
|
||||||
/* Observer (for updating animation state)
|
/* Observer (for updating animation state)
|
||||||
* 1: Animation
|
* 1: Animation
|
||||||
* 2: EntityState
|
* 2: AnimationType
|
||||||
*/
|
*/
|
||||||
void entitySetAnimationState(ecs_iter_t *it);
|
void entitySetAnimationState(ecs_iter_t *it);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0: Game (singleton) for entity map
|
* 0: Game (singleton) for entity map
|
||||||
* 1: Position
|
* 1: Position
|
||||||
@@ -59,6 +60,11 @@ void entityUpdateKinematic(ecs_iter_t *it);
|
|||||||
*/
|
*/
|
||||||
void entityFollowPath(ecs_iter_t *it);
|
void entityFollowPath(ecs_iter_t *it);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1: Velocity
|
||||||
|
* 2: AnimationType
|
||||||
|
*/
|
||||||
|
void entityUpdateAnimationState(ecs_iter_t *it);
|
||||||
/*
|
/*
|
||||||
* 0:
|
* 0:
|
||||||
* 1: Animation
|
* 1: Animation
|
||||||
@@ -66,6 +72,7 @@ void entityFollowPath(ecs_iter_t *it);
|
|||||||
*/
|
*/
|
||||||
void entityUpdateAnimation(ecs_iter_t *it);
|
void entityUpdateAnimation(ecs_iter_t *it);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0:
|
* 0:
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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) {
|
void entityUpdateAnimation(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
Animation *anim = ecs_field(it, Animation, 1);
|
Animation *anim = ecs_field(it, Animation, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user