Ent movement

This commit is contained in:
2025-11-04 09:03:36 -06:00
parent 68c4834a62
commit 7d46b98310
4 changed files with 18 additions and 13 deletions

View File

@@ -43,8 +43,8 @@ void entityUpdate(entity_t *entity) {
} }
// Movement code. // Movement code.
if(entity->type == ENTITY_TYPE_PLAYER) { if(ENTITY_CALLBACKS[entity->type].movement != NULL) {
playerInput(entity); ENTITY_CALLBACKS[entity->type].movement(entity);
} }
} }
@@ -100,14 +100,11 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
entity_t * entityGetAt(const worldpos_t position) { entity_t * entityGetAt(const worldpos_t position) {
entity_t *ent = ENTITIES; entity_t *ent = ENTITIES;
do { do {
if( if(ent->type == ENTITY_TYPE_NULL) continue;
ent->type != ENTITY_TYPE_NULL && if(ent->position.x != position.x) continue;
ent->position.x == position.x && if(ent->position.y != position.y) continue;
ent->position.y == position.y && if(ent->position.z != position.z) continue;
ent->position.z == position.z return ent;
) {
return ent;
}
} while(++ent, ent < &ENTITIES[ENTITY_COUNT]); } while(++ent, ent < &ENTITIES[ENTITY_COUNT]);
return NULL; return NULL;

View File

@@ -30,6 +30,12 @@ typedef struct {
*/ */
void (*init)(entity_t *entity); void (*init)(entity_t *entity);
/**
* Movement callback for the entity type.
* @param entity Pointer to the entity to move.
*/
void (*movement)(entity_t *entity);
/** /**
* Interaction callback for the entity type. * Interaction callback for the entity type.
* @param player Pointer to the player entity. * @param player Pointer to the player entity.
@@ -43,11 +49,13 @@ static const entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
[ENTITY_TYPE_NULL] = { NULL }, [ENTITY_TYPE_NULL] = { NULL },
[ENTITY_TYPE_PLAYER] = { [ENTITY_TYPE_PLAYER] = {
.init = playerInit .init = playerInit,
.movement = playerInput
}, },
[ENTITY_TYPE_NPC] = { [ENTITY_TYPE_NPC] = {
.init = npcInit, .init = npcInit,
.movement = npcMovement,
.interact = npcInteract .interact = npcInteract
} }
}; };

View File

@@ -12,7 +12,7 @@ void npcInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL"); assertNotNull(entity, "Entity pointer cannot be NULL");
} }
void npcUpdate(entity_t *entity) { void npcMovement(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL"); assertNotNull(entity, "Entity pointer cannot be NULL");
} }

View File

@@ -26,7 +26,7 @@ void npcInit(entity_t *entity);
* *
* @param entity Pointer to the entity structure to update. * @param entity Pointer to the entity structure to update.
*/ */
void npcUpdate(entity_t *entity); void npcMovement(entity_t *entity);
/** /**
* Handles interaction with an NPC entity. * Handles interaction with an NPC entity.