Fixed animation
This commit is contained in:
@@ -39,8 +39,11 @@ void entityUpdate(entity_t *entity) {
|
||||
// What state is the entity in?
|
||||
if(entity->animation != ENTITY_ANIM_IDLE) {
|
||||
// Entity is mid animation, tick it (down).
|
||||
entity->animFrame--;
|
||||
if(entity->animFrame == 0) entity->animation = ENTITY_ANIM_IDLE;
|
||||
entity->animTime -= TIME.delta;
|
||||
if(entity->animTime <= 0) {
|
||||
entity->animation = ENTITY_ANIM_IDLE;
|
||||
entity->animTime = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,7 +59,7 @@ void entityUpdate(entity_t *entity) {
|
||||
void entityTurn(entity_t *entity, const entitydir_t direction) {
|
||||
entity->direction = direction;
|
||||
entity->animation = ENTITY_ANIM_TURN;
|
||||
entity->animFrame = ENTITY_ANIM_TURN_DURATION;
|
||||
entity->animTime = ENTITY_ANIM_TURN_DURATION;
|
||||
}
|
||||
|
||||
void entityWalk(entity_t *entity, const entitydir_t direction) {
|
||||
@@ -99,7 +102,7 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
|
||||
entity->position.y = newY;
|
||||
|
||||
entity->animation = ENTITY_ANIM_WALK;
|
||||
entity->animFrame = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
|
||||
entity->animTime = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
|
||||
}
|
||||
|
||||
entity_t * entityGetAt(const worldpos_t position) {
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef struct entity_s {
|
||||
worldpos_t position;
|
||||
|
||||
entityanim_t animation;
|
||||
uint8_t animFrame;
|
||||
float_t animTime;
|
||||
} entity_t;
|
||||
|
||||
extern entity_t ENTITIES[ENTITY_COUNT];
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
#define ENTITY_ANIM_TURN_DURATION 6
|
||||
#define ENTITY_ANIM_WALK_DURATION 10
|
||||
#define ENTITY_ANIM_TURN_DURATION 0.06f
|
||||
#define ENTITY_ANIM_WALK_DURATION 0.1f
|
||||
|
||||
typedef enum {
|
||||
ENTITY_ANIM_IDLE,
|
||||
|
||||
Reference in New Issue
Block a user