From 517b39649cbbfa363d6243eb33ea21da5ff62072 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 14 Sep 2025 08:58:54 -0500 Subject: [PATCH] npc start --- src/display/scene/overworld/sceneoverworld.c | 7 +++-- src/rpg/entity/CMakeLists.txt | 1 + src/rpg/entity/entity.c | 2 +- src/rpg/entity/entity.h | 7 ++--- src/rpg/entity/npc.c | 17 ++++++++++++ src/rpg/entity/npc.h | 29 ++++++++++++++++++++ src/rpg/entity/player.c | 7 ++++- src/rpg/rpg.c | 5 ++++ 8 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/rpg/entity/npc.c create mode 100644 src/rpg/entity/npc.h diff --git a/src/display/scene/overworld/sceneoverworld.c b/src/display/scene/overworld/sceneoverworld.c index aa670f0..732235a 100644 --- a/src/display/scene/overworld/sceneoverworld.c +++ b/src/display/scene/overworld/sceneoverworld.c @@ -23,6 +23,7 @@ ref_t testAssetRef; errorret_t sceneOverworldInit(void) { cameraInit(&SCENE_OVERWORLD.camera); glm_vec3_copy((vec3){ 0.0f, 1.0f, 0.0f }, SCENE_OVERWORLD.camera.lookat.up); + SCENE_OVERWORLD.camera.perspective.fov = 45; scene_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_OVERWORLD]; scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE; @@ -46,9 +47,9 @@ void sceneOverworldRender(void) { (glm_rad(180) - SCENE_OVERWORLD.camera.perspective.fov) / 2.0f ) * (fbHeight/ 2.0f); - glm_vec3_copy((vec3){ - -100.0f, -100.0f, 0.0f - }, SCENE_OVERWORLD.camera.lookat.target); + // glm_vec3_copy((vec3){ + // -100.0f, -100.0f, 0.0f + // }, SCENE_OVERWORLD.camera.lookat.target); glm_vec3_copy((vec3){ SCENE_OVERWORLD.camera.lookat.target[0], SCENE_OVERWORLD.camera.lookat.target[1] + camOffset, diff --git a/src/rpg/entity/CMakeLists.txt b/src/rpg/entity/CMakeLists.txt index f559893..fd5a1e3 100644 --- a/src/rpg/entity/CMakeLists.txt +++ b/src/rpg/entity/CMakeLists.txt @@ -7,5 +7,6 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE entity.c + npc.c player.c ) \ No newline at end of file diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.c index 5ce21c5..ab02b7b 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.c @@ -12,7 +12,7 @@ entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = { { NULL, NULL }, // ENTITY_TYPE_NULL { playerInit, playerUpdate }, // ENTITY_TYPE_PLAYER - { NULL, NULL }, // ENTITY_TYPE_NPC + { npcInit, npcUpdate}, // ENTITY_TYPE_NPC }; void entityInit(entity_t *entity, const entitytype_t type) { diff --git a/src/rpg/entity/entity.h b/src/rpg/entity/entity.h index adbd317..2e7c6c8 100644 --- a/src/rpg/entity/entity.h +++ b/src/rpg/entity/entity.h @@ -8,11 +8,7 @@ #pragma once // #include "direction.h" #include "rpg/entity/player.h" -// #include "npc.h" - -// #define ENTITY_TURN_DURATION 0.075f // Duration for turning in seconds -// #define ENTITY_MOVE_DURATION 0.1f // Duration for moving 1 tile, in seconds. -// #define ENTITY_PLAYER_INDEX 0 +#include "npc.h" typedef struct { void (*init)(entity_t *entity); @@ -35,6 +31,7 @@ typedef struct entity_s { union { player_t player; + npc_t npc; }; } entity_t; diff --git a/src/rpg/entity/npc.c b/src/rpg/entity/npc.c new file mode 100644 index 0000000..79d21d6 --- /dev/null +++ b/src/rpg/entity/npc.c @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "entity.h" +#include "assert/assert.h" + +void npcInit(entity_t *entity) { + assertNotNull(entity, "Entity pointer cannot be NULL"); +} + +void npcUpdate(entity_t *entity) { + assertNotNull(entity, "Entity pointer cannot be NULL"); +} \ No newline at end of file diff --git a/src/rpg/entity/npc.h b/src/rpg/entity/npc.h new file mode 100644 index 0000000..b22754f --- /dev/null +++ b/src/rpg/entity/npc.h @@ -0,0 +1,29 @@ +/** + * 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 entity_s entity_t; + +typedef struct { + void *nothing; +} npc_t; + +/** + * Initializes an NPC entity. + * + * @param entity Pointer to the entity structure to initialize. + */ +void npcInit(entity_t *entity); + +/** + * Updates an NPC entity. + * + * @param entity Pointer to the entity structure to update. + */ +void npcUpdate(entity_t *entity); \ No newline at end of file diff --git a/src/rpg/entity/player.c b/src/rpg/entity/player.c index b829f66..66b0829 100644 --- a/src/rpg/entity/player.c +++ b/src/rpg/entity/player.c @@ -10,6 +10,8 @@ #include "time/time.h" #include "input/input.h" +#include "display/scene/overworld/sceneoverworld.h" + void playerInit(entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); } @@ -18,7 +20,7 @@ void playerUpdate(entity_t *entity) { assertNotNull(entity, "Entity pointer cannot be NULL"); // testing only - float_t move = TIME.delta * 128.0f; // tiles per second + float_t move = TIME.delta * 64.0f; // tiles per second vec2 dir = { inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT), inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN) @@ -26,4 +28,7 @@ void playerUpdate(entity_t *entity) { glm_vec2_normalize(dir); entity->x += move * dir[0]; entity->y -= move * dir[1]; + + SCENE_OVERWORLD.camera.lookat.target[0] = entity->x; + SCENE_OVERWORLD.camera.lookat.target[1] = entity->y; } \ No newline at end of file diff --git a/src/rpg/rpg.c b/src/rpg/rpg.c index 890afb5..d03d824 100644 --- a/src/rpg/rpg.c +++ b/src/rpg/rpg.c @@ -16,6 +16,11 @@ void rpgInit() { entity_t *ent = mapEntityAdd(&testMap); entityInit(ent, ENTITY_TYPE_PLAYER); + + entity_t *npc = mapEntityAdd(&testMap); + entityInit(npc, ENTITY_TYPE_NPC); + npc->x = 32.0f; + npc->y = 32.0f; } void rpgUpdate() {