Input test.
This commit is contained in:
@ -11,4 +11,5 @@ target_sources(${DUSK_TARGET_NAME}
|
||||
# Subdirs
|
||||
add_subdirectory(entity)
|
||||
add_subdirectory(item)
|
||||
add_subdirectory(quest)
|
||||
add_subdirectory(quest)
|
||||
add_subdirectory(world)
|
@ -12,12 +12,11 @@
|
||||
entity_t ENTITIES[ENTITY_COUNT];
|
||||
|
||||
entitycallbacks_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
|
||||
[ENTITY_TYPE_NULL] = {
|
||||
.init = NULL
|
||||
},
|
||||
[ENTITY_TYPE_NULL] = { 0 },
|
||||
|
||||
[ENTITY_TYPE_PLAYER] = {
|
||||
.init = playerInit
|
||||
.init = playerInit,
|
||||
.update = playerUpdate
|
||||
},
|
||||
};
|
||||
|
||||
@ -31,4 +30,23 @@ void entityInit(entity_t *entity, const entitytype_t type) {
|
||||
memoryZero(entity, sizeof(entity_t));
|
||||
entity->type = type;
|
||||
ENTITY_CALLBACKS[type].init(entity);
|
||||
}
|
||||
|
||||
void entityUpdate(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity cannot be NULL");
|
||||
assertNotNull(
|
||||
ENTITY_CALLBACKS[entity->type].update,
|
||||
"Entity type has no update"
|
||||
);
|
||||
|
||||
ENTITY_CALLBACKS[entity->type].update(entity);
|
||||
}
|
||||
|
||||
entity_t * entityGetAt(const uint8_t x, const uint8_t y) {
|
||||
entity_t *e = ENTITIES;
|
||||
do {
|
||||
if(e->type && e->x == x && e->y == y) return e;
|
||||
e++;
|
||||
} while(e < (ENTITIES + ENTITY_COUNT));
|
||||
return NULL;
|
||||
}
|
@ -43,6 +43,7 @@ extern entity_t ENTITIES[ENTITY_COUNT];
|
||||
|
||||
typedef struct {
|
||||
void (*init)(entity_t *entity);
|
||||
void (*update)(entity_t *entity);
|
||||
} entitycallbacks_t;
|
||||
extern entitycallbacks_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT];
|
||||
|
||||
@ -52,4 +53,20 @@ extern entitycallbacks_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT];
|
||||
* @param entity Pointer to the entity to initialize.
|
||||
* @param type The type of the entity to initialize.
|
||||
*/
|
||||
void entityInit(entity_t *entity, const entitytype_t type);
|
||||
void entityInit(entity_t *entity, const entitytype_t type);
|
||||
|
||||
/**
|
||||
* Updates the entity's state based on its type.
|
||||
*
|
||||
* @param entity Pointer to the entity to update.
|
||||
*/
|
||||
void entityUpdate(entity_t *entity);
|
||||
|
||||
/**
|
||||
* Resets the entity at a given position.
|
||||
*
|
||||
* @param x The x-coordinate of the entity.
|
||||
* @param y The y-coordinate of the entity.
|
||||
* @return Pointer to the entity at the specified position, or NULL.
|
||||
*/
|
||||
entity_t * entityGetAt(const uint8_t x, const uint8_t y);
|
@ -11,4 +11,9 @@
|
||||
void playerInit(entity_t *player) {
|
||||
assertNotNull(player, "Player entity is NULL");
|
||||
assertTrue(player->type == ENTITY_TYPE_PLAYER, "Entity is not a player");
|
||||
}
|
||||
|
||||
void playerUpdate(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity is NULL");
|
||||
assertTrue(entity->type == ENTITY_TYPE_PLAYER, "Entity is not a player");
|
||||
}
|
@ -19,4 +19,11 @@ typedef struct {
|
||||
*
|
||||
* @param ent Pointer to the player entity to initialize.
|
||||
*/
|
||||
void playerInit(entity_t *ent);
|
||||
void playerInit(entity_t *ent);
|
||||
|
||||
/**
|
||||
* Updates a player entity.
|
||||
*
|
||||
* @param ent Entity to update.
|
||||
*/
|
||||
void playerUpdate(entity_t *ent);
|
10
src/rpg/world/CMakeLists.txt
Normal file
10
src/rpg/world/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
map.c
|
||||
)
|
0
src/rpg/world/map.c
Normal file
0
src/rpg/world/map.c
Normal file
16
src/rpg/world/map.h
Normal file
16
src/rpg/world/map.h
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
} map_t;
|
||||
|
||||
extern map_t MAP;
|
Reference in New Issue
Block a user