From f1db7de87c67baee05b84245e7dff30ed7c6ab38 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 26 Oct 2025 15:42:34 -0500 Subject: [PATCH] Initial commit. --- .gitignore | 33 ++++++++++++++ CMakeLists.txt | 19 ++++++++ README.md | 2 + src/CMakeLists.txt | 21 +++++++++ src/entity/CMakeLists.txt | 10 +++++ src/entity/direction.h | 21 +++++++++ src/entity/entity.c | 48 ++++++++++++++++++++ src/entity/entity.h | 52 +++++++++++++++++++++ src/entity/entitytype.h | 14 ++++++ src/entity/player.c | 21 +++++++++ src/entity/player.h | 18 ++++++++ src/game.c | 22 +++++++++ src/game.h | 37 +++++++++++++++ src/input.c | 16 +++++++ src/input.h | 66 +++++++++++++++++++++++++++ src/main.c | 37 +++++++++++++++ src/microrpg.h | 15 +++++++ src/scene/CMakeLists.txt | 9 ++++ src/scene/scene.c | 23 ++++++++++ src/scene/scene.h | 16 +++++++ src/term/CMakeLists.txt | 28 ++++++++++++ src/term/inputterm.c | 24 ++++++++++ src/term/term.c | 95 +++++++++++++++++++++++++++++++++++++++ src/term/term.h | 46 +++++++++++++++++++ src/world/CMakeLists.txt | 9 ++++ src/world/chunk.h | 17 +++++++ src/world/map.c | 14 ++++++ src/world/map.h | 35 +++++++++++++++ src/world/tile.h | 13 ++++++ 29 files changed, 781 insertions(+) create mode 100755 .gitignore create mode 100755 CMakeLists.txt create mode 100755 README.md create mode 100755 src/CMakeLists.txt create mode 100755 src/entity/CMakeLists.txt create mode 100755 src/entity/direction.h create mode 100755 src/entity/entity.c create mode 100755 src/entity/entity.h create mode 100755 src/entity/entitytype.h create mode 100755 src/entity/player.c create mode 100755 src/entity/player.h create mode 100755 src/game.c create mode 100755 src/game.h create mode 100755 src/input.c create mode 100755 src/input.h create mode 100755 src/main.c create mode 100755 src/microrpg.h create mode 100755 src/scene/CMakeLists.txt create mode 100755 src/scene/scene.c create mode 100755 src/scene/scene.h create mode 100755 src/term/CMakeLists.txt create mode 100755 src/term/inputterm.c create mode 100755 src/term/term.c create mode 100755 src/term/term.h create mode 100755 src/world/CMakeLists.txt create mode 100755 src/world/chunk.h create mode 100755 src/world/map.c create mode 100755 src/world/map.h create mode 100755 src/world/tile.h diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..3ea830e --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# C/C++ build artifacts +*.o +*.obj +*.so +*.dll +*.exe +*.out +*.a +*.lib +*.lo +*.dep + +# CMake files +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +Makefile +CMakeLists.txt.user +CMakeConfigureLog.yaml + +# Editor files +*.swp +*.swo +*~ +.vscode/ +.idea/ + +# OS files +.DS_Store +Thumbs.db + +# CMake build directories +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..4daa46f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +cmake_minimum_required(VERSION 3.13) +project(microrpg + VERSION 0.1.0 + DESCRIPTION "A tiny JRPG game written in C" + LANGUAGES C +) + +set(CMAKE_C_STANDARD 99) + +# Executable +add_executable(microrpg) + +# Add sources +add_subdirectory(src) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..3597ca3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Micro JRPG +Small JRPG game/engine that is designed to run on "just about" anything. \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..7c16a88 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Include directories +target_include_directories(microrpg PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + +# Sources +target_sources(microrpg PRIVATE + main.c + game.c + input.c +) + +# Subdirs +add_subdirectory(entity) +add_subdirectory(scene) +add_subdirectory(world) + +add_subdirectory(term) \ No newline at end of file diff --git a/src/entity/CMakeLists.txt b/src/entity/CMakeLists.txt new file mode 100755 index 0000000..b61983e --- /dev/null +++ b/src/entity/CMakeLists.txt @@ -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(microrpg PRIVATE + entity.c + player.c +) \ No newline at end of file diff --git a/src/entity/direction.h b/src/entity/direction.h new file mode 100755 index 0000000..e5585d6 --- /dev/null +++ b/src/entity/direction.h @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "microrpg.h" + +#define DIRECTION_UP 0 +#define DIRECTION_RIGHT 1 +#define DIRECTION_DOWN 2 +#define DIRECTION_LEFT 3 + +#define DIRECTION_NORTH DIRECTION_UP +#define DIRECTION_EAST DIRECTION_RIGHT +#define DIRECTION_SOUTH DIRECTION_DOWN +#define DIRECTION_WEST DIRECTION_LEFT + +typedef uint8_t direction_t; \ No newline at end of file diff --git a/src/entity/entity.c b/src/entity/entity.c new file mode 100755 index 0000000..3c69706 --- /dev/null +++ b/src/entity/entity.c @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "entity.h" + +void entityInit(entity_t *entity, const entitytype_t type) { + memset(entity, 0, sizeof(entity_t)); + + entity->type = type; +} + +void entityTick(entity_t *entity) { + if(entity->type == ENTITY_TYPE_NULL) return; + + // Let entities move (if they do) + if(entity->type == ENTITY_TYPE_PLAYER) { + playerTickInput(entity); + } +} + +void entityTurn(entity_t *entity, const direction_t direction) { + // TODO: animation/delay. + entity->direction = direction; +} + +void entityWalk(entity_t *entity, const direction_t direction) { + // TODO: Animation, delay, colission, result, etc. + entity->direction = direction; + + switch(direction) { + case DIRECTION_NORTH: + entity->position.y--; + break; + case DIRECTION_EAST: + entity->position.x++; + break; + case DIRECTION_SOUTH: + entity->position.y++; + break; + case DIRECTION_WEST: + entity->position.x--; + break; + } +} \ No newline at end of file diff --git a/src/entity/entity.h b/src/entity/entity.h new file mode 100755 index 0000000..fb46903 --- /dev/null +++ b/src/entity/entity.h @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "entity/direction.h" +#include "entity/entitytype.h" +#include "player.h" + +typedef struct entity_s { + struct { + // Relative to top-left of the map + uint8_t x, y; + } position; + + direction_t direction; + entitytype_t type; +} entity_t; + +/** + * Initialize an entity. + * + * @param entity Pointer to the entity to initialize. + * @param type The type of the entity. + */ +void entityInit(entity_t *entity, const entitytype_t type); + +/** + * Update an entity for one tick. + * + * @param entity Pointer to the entity to update. + */ +void entityTick(entity_t *entity); + +/** + * Turn an entity to face a new direction. + * + * @param entity Pointer to the entity to turn. + * @param direction The direction to face. + */ +void entityTurn(entity_t *entity, const direction_t direction); + +/** + * Make an entity walk in a direction. + * + * @param entity Pointer to the entity to make walk. + * @param direction The direction to walk in. + */ +void entityWalk(entity_t *entity, const direction_t direction); \ No newline at end of file diff --git a/src/entity/entitytype.h b/src/entity/entitytype.h new file mode 100755 index 0000000..2e7f11e --- /dev/null +++ b/src/entity/entitytype.h @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "microrpg.h" + +#define ENTITY_TYPE_NULL 0 +#define ENTITY_TYPE_PLAYER 1 + +typedef uint8_t entitytype_t; \ No newline at end of file diff --git a/src/entity/player.c b/src/entity/player.c new file mode 100755 index 0000000..338ca47 --- /dev/null +++ b/src/entity/player.c @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "entity.h" +#include "input.h" + +void playerTickInput(entity_t *entity) { + if(inputPressed(INPUT_ACTION_UP)) { + entityWalk(entity, DIRECTION_NORTH); + } else if(inputPressed(INPUT_ACTION_DOWN)) { + entityWalk(entity, DIRECTION_SOUTH); + } else if(inputPressed(INPUT_ACTION_LEFT)) { + entityWalk(entity, DIRECTION_WEST); + } else if(inputPressed(INPUT_ACTION_RIGHT)) { + entityWalk(entity, DIRECTION_EAST); + } +} \ No newline at end of file diff --git a/src/entity/player.h b/src/entity/player.h new file mode 100755 index 0000000..863cc64 --- /dev/null +++ b/src/entity/player.h @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "microrpg.h" + +typedef struct entity_s entity_t; + +/** + * Ticks player input logic. + * + * @param entity Pointer to the player entity. + */ +void playerTickInput(entity_t *entity); \ No newline at end of file diff --git a/src/game.c b/src/game.c new file mode 100755 index 0000000..8ba674a --- /dev/null +++ b/src/game.c @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "game.h" + +game_t GAME; + +void gameInit() { + memset(&GAME, 0, sizeof(GAME)); + + entityInit(&GAME.player, ENTITY_TYPE_PLAYER); + + GAME.scene = SCENE_OVERWORLD; +} + +void gameTick() { + sceneTick(); +} \ No newline at end of file diff --git a/src/game.h b/src/game.h new file mode 100755 index 0000000..149df76 --- /dev/null +++ b/src/game.h @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "entity/entity.h" +#include "world/map.h" +#include "scene/scene.h" + +#define GAME_SCENE_INITIAL 0 +#define GAME_SCENE_OVERWORLD 1 + +typedef struct game_s { + scene_t scene; + entity_t player; + + union { + struct { + map_t map; + } overworld; + }; +} game_t; + +extern game_t GAME; + +/** + * Initialize the game state. + */ +void gameInit(); + +/** + * Advance the game state by one tick. Should be called at 60Hz. + */ +void gameTick(); \ No newline at end of file diff --git a/src/input.c b/src/input.c new file mode 100755 index 0000000..164beb5 --- /dev/null +++ b/src/input.c @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "input.h" + +bool_t inputPressed(const uint8_t action) { + return inputDown(action) && inputWasUp(action); +} + +bool_t inputReleased(const uint8_t action) { + return inputUp(action) && inputWasDown(action); +} \ No newline at end of file diff --git a/src/input.h b/src/input.h new file mode 100755 index 0000000..c702ceb --- /dev/null +++ b/src/input.h @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "microrpg.h" + +#define INPUT_ACTION_UP (1 << 0) +#define INPUT_ACTION_DOWN (1 << 1) +#define INPUT_ACTION_LEFT (1 << 2) +#define INPUT_ACTION_RIGHT (1 << 3) +#define INPUT_ACTION_A (1 << 4) +#define INPUT_ACTION_B (1 << 5) +#define INPUT_ACTION_START (1 << 6) +#define INPUT_ACTION_SELECT (1 << 7) + +/** + * Check if an input action is currently held down. + * + * @param action The action to check. + * @return true if the action is held down, false otherwise. + */ +bool_t inputDown(const uint8_t action); + +/** + * Check if an input action is not currently held down. + * + * @param action The action to check. + * @return true if the action is not held down, false otherwise. + */ +bool_t inputUp(const uint8_t action); + +/** + * Check if an input action was held down in the previous tick. + * + * @param action The action to check. + * @return true if the action was down last tick, false otherwise. + */ +bool_t inputWasDown(const uint8_t action); + +/** + * Check if an input action was not held down in the previous tick. + * + * @param action The action to check. + * @return true if the action was up last tick, false otherwise. + */ +bool_t inputWasUp(const uint8_t action); + +/** + * Check if an input action was just pressed this tick. + * + * @param action The action to check. + * @return true if the action was just pressed, false otherwise. + */ +bool_t inputPressed(const uint8_t action); + +/** + * Check if an input action was just released this tick. + * + * @param action The action to check. + * @return true if the action was just released, false otherwise. + */ +bool_t inputReleased(const uint8_t action); \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100755 index 0000000..92d8626 --- /dev/null +++ b/src/main.c @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "game.h" +#if RPG_TERM == 1 +#include "term/term.h" +#endif + +int main(int argc, char** argv) { + gameInit(); + + #if RPG_TERM == 1 + termInit(); + #endif + + while(1) { + #if RPG_TERM == 1 + termUpdate(); + #endif + + gameTick(); + + #if RPG_TERM == 1 + termDraw(); + #endif + } + + #if RPG_TERM == 1 + termDispose(); + #endif + + return 0; +} \ No newline at end of file diff --git a/src/microrpg.h b/src/microrpg.h new file mode 100755 index 0000000..62f5024 --- /dev/null +++ b/src/microrpg.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include +#include +#include +#include + +typedef bool bool_t; \ No newline at end of file diff --git a/src/scene/CMakeLists.txt b/src/scene/CMakeLists.txt new file mode 100755 index 0000000..2a280ba --- /dev/null +++ b/src/scene/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(microrpg PRIVATE + scene.c +) \ No newline at end of file diff --git a/src/scene/scene.c b/src/scene/scene.c new file mode 100755 index 0000000..41b6ec2 --- /dev/null +++ b/src/scene/scene.c @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "scene.h" +#include "game.h" + +void sceneTick() { + switch(GAME.scene) { + case SCENE_INITIAL: { + break; + } + + case SCENE_OVERWORLD: { + mapTick(&GAME.overworld.map); + entityTick(&GAME.player); + break; + } + } +} \ No newline at end of file diff --git a/src/scene/scene.h b/src/scene/scene.h new file mode 100755 index 0000000..88ceaa6 --- /dev/null +++ b/src/scene/scene.h @@ -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 "microrpg.h" + +#define SCENE_INITIAL 0 +#define SCENE_OVERWORLD 1 + +typedef uint8_t scene_t; + +void sceneTick(); \ No newline at end of file diff --git a/src/term/CMakeLists.txt b/src/term/CMakeLists.txt new file mode 100755 index 0000000..8ea11da --- /dev/null +++ b/src/term/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Libraries +find_package(Curses REQUIRED) + +target_link_libraries(microrpg PRIVATE + ${CURSES_LIBRARIES} +) +target_include_directories(microrpg PRIVATE + ${CURSES_INCLUDE_DIR} +) +target_link_libraries(microrpg PRIVATE + ${CURSES_LIBRARIES} +) + +# Sources +target_sources(microrpg PRIVATE + term.c + inputterm.c +) + +# Compiler flags +target_compile_definitions(microrpg PRIVATE + RPG_TERM=1 +) \ No newline at end of file diff --git a/src/term/inputterm.c b/src/term/inputterm.c new file mode 100755 index 0000000..62b5223 --- /dev/null +++ b/src/term/inputterm.c @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "term.h" + +bool_t inputDown(const uint8_t action) { + return (TERM.inputCurrent & action) != 0; +} + +bool_t inputUp(const uint8_t action) { + return (TERM.inputCurrent & action) == 0; +} + +bool_t inputWasDown(const uint8_t action) { + return (TERM.inputPrevious & action) != 0; +} + +bool_t inputWasUp(const uint8_t action) { + return (TERM.inputPrevious & action) == 0; +} \ No newline at end of file diff --git a/src/term/term.c b/src/term/term.c new file mode 100755 index 0000000..6923c6c --- /dev/null +++ b/src/term/term.c @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "term.h" +#include "input.h" + +typedef struct terminputmap_s { + int key; + uint8_t action; +} terminputmap_t; + +static const terminputmap_t TERM_INPUT_MAP[] = { + { KEY_UP, INPUT_ACTION_UP }, + { 'w', INPUT_ACTION_UP }, + { KEY_DOWN, INPUT_ACTION_DOWN }, + { 's', INPUT_ACTION_DOWN }, + { KEY_LEFT, INPUT_ACTION_LEFT }, + { 'a', INPUT_ACTION_LEFT }, + { KEY_RIGHT, INPUT_ACTION_RIGHT }, + { 'd', INPUT_ACTION_RIGHT }, + { 'j', INPUT_ACTION_A }, + { 'e', INPUT_ACTION_A }, + { 'k', INPUT_ACTION_B }, + { 'q', INPUT_ACTION_B }, + { KEY_ENTER, INPUT_ACTION_START }, + { ' ', INPUT_ACTION_SELECT }, + { -1, 0 } +}; + +term_t TERM; + +void termInit() { + memset(&TERM, 0, sizeof(TERM)); + + initscr(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + nodelay(stdscr, TRUE); + curs_set(0); + start_color(); + use_default_colors(); + init_pair(1, COLOR_GREEN, -1); +} + +void termUpdate() { + TERM.inputPrevious = TERM.inputCurrent; + TERM.inputCurrent = 0; + + int ch = getch(); + if(ch == ERR) { + TERM.lastch = ERR; + return; + } + + if(ch == TERM.lastch) { + return; + } + TERM.lastch = ch; + + const terminputmap_t *map = TERM_INPUT_MAP; + while(map->key != -1) { + if(map->key == ch) { + TERM.inputCurrent |= map->action; + break; + } + map++; + } +} + +void termDraw() { + clear(); + attron(COLOR_PAIR(1)); + + termDrawEntity(&GAME.player); + + attroff(COLOR_PAIR(1)); + refresh(); + + // 16ms delay (60FPS) + napms(16); +} + +void termDrawEntity(const entity_t *ent) { + // Placeholder: Draw entity at its position + mvaddch(ent->position.y, ent->position.x, '@'); +} + +void termDispose() { + endwin(); +} \ No newline at end of file diff --git a/src/term/term.h b/src/term/term.h new file mode 100755 index 0000000..9b29696 --- /dev/null +++ b/src/term/term.h @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "microrpg.h" +#include "game.h" +#include + +typedef struct term_s { + uint8_t inputCurrent; + uint8_t inputPrevious; + int lastch; +} term_t; + +extern term_t TERM; + +/** + * Initialize the terminal subsystem. + */ +void termInit(); + +/** + * Update the terminal prior to game update. + */ +void termUpdate(); + +/** + * Draw the terminal game. + */ +void termDraw(); + +/** + * Draw an entity to the terminal. + * + * @param ent The entity to draw. + */ +void termDrawEntity(const entity_t *ent); + +/** + * Dispose of the terminal subsystem. + */ +void termDispose(); \ No newline at end of file diff --git a/src/world/CMakeLists.txt b/src/world/CMakeLists.txt new file mode 100755 index 0000000..82f3284 --- /dev/null +++ b/src/world/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(microrpg PRIVATE + map.c +) \ No newline at end of file diff --git a/src/world/chunk.h b/src/world/chunk.h new file mode 100755 index 0000000..49239d7 --- /dev/null +++ b/src/world/chunk.h @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "world/tile.h" + +#define CHUNK_WIDTH_IN_TILES 16 +#define CHUNK_HEIGHT_IN_TILES 16 +#define CHUNK_TILE_COUNT (CHUNK_WIDTH_IN_TILES * CHUNK_HEIGHT_IN_TILES) + +typedef struct chunk_s { + tile_t tiles[CHUNK_TILE_COUNT]; +} chunk_t; \ No newline at end of file diff --git a/src/world/map.c b/src/world/map.c new file mode 100755 index 0000000..e07c4ec --- /dev/null +++ b/src/world/map.c @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "map.h" + +void mapTick(map_t *map) { + for(int i = 0; i < MAP_ENTITY_COUNT; i++) { + entityTick(&map->entities[i]); + } +} \ No newline at end of file diff --git a/src/world/map.h b/src/world/map.h new file mode 100755 index 0000000..b7b4eaf --- /dev/null +++ b/src/world/map.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "world/chunk.h" +#include "entity/entity.h" + +#define MAP_ENTITY_COUNT 8 +#define MAP_WIDTH_IN_CHUNKS 3 +#define MAP_HEIGHT_IN_CHUNKS 3 +#define MAP_CHUNK_COUNT (MAP_WIDTH_IN_CHUNKS * MAP_HEIGHT_IN_CHUNKS) + +typedef struct map_s { + // Loaded chunks. + chunk_t chunks[MAP_CHUNK_COUNT]; + chunk_t *order[MAP_CHUNK_COUNT]; + int8_t firstChunk; + + // Map entities + entity_t entities[MAP_ENTITY_COUNT]; + + // Size of map (in chunks) + uint8_t width, height; +} map_t; + +/** + * Update the map for one tick. + * + * @param map Pointer to the map to update. + */ +void mapTick(map_t *map); \ No newline at end of file diff --git a/src/world/tile.h b/src/world/tile.h new file mode 100755 index 0000000..4a518a6 --- /dev/null +++ b/src/world/tile.h @@ -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 "microrpg.h" + +#define TILE_NULL 0x00 + +typedef uint8_t tile_t; \ No newline at end of file