Add walk animation

This commit is contained in:
2023-12-29 08:02:19 +01:00
parent b667f18b8e
commit 0c9fae7781
4 changed files with 24 additions and 31 deletions

View File

@@ -205,7 +205,7 @@ bool init(void *userData) {
// Needs to be called after AI update, since it removes finished actions // Needs to be called after AI update, since it removes finished actions
ECS_SYSTEM(ECS, updateUnitActionsSystem, EcsOnUpdate, UnitAction); ECS_SYSTEM(ECS, updateUnitActionsSystem, EcsOnUpdate, UnitAction);
//ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Velocity, AnimationType); ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Animation, TextureRegion);
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);

View File

@@ -53,13 +53,6 @@ void entitySpatialRemove(ecs_iter_t *it);
*/ */
void entityPathRemove(ecs_iter_t *it); void entityPathRemove(ecs_iter_t *it);
/* Observer (for updating animation state)
* 1: Animation
* 2: AnimationType
*/
void entitySetAnimationState(ecs_iter_t *it);
/* /*
* 0: Game (singleton) for entity map * 0: Game (singleton) for entity map
* 1: Position * 1: Position
@@ -93,17 +86,10 @@ void entityMoveToTarget(ecs_iter_t *it);
*/ */
void entityFollowPath(ecs_iter_t *it); void entityFollowPath(ecs_iter_t *it);
/*
* 0: Game (for pathfinding)
* 1: Position
* 2: Rotation
* 3: HarvestTask
*/
void entityHarvestTaskSystem(ecs_iter_t *it);
/* /*
* 1: Velocity * 1: Animation
* 2: AnimationType * 2: TextureRegion
*/ */
void entityUpdateAnimationState(ecs_iter_t *it); void entityUpdateAnimationState(ecs_iter_t *it);
/* /*

View File

@@ -253,19 +253,26 @@ void entityHarvestTaskSystem(ecs_iter_t *it) {
*/ */
void entityUpdateAnimationState(ecs_iter_t *it) { void entityUpdateAnimationState(ecs_iter_t *it) {
Velocity *velocity = ecs_field(it, Velocity, 1); Animation *anim = ecs_field(it, Animation, 1);
//AnimationType *animType = ecs_field(it, AnimationType , 2); TextureRegion *text = ecs_field(it, TextureRegion, 2);
for (i32 i = 0; i < it->count; i++) { for (i32 i = 0; i < it->count; i++) {
f32 len = Vector2Length(velocity[i]);
/*
ecs_entity_t entity = it->entities[i]; ecs_entity_t entity = it->entities[i];
AnimationType type = ANIM_IDLE; AnimType type = ANIM_IDLE;
if (len > 1.0f) if (ecs_has(ECS, entity, Velocity)) {
Velocity vel = *ecs_get(ECS, entity, Velocity);
f32 len = Vector2Length(vel);
if (len > 1.0f) {
type = ANIM_WALK; type = ANIM_WALK;
text[i].flipX = vel.x < 0;
}
}
ecs_set(it->world, entity, AnimationType, {type}); if (type != anim[i].animType) {
*/ anim[i].animType = type;
anim[i].sequence = entityGetAnimationSequence(anim[i].entityType, type);
anim[i].curFrame = 0;
anim[i].elapsed = 0;
}
} }
} }
void entityUpdateAnimation(ecs_iter_t *it) { void entityUpdateAnimation(ecs_iter_t *it) {

View File

@@ -112,17 +112,17 @@ void inputUnitAction(Game *game, InputState *input) {
if (isInputBtnJustUp(input, actionBtn)) { if (isInputBtnJustUp(input, actionBtn)) {
// Note: We mustn't use ecs ecs_remove_all since this will also // Note: We mustn't use ecs ecs_remove_all since this will also
// remove ongoing paths that are not part of this query. // remove ongoing paths that are not part of this query.
iterateSelectedUnits(input->queries.selected, iterRemovePaths); ecs_defer_begin(ECS);
iterateSelectedUnits(query, iterRemovePaths);
ecs_defer_end(ECS);
const Position target = input->mouseWorld; const Position target = input->mouseWorld;
ecs_iter_t it = ecs_query_iter(ECS, query); ecs_iter_t it = ecs_query_iter(ECS, query);
ecs_defer_begin(ECS); ecs_defer_begin(ECS);
while (ecs_iter_next(&it)) { while (ecs_iter_next(&it)) {
const Position *pos = ecs_field(&it, Position, 1);
for (i32 i = 0; i < it.count; i++) { for (i32 i = 0; i < it.count; i++) {
const ecs_entity_t entity = it.entities[i]; const ecs_entity_t entity = it.entities[i];
entitySetPath(entity, target, game); entitySetPath(entity, target, game);
} }
} }