npc start

This commit is contained in:
2025-09-14 08:58:54 -05:00
parent 067b0d2e9f
commit 517b39649c
8 changed files with 65 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ ref_t testAssetRef;
errorret_t sceneOverworldInit(void) { errorret_t sceneOverworldInit(void) {
cameraInit(&SCENE_OVERWORLD.camera); cameraInit(&SCENE_OVERWORLD.camera);
glm_vec3_copy((vec3){ 0.0f, 1.0f, 0.0f }, SCENE_OVERWORLD.camera.lookat.up); 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_t *scene = &SCENE_MANAGER_SCENES[SCENE_TYPE_OVERWORLD];
scene->flags |= SCENE_FLAG_ACTIVE | SCENE_FLAG_VISIBLE; 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 (glm_rad(180) - SCENE_OVERWORLD.camera.perspective.fov) / 2.0f
) * (fbHeight/ 2.0f); ) * (fbHeight/ 2.0f);
glm_vec3_copy((vec3){ // glm_vec3_copy((vec3){
-100.0f, -100.0f, 0.0f // -100.0f, -100.0f, 0.0f
}, SCENE_OVERWORLD.camera.lookat.target); // }, SCENE_OVERWORLD.camera.lookat.target);
glm_vec3_copy((vec3){ glm_vec3_copy((vec3){
SCENE_OVERWORLD.camera.lookat.target[0], SCENE_OVERWORLD.camera.lookat.target[0],
SCENE_OVERWORLD.camera.lookat.target[1] + camOffset, SCENE_OVERWORLD.camera.lookat.target[1] + camOffset,

View File

@@ -7,5 +7,6 @@
target_sources(${DUSK_TARGET_NAME} target_sources(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
entity.c entity.c
npc.c
player.c player.c
) )

View File

@@ -12,7 +12,7 @@
entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = { entitycallback_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
{ NULL, NULL }, // ENTITY_TYPE_NULL { NULL, NULL }, // ENTITY_TYPE_NULL
{ playerInit, playerUpdate }, // ENTITY_TYPE_PLAYER { playerInit, playerUpdate }, // ENTITY_TYPE_PLAYER
{ NULL, NULL }, // ENTITY_TYPE_NPC { npcInit, npcUpdate}, // ENTITY_TYPE_NPC
}; };
void entityInit(entity_t *entity, const entitytype_t type) { void entityInit(entity_t *entity, const entitytype_t type) {

View File

@@ -8,11 +8,7 @@
#pragma once #pragma once
// #include "direction.h" // #include "direction.h"
#include "rpg/entity/player.h" #include "rpg/entity/player.h"
// #include "npc.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
typedef struct { typedef struct {
void (*init)(entity_t *entity); void (*init)(entity_t *entity);
@@ -35,6 +31,7 @@ typedef struct entity_s {
union { union {
player_t player; player_t player;
npc_t npc;
}; };
} entity_t; } entity_t;

17
src/rpg/entity/npc.c Normal file
View File

@@ -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");
}

29
src/rpg/entity/npc.h Normal file
View File

@@ -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);

View File

@@ -10,6 +10,8 @@
#include "time/time.h" #include "time/time.h"
#include "input/input.h" #include "input/input.h"
#include "display/scene/overworld/sceneoverworld.h"
void playerInit(entity_t *entity) { void playerInit(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL"); assertNotNull(entity, "Entity pointer cannot be NULL");
} }
@@ -18,7 +20,7 @@ void playerUpdate(entity_t *entity) {
assertNotNull(entity, "Entity pointer cannot be NULL"); assertNotNull(entity, "Entity pointer cannot be NULL");
// testing only // testing only
float_t move = TIME.delta * 128.0f; // tiles per second float_t move = TIME.delta * 64.0f; // tiles per second
vec2 dir = { vec2 dir = {
inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT), inputAxis(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT),
inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN) inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN)
@@ -26,4 +28,7 @@ void playerUpdate(entity_t *entity) {
glm_vec2_normalize(dir); glm_vec2_normalize(dir);
entity->x += move * dir[0]; entity->x += move * dir[0];
entity->y -= move * dir[1]; entity->y -= move * dir[1];
SCENE_OVERWORLD.camera.lookat.target[0] = entity->x;
SCENE_OVERWORLD.camera.lookat.target[1] = entity->y;
} }

View File

@@ -16,6 +16,11 @@ void rpgInit() {
entity_t *ent = mapEntityAdd(&testMap); entity_t *ent = mapEntityAdd(&testMap);
entityInit(ent, ENTITY_TYPE_PLAYER); 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() { void rpgUpdate() {