Interact
This commit is contained in:
@@ -56,7 +56,7 @@ void entityUpdate(entity_t *entity) {
|
|||||||
|
|
||||||
// Movement code.
|
// Movement code.
|
||||||
if(entity->type == ENTITY_TYPE_PLAYER) {
|
if(entity->type == ENTITY_TYPE_PLAYER) {
|
||||||
playerMovement(entity);
|
playerInput(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,3 +109,19 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
|
|||||||
entity->animation = ENTITY_ANIM_WALK;
|
entity->animation = ENTITY_ANIM_WALK;
|
||||||
entity->animFrame = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
|
entity->animFrame = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entity_t * entityGetAt(const worldpos_t position) {
|
||||||
|
entity_t *ent = ENTITIES;
|
||||||
|
do {
|
||||||
|
if(
|
||||||
|
ent->type != ENTITY_TYPE_NULL &&
|
||||||
|
ent->position.x == position.x &&
|
||||||
|
ent->position.y == position.y &&
|
||||||
|
ent->position.z == position.z
|
||||||
|
) {
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
} while(++ent, ent < &ENTITIES[ENTITY_COUNT]);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
@@ -72,3 +72,12 @@ void entityTurn(entity_t *entity, const entitydir_t direction);
|
|||||||
* @param direction The direction to walk in.
|
* @param direction The direction to walk in.
|
||||||
*/
|
*/
|
||||||
void entityWalk(entity_t *entity, const entitydir_t direction);
|
void entityWalk(entity_t *entity, const entitydir_t direction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entity at a specific world position.
|
||||||
|
*
|
||||||
|
* @param map Pointer to the map to check.
|
||||||
|
* @param pos The world position to check.
|
||||||
|
* @return Pointer to the entity at the position, or NULL if none.
|
||||||
|
*/
|
||||||
|
entity_t *entityGetAt(const worldpos_t pos);
|
||||||
@@ -8,7 +8,11 @@
|
|||||||
#include "entitydir.h"
|
#include "entitydir.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
|
|
||||||
void entityDirGetRelative(const entitydir_t from, int8_t *outX, int8_t *outY) {
|
void entityDirGetRelative(
|
||||||
|
const entitydir_t from,
|
||||||
|
worldunits_t *outX,
|
||||||
|
worldunits_t *outY
|
||||||
|
) {
|
||||||
assertValidEntityDir(from, "Invalid direction provided");
|
assertValidEntityDir(from, "Invalid direction provided");
|
||||||
assertNotNull(outX, "Output X pointer cannot be NULL");
|
assertNotNull(outX, "Output X pointer cannot be NULL");
|
||||||
assertNotNull(outY, "Output Y pointer cannot be NULL");
|
assertNotNull(outY, "Output Y pointer cannot be NULL");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "rpg/world/worldpos.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENTITY_DIR_SOUTH = 0,
|
ENTITY_DIR_SOUTH = 0,
|
||||||
@@ -42,4 +42,6 @@ typedef enum {
|
|||||||
* @param relX Pointer to store the relative x offset.
|
* @param relX Pointer to store the relative x offset.
|
||||||
* @param relY Pointer to store the relative y offset.
|
* @param relY Pointer to store the relative y offset.
|
||||||
*/
|
*/
|
||||||
void entityDirGetRelative(const entitydir_t dir, int8_t *relX, int8_t *relY);
|
void entityDirGetRelative(
|
||||||
|
const entitydir_t dir, worldunits_t *relX, worldunits_t *relY
|
||||||
|
);
|
||||||
@@ -30,7 +30,7 @@ void playerInit(entity_t *entity) {
|
|||||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
void playerMovement(entity_t *entity) {
|
void playerInput(entity_t *entity) {
|
||||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
assertNotNull(entity, "Entity pointer cannot be NULL");
|
||||||
|
|
||||||
// Turn
|
// Turn
|
||||||
@@ -48,11 +48,23 @@ void playerMovement(entity_t *entity) {
|
|||||||
if(entity->direction != dirMap->direction) continue;
|
if(entity->direction != dirMap->direction) continue;
|
||||||
return entityWalk(entity, dirMap->direction);
|
return entityWalk(entity, dirMap->direction);
|
||||||
} while((++dirMap)->action != 0xFF);
|
} while((++dirMap)->action != 0xFF);
|
||||||
|
|
||||||
|
// Interaction
|
||||||
|
if(inputPressed(INPUT_ACTION_ACCEPT)) {
|
||||||
|
worldunit_t x, y, z;
|
||||||
|
{
|
||||||
|
worldunits_t relX, relY;
|
||||||
|
entityDirGetRelative(entity->direction, &relX, &relY);
|
||||||
|
x = entity->position.x + relX;
|
||||||
|
y = entity->position.y + relY;
|
||||||
|
z = entity->position.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playerInteraction(entity_t *entity) {
|
entity_t *interact = entityGetAt((worldpos_t){ x, y, z });
|
||||||
assertNotNull(entity, "Entity pointer cannot be NULL");
|
if(interact != NULL) {
|
||||||
|
printf("INTERACT\n");
|
||||||
if(!inputPressed(INPUT_ACTION_ACCEPT)) return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,11 +26,4 @@ void playerInit(entity_t *entity);
|
|||||||
*
|
*
|
||||||
* @param entity Pointer to the player entity structure.
|
* @param entity Pointer to the player entity structure.
|
||||||
*/
|
*/
|
||||||
void playerMovement(entity_t *entity);
|
void playerInput(entity_t *entity);
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles interaction logic for the player entity.
|
|
||||||
*
|
|
||||||
* @param entity Pointer to the player entity structure.
|
|
||||||
*/
|
|
||||||
void playerInteraction(entity_t *entity);
|
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dusk.h"
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef uint8_t worldunit_t;
|
||||||
|
typedef int8_t worldunits_t;
|
||||||
|
|
||||||
typedef struct worldpos_s {
|
typedef struct worldpos_s {
|
||||||
uint32_t x, y, z;
|
worldunit_t x, y, z;
|
||||||
} worldpos_t;
|
} worldpos_t;
|
||||||
Reference in New Issue
Block a user