Render test
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
# 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)
|
||||
add_subdirectory(world)
|
@@ -1,11 +0,0 @@
|
||||
# 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
|
||||
)
|
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* 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] = { 0 },
|
||||
|
||||
[ENTITY_TYPE_PLAYER] = {
|
||||
.init = playerInit,
|
||||
.update = playerUpdate
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void entityUpdate(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity cannot be NULL");
|
||||
assertNotNull(
|
||||
ENTITY_CALLBACKS[entity->type].update,
|
||||
"Entity type has no update"
|
||||
);
|
||||
|
||||
// Handle subpixel movement
|
||||
if(entity->subX < 0) {
|
||||
entity->subX++;
|
||||
} else if(entity->subY < 0) {
|
||||
entity->subY++;
|
||||
} else if(entity->subX > 0) {
|
||||
entity->subX--;
|
||||
} else if(entity->subY > 0) {
|
||||
entity->subY--;
|
||||
}
|
||||
|
||||
// Entity-Type handling
|
||||
ENTITY_CALLBACKS[entity->type].update(entity);
|
||||
}
|
||||
|
||||
void entityTurn(entity_t *entity, const entitydir_t dir) {
|
||||
assertNotNull(entity, "Entity cannot be NULL");
|
||||
assertFalse(entityIsWalking(entity), "Entity is currently walking");
|
||||
entity->dir = dir;
|
||||
}
|
||||
|
||||
void entityWalk(entity_t *entity) {
|
||||
assertNotNull(entity, "Entity cannot be NULL");
|
||||
assertFalse(entityIsWalking(entity), "Entity is already walking");
|
||||
|
||||
switch(entity->dir) {
|
||||
case ENTITY_DIR_UP:
|
||||
entity->y--;
|
||||
entity->subY = ENTITY_MOVE_SUBPIXEL;
|
||||
break;
|
||||
case ENTITY_DIR_DOWN:
|
||||
entity->y++;
|
||||
entity->subY = -ENTITY_MOVE_SUBPIXEL;
|
||||
break;
|
||||
case ENTITY_DIR_LEFT:
|
||||
entity->x--;
|
||||
entity->subX = ENTITY_MOVE_SUBPIXEL;
|
||||
break;
|
||||
case ENTITY_DIR_RIGHT:
|
||||
entity->x++;
|
||||
entity->subX = -ENTITY_MOVE_SUBPIXEL;
|
||||
break;
|
||||
default:
|
||||
assertUnreachable("Invalid entity direction");
|
||||
}
|
||||
}
|
||||
|
||||
bool_t entityIsWalking(const entity_t *entity) {
|
||||
assertNotNull(entity, "Entity cannot be NULL");
|
||||
return (entity->subX != 0 || entity->subY != 0);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "player.h"
|
||||
|
||||
#define ENTITY_MOVE_SUBPIXEL 4
|
||||
|
||||
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;
|
||||
uint8_t subX, subY;
|
||||
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);
|
||||
void (*update)(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);
|
||||
|
||||
/**
|
||||
* Updates the entity's state based on its type.
|
||||
*
|
||||
* @param entity Pointer to the entity to update.
|
||||
*/
|
||||
void entityUpdate(entity_t *entity);
|
||||
|
||||
/**
|
||||
* Turns the entity to face a specific direction.
|
||||
*
|
||||
* @param entity Pointer to the entity to turn.
|
||||
* @param dir The direction to turn the entity towards.
|
||||
*/
|
||||
void entityTurn(entity_t *entity, const entitydir_t dir);
|
||||
|
||||
/**
|
||||
* Makes the entity walk in the current direction.
|
||||
*
|
||||
* @param entity Pointer to the entity to make walk.
|
||||
*/
|
||||
void entityWalk(entity_t *entity);
|
||||
|
||||
/**
|
||||
* Checks if the entity is currently mid-walking.
|
||||
*
|
||||
* @param entity Pointer to the entity to check.
|
||||
* @return true if the entity is walking, false otherwise.
|
||||
*/
|
||||
bool_t entityIsWalking(const 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);
|
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* 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"
|
||||
#include "input.h"
|
||||
|
||||
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");
|
||||
|
||||
if(!entityIsWalking(entity)) {
|
||||
entitydir_t dir = 0xFF;
|
||||
if(inputIsDown(INPUT_UP)) {
|
||||
dir = ENTITY_DIR_UP;
|
||||
} else if(inputIsDown(INPUT_DOWN)) {
|
||||
dir = ENTITY_DIR_DOWN;
|
||||
} else if(inputIsDown(INPUT_LEFT)) {
|
||||
dir = ENTITY_DIR_LEFT;
|
||||
} else if(inputIsDown(INPUT_RIGHT)) {
|
||||
dir = ENTITY_DIR_RIGHT;
|
||||
}
|
||||
|
||||
if(dir != 0xFF) {
|
||||
if(dir != entity->dir) {
|
||||
entityTurn(entity, dir);
|
||||
} else {
|
||||
entityWalk(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Updates a player entity.
|
||||
*
|
||||
* @param ent Entity to update.
|
||||
*/
|
||||
void playerUpdate(entity_t *ent);
|
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 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;
|
@@ -1,11 +0,0 @@
|
||||
# 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
|
||||
inventory.c
|
||||
)
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert/assert.h"
|
||||
#include "inventory.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
void inventoryInit(inventory_t *inventory) {
|
||||
assertNotNull(inventory, "Inventory pointer cannot be NULL");
|
||||
|
||||
memoryZero(inventory, sizeof(inventory_t));
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "itemstack.h"
|
||||
|
||||
#define INVENTORY_ITEM_COUNT 32
|
||||
|
||||
typedef struct {
|
||||
itemstack_t items[INVENTORY_ITEM_COUNT];
|
||||
uint8_t itemCount;
|
||||
} inventory_t;
|
||||
|
||||
/**
|
||||
* Initializes the inventory.
|
||||
*
|
||||
* @param inventory Pointer to the inventory to initialize.
|
||||
*/
|
||||
void inventoryInit(inventory_t *inventory);
|
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "itemtype.h"
|
||||
|
||||
typedef struct {
|
||||
itemtype_t type;
|
||||
uint8_t count;
|
||||
} itemstack_t;
|
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert/assert.h"
|
||||
#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 },
|
||||
};
|
||||
|
||||
static inline bool_t itemTypeIsStackable(const itemtype_t type) {
|
||||
assertTrue(type < ITEM_TYPE_COUNT, "Invalid item type");
|
||||
return ITEM_INFO[type].stackable;
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* 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];
|
||||
|
||||
/**
|
||||
* Returns true if the item type is stackable.
|
||||
*
|
||||
* @param type The item type to check.
|
||||
* @return true if the item type is stackable, false otherwise.
|
||||
*/
|
||||
static inline bool_t itemTypeIsStackable(const itemtype_t type);
|
@@ -1,10 +0,0 @@
|
||||
# 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
|
||||
)
|
@@ -1,8 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "quest.h"
|
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 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;
|
@@ -1,10 +0,0 @@
|
||||
# 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
|
||||
)
|
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* 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