diff --git a/src/dusk/entity/entity.c b/src/dusk/entity/entity.c index 85594eb..18c8703 100644 --- a/src/dusk/entity/entity.c +++ b/src/dusk/entity/entity.c @@ -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)); diff --git a/src/dusk/entity/player.c b/src/dusk/entity/player.c index b39e073..0375b8e 100644 --- a/src/dusk/entity/player.c +++ b/src/dusk/entity/player.c @@ -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); + } } } \ No newline at end of file diff --git a/src/dusk/entity/player.h b/src/dusk/entity/player.h index 1709342..d4f0f73 100644 --- a/src/dusk/entity/player.h +++ b/src/dusk/entity/player.h @@ -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.