Add walk animation
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -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];
|
||||||
|
AnimType type = ANIM_IDLE;
|
||||||
|
if (ecs_has(ECS, entity, Velocity)) {
|
||||||
|
Velocity vel = *ecs_get(ECS, entity, Velocity);
|
||||||
|
f32 len = Vector2Length(vel);
|
||||||
|
if (len > 1.0f) {
|
||||||
|
type = ANIM_WALK;
|
||||||
|
text[i].flipX = vel.x < 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
if (type != anim[i].animType) {
|
||||||
ecs_entity_t entity = it->entities[i];
|
anim[i].animType = type;
|
||||||
AnimationType type = ANIM_IDLE;
|
anim[i].sequence = entityGetAnimationSequence(anim[i].entityType, type);
|
||||||
if (len > 1.0f)
|
anim[i].curFrame = 0;
|
||||||
type = ANIM_WALK;
|
anim[i].elapsed = 0;
|
||||||
|
}
|
||||||
ecs_set(it->world, entity, AnimationType, {type});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void entityUpdateAnimation(ecs_iter_t *it) {
|
void entityUpdateAnimation(ecs_iter_t *it) {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user