interact dist
This commit is contained in:
@ -26,7 +26,7 @@ void entityInit(entity_t *entity, const entitytype_t type) {
|
|||||||
assertTrue(type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
assertTrue(type < ENTITY_TYPE_COUNT, "Entity type out of bounds");
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
ENTITY_CALLBACKS[type].init,
|
ENTITY_CALLBACKS[type].init,
|
||||||
"Entity type has no init callback"
|
"Entity type has no i nit callback"
|
||||||
);
|
);
|
||||||
|
|
||||||
memoryZero(entity, sizeof(entity_t));
|
memoryZero(entity, sizeof(entity_t));
|
||||||
|
@ -82,5 +82,39 @@ void playerNPCUpdate(entity_t *entity) {
|
|||||||
} else {
|
} else {
|
||||||
entity->vx = 0;
|
entity->vx = 0;
|
||||||
entity->vy = 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ typedef struct {
|
|||||||
#define PLAYER_ENTITY_ID (UINT32_MAX-1)
|
#define PLAYER_ENTITY_ID (UINT32_MAX-1)
|
||||||
#define PLAYER_MOVE_SPEED FIXED248(1, 0)
|
#define PLAYER_MOVE_SPEED FIXED248(1, 0)
|
||||||
#define PLAYER_MOVE_SPEED_XY FIXED248(0, 80)
|
#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.
|
* Initializes the player and all player-related entities.
|
||||||
|
Reference in New Issue
Block a user