Fixed animation

This commit is contained in:
2025-11-09 18:50:02 -06:00
parent 943e775364
commit d054cf9e36
6 changed files with 13 additions and 23 deletions

View File

@@ -39,8 +39,11 @@ void entityUpdate(entity_t *entity) {
// What state is the entity in? // What state is the entity in?
if(entity->animation != ENTITY_ANIM_IDLE) { if(entity->animation != ENTITY_ANIM_IDLE) {
// Entity is mid animation, tick it (down). // Entity is mid animation, tick it (down).
entity->animFrame--; entity->animTime -= TIME.delta;
if(entity->animFrame == 0) entity->animation = ENTITY_ANIM_IDLE; if(entity->animTime <= 0) {
entity->animation = ENTITY_ANIM_IDLE;
entity->animTime = 0;
}
return; return;
} }
@@ -56,7 +59,7 @@ void entityUpdate(entity_t *entity) {
void entityTurn(entity_t *entity, const entitydir_t direction) { void entityTurn(entity_t *entity, const entitydir_t direction) {
entity->direction = direction; entity->direction = direction;
entity->animation = ENTITY_ANIM_TURN; 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) { 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->position.y = newY;
entity->animation = ENTITY_ANIM_WALK; 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) { entity_t * entityGetAt(const worldpos_t position) {

View File

@@ -25,7 +25,7 @@ typedef struct entity_s {
worldpos_t position; worldpos_t position;
entityanim_t animation; entityanim_t animation;
uint8_t animFrame; float_t animTime;
} entity_t; } entity_t;
extern entity_t ENTITIES[ENTITY_COUNT]; extern entity_t ENTITIES[ENTITY_COUNT];

View File

@@ -8,8 +8,8 @@
#pragma once #pragma once
#include "dusk.h" #include "dusk.h"
#define ENTITY_ANIM_TURN_DURATION 6 #define ENTITY_ANIM_TURN_DURATION 0.06f
#define ENTITY_ANIM_WALK_DURATION 10 #define ENTITY_ANIM_WALK_DURATION 0.1f
typedef enum { typedef enum {
ENTITY_ANIM_IDLE, ENTITY_ANIM_IDLE,

View File

@@ -58,9 +58,7 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
// Add animation offset(s) // Add animation offset(s)
switch(entity->animation) { switch(entity->animation) {
case ENTITY_ANIM_WALK: case ENTITY_ANIM_WALK:
float_t animPercentage = ( float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
(float_t)entity->animFrame / (float_t)ENTITY_ANIM_WALK_DURATION
);
// Get facing rel, we know we moved from the inverse direction. // Get facing rel, we know we moved from the inverse direction.
int8_t x, y; int8_t x, y;

View File

@@ -14,6 +14,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
TIME_SDL2=1 TIME_SDL2=1
TIME_FIXED=0
) )
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}

View File

@@ -8,22 +8,10 @@
#pragma once #pragma once
#include "dusk.h" #include "dusk.h"
#define TIME_STEP (1.0f / 60.0f) // 60 Ticks per second. #define TIME_STEP (1.0f / 144.0f) // 60 Ticks per second.
#ifndef TIME_FIXED #ifndef TIME_FIXED
#define TIME_FIXED 0 #define TIME_FIXED 0
#else
#ifndef TIME_PLATFORM_STEP
#error "TIME_PLATFORM_STEP must be defined when TIME_FIXED is enabled"
#endif
#if TIME_PLATFORM_STEP <= 0.0f
#error "TIME_PLATFORM_STEP must be greater than zero"
#endif
#if TIME_PLATFORM_STEP != TIME_STEP
#define TIME_FIXED 0
#endif
#endif #endif
typedef struct { typedef struct {