This commit is contained in:
2025-06-08 14:38:22 -05:00
parent 8411c2981b
commit 0b6b33721b
69 changed files with 210 additions and 3384 deletions

14
src/rpg/CMakeLists.txt Normal file
View File

@ -0,0 +1,14 @@
# 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
)
# Subdirs
add_subdirectory(entity)
add_subdirectory(item)
add_subdirectory(quest)

View File

@ -0,0 +1,11 @@
# 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
entity.c
player.c
)

34
src/rpg/entity/entity.c Normal file
View File

@ -0,0 +1,34 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "assert/assert.h"
#include "util/memory.h"
#include "entity.h"
entity_t ENTITIES[ENTITY_COUNT];
entitycallbacks_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT] = {
[ENTITY_TYPE_NULL] = {
.init = NULL
},
[ENTITY_TYPE_PLAYER] = {
.init = playerInit
},
};
void entityInit(entity_t *entity, const entitytype_t type) {
assertNotNull(entity, "Entity is NULL");
assertTrue(type < ENTITY_TYPE_COUNT, "Invalid entity type");
assertNotNull(ENTITY_CALLBACKS[type].init, "Entity type has no init");
memoryZero(entity, sizeof(entity_t));
entity->type = type;
ENTITY_CALLBACKS[type].init(entity);
}

54
src/rpg/entity/entity.h Normal file
View File

@ -0,0 +1,54 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "player.h"
typedef enum {
ENTITY_DIR_UP = 0,
ENTITY_DIR_DOWN = 1,
ENTITY_DIR_LEFT = 2,
ENTITY_DIR_RIGHT = 3,
ENTITY_DIR_NORTH = ENTITY_DIR_UP,
ENTITY_DIR_SOUTH = ENTITY_DIR_DOWN,
ENTITY_DIR_WEST = ENTITY_DIR_LEFT,
ENTITY_DIR_EAST = ENTITY_DIR_RIGHT
} entitydir_t;
typedef enum {
ENTITY_TYPE_NULL = 0,
ENTITY_TYPE_PLAYER = 1,
} entitytype_t;
#define ENTITY_TYPE_COUNT (ENTITY_TYPE_PLAYER + 1)
typedef struct _entity_t {
entitytype_t type;
uint8_t x, y;
entitydir_t dir;
// Per type data
union {
player_t player;
};
} entity_t;
#define ENTITY_COUNT 16
extern entity_t ENTITIES[ENTITY_COUNT];
typedef struct {
void (*init)(entity_t *entity);
} entitycallbacks_t;
extern entitycallbacks_t ENTITY_CALLBACKS[ENTITY_TYPE_COUNT];
/**
* Initializes an entity with the given type.
*
* @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);

14
src/rpg/entity/player.c Normal file
View File

@ -0,0 +1,14 @@
/**
* 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 playerInit(entity_t *player) {
assertNotNull(player, "Player entity is NULL");
assertTrue(player->type == ENTITY_TYPE_PLAYER, "Entity is not a player");
}

22
src/rpg/entity/player.h Normal file
View File

@ -0,0 +1,22 @@
/**
* 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_t entity_t;
typedef struct {
uint8_t nothing;
} player_t;
/**
* Initializes a player entity.
*
* @param ent Pointer to the player entity to initialize.
*/
void playerInit(entity_t *ent);

13
src/rpg/event/event.h Normal file
View File

@ -0,0 +1,13 @@
/**
* 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 {
} event_t;

View 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
itemtype.c
)

9
src/rpg/item/item.h Normal file
View File

@ -0,0 +1,9 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "itemtype.h"

22
src/rpg/item/itemtype.c Normal file
View File

@ -0,0 +1,22 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "itemtype.h"
iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
[ITEM_TYPE_NULL] = { 0 },
// Consumables
[ITEM_TYPE_POTION] = { .stackable = true },
// Ingredients
[ITEM_TYPE_ONION] = { .stackable = true },
[ITEM_TYPE_SWEET_POTATO] = { .stackable = true },
// Cooked Items
[ITEM_TYPE_BAKED_SWEET_POTATO] = { .stackable = true },
};

30
src/rpg/item/itemtype.h Normal file
View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef enum {
ITEM_TYPE_NULL,
// Consumables
ITEM_TYPE_POTION,
// Ingredients
ITEM_TYPE_ONION,
ITEM_TYPE_SWEET_POTATO,
// Cooked Items
ITEM_TYPE_BAKED_SWEET_POTATO,
} itemtype_t;
#define ITEM_TYPE_COUNT (ITEM_TYPE_BAKED_SWEET_POTATO + 1)
typedef struct {
bool_t stackable;
} iteminfo_t;
extern iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT];

View 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
quest.c
)

8
src/rpg/quest/quest.c Normal file
View File

@ -0,0 +1,8 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "quest.h"

13
src/rpg/quest/quest.h Normal file
View File

@ -0,0 +1,13 @@
/**
* 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 {
} quest_t;