Blocked path
This commit is contained in:
@@ -8,13 +8,11 @@
|
|||||||
#include "npc.h"
|
#include "npc.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
#include "rpg/overworld/worldpos.h"
|
#include "rpg/overworld/worldpos.h"
|
||||||
#include "time/time.h"
|
|
||||||
|
|
||||||
void npcPathInit(npc_t *npc) {
|
void npcPathInit(npc_t *npc) {
|
||||||
npcpath_t *path = &npc->moveData.path;
|
npcpath_t *path = &npc->moveData.path;
|
||||||
path->count = 0;
|
path->count = 0;
|
||||||
path->index = 0;
|
path->index = 0;
|
||||||
path->blockedTimer = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void npcPathMovement(entity_t *entity) {
|
void npcPathMovement(entity_t *entity) {
|
||||||
@@ -42,17 +40,5 @@ void npcPathMovement(entity_t *entity) {
|
|||||||
dir = pos.z < target->z ? ENTITY_DIR_NORTH : ENTITY_DIR_SOUTH;
|
dir = pos.z < target->z ? ENTITY_DIR_NORTH : ENTITY_DIR_SOUTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
worldpos_t prevPos = entity->position;
|
|
||||||
entityWalk(entity, dir);
|
entityWalk(entity, dir);
|
||||||
|
|
||||||
if(worldPosIsEqual(entity->position, prevPos)) {
|
|
||||||
// Blocked - wait before skipping so temporary blockers can move away.
|
|
||||||
path->blockedTimer += TIME.delta;
|
|
||||||
if(path->blockedTimer >= NPC_PATH_BLOCKED_TIMEOUT) {
|
|
||||||
path->index = (path->index + 1) % path->count;
|
|
||||||
path->blockedTimer = 0.0f;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
path->blockedTimer = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user