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,
|
||||
|
||||
@@ -58,9 +58,7 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
|
||||
// Add animation offset(s)
|
||||
switch(entity->animation) {
|
||||
case ENTITY_ANIM_WALK:
|
||||
float_t animPercentage = (
|
||||
(float_t)entity->animFrame / (float_t)ENTITY_ANIM_WALK_DURATION
|
||||
);
|
||||
float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
|
||||
|
||||
// Get facing rel, we know we moved from the inverse direction.
|
||||
int8_t x, y;
|
||||
|
||||
@@ -14,6 +14,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
TIME_SDL2=1
|
||||
TIME_FIXED=0
|
||||
)
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
|
||||
@@ -8,22 +8,10 @@
|
||||
#pragma once
|
||||
#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
|
||||
#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
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user