interact dist

This commit is contained in:
2025-06-20 13:43:43 -05:00
parent 44ebf3a66d
commit 56642774c4
3 changed files with 36 additions and 1 deletions

View File

@ -26,7 +26,7 @@ void entityInit(entity_t *entity, const entitytype_t type) {
assertTrue(type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
assertNotNull(
ENTITY_CALLBACKS[type].init,
"Entity type has no init callback"
"Entity type has no i nit callback"
);
memoryZero(entity, sizeof(entity_t));

View File

@ -82,5 +82,39 @@ void playerNPCUpdate(entity_t *entity) {
} else {
entity->vx = 0;
entity->vy = 0;
// Interact
if(inputPressed(INPUT_BIND_ACTION)) {
entity_t *other = ENTITIES;
do {
if(other == entity || other->type == ENTITY_TYPE_NULL) {
other++;
continue;
}
fixed248_t distanceX = fx248Subfx248(other->x, entity->x);
fixed248_t distanceY = fx248Subfx248(other->y, entity->y);
fixed248_t distance = fx248Sqrt(
fx248Addfx248(
fx248Mulfx248(distanceX, distanceX),
fx248Mulfx248(distanceY, distanceY)
)
);
if(other->id == 102) {
printf("Distance to entity %u: %f\n", other->id, fx248Tof32(distance));
}
if(distance > PLAYER_INTERACT_RANGE) {
other++;
continue;
}
printf("Interacting with entity %u\n", other->id);
other++;
} while(other != ENTITIES + ENTITY_COUNT_MAX);
}
}
}

View File

@ -18,6 +18,7 @@ typedef struct {
#define PLAYER_ENTITY_ID (UINT32_MAX-1)
#define PLAYER_MOVE_SPEED FIXED248(1, 0)
#define PLAYER_MOVE_SPEED_XY FIXED248(0, 80)
#define PLAYER_INTERACT_RANGE FIXED248((TILE_WIDTH_HEIGHT + (TILE_WIDTH_HEIGHT / 3)), 0)
/**
* Initializes the player and all player-related entities.