From 87d99f700734c7c5804a12a4446f4676f50d5b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A2ni=20Marques?= Date: Sat, 11 Jul 2026 23:18:44 +0200 Subject: [PATCH] build: CMake and public headers --- CMakeLists.txt | 34 +++++++++++++++++++++++++++++++++ include/ok_game.h | 7 +++++++ include/ok_map.h | 6 ++++++ include/ok_render.h | 9 +++++++++ include/ok_types.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ include/ok_unit.h | 5 +++++ 6 files changed, 107 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 include/ok_game.h create mode 100644 include/ok_map.h create mode 100644 include/ok_render.h create mode 100644 include/ok_types.h create mode 100644 include/ok_unit.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..39a9473 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.16) +project(openkknd C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + +file(READ "${CMAKE_SOURCE_DIR}/VERSION" OPENKKND_VERSION) +string(STRIP "${OPENKKND_VERSION}" OPENKKND_VERSION) + +add_executable(openkknd + src/main.c + src/game.c + src/map.c + src/unit.c + src/render.c +) + +target_include_directories(openkknd PRIVATE include) +target_compile_definitions(openkknd PRIVATE + OPENKKND_VERSION="${OPENKKND_VERSION}" +) + +find_package(SDL2 REQUIRED) +if(TARGET SDL2::SDL2) + target_link_libraries(openkknd PRIVATE SDL2::SDL2) +elseif(TARGET SDL2::SDL2-static) + target_link_libraries(openkknd PRIVATE SDL2::SDL2-static) +else() + target_include_directories(openkknd PRIVATE ${SDL2_INCLUDE_DIRS}) + target_link_libraries(openkknd PRIVATE ${SDL2_LIBRARIES}) +endif() + +install(TARGETS openkknd RUNTIME DESTINATION bin) diff --git a/include/ok_game.h b/include/ok_game.h new file mode 100644 index 0000000..b3aeb2d --- /dev/null +++ b/include/ok_game.h @@ -0,0 +1,7 @@ +#ifndef OK_GAME_H +#define OK_GAME_H +#include "ok_types.h" +void ok_game_init(OkGame *g); +void ok_game_update(OkGame *g, float dt); +void ok_game_spawn(OkGame *g, OkFaction f, OkUnitKind k, int x, int y); +#endif diff --git a/include/ok_map.h b/include/ok_map.h new file mode 100644 index 0000000..6ff6c80 --- /dev/null +++ b/include/ok_map.h @@ -0,0 +1,6 @@ +#ifndef OK_MAP_H +#define OK_MAP_H +#include "ok_types.h" +void ok_map_generate(OkMap *m); +bool ok_map_walkable(const OkMap *m, int x, int y); +#endif diff --git a/include/ok_render.h b/include/ok_render.h new file mode 100644 index 0000000..410577a --- /dev/null +++ b/include/ok_render.h @@ -0,0 +1,9 @@ +#ifndef OK_RENDER_H +#define OK_RENDER_H +#include "ok_types.h" +#include +bool ok_render_init(int w, int h); +void ok_render_draw(const OkGame *g); +void ok_render_shutdown(void); +SDL_Window *ok_render_window(void); +#endif diff --git a/include/ok_types.h b/include/ok_types.h new file mode 100644 index 0000000..b9160d8 --- /dev/null +++ b/include/ok_types.h @@ -0,0 +1,46 @@ +#ifndef OK_TYPES_H +#define OK_TYPES_H + +#include +#include + +#define OK_MAP_W 64 +#define OK_MAP_H 48 +#define OK_MAX_UNITS 256 + +typedef enum { + OK_FACTION_SURVIVORS = 0, + OK_FACTION_SCAVENGERS = 1 +} OkFaction; + +typedef enum { + OK_UNIT_INFANTRY = 0, + OK_UNIT_VEHICLE = 1 +} OkUnitKind; + +typedef struct { + int x, y; + OkFaction faction; + OkUnitKind kind; + int hp; + int hp_max; + int target; /* unit index or -1 */ + bool alive; +} OkUnit; + +typedef struct { + uint8_t tile[OK_MAP_H][OK_MAP_W]; /* 0 empty, 1 blocked, 2 resource */ +} OkMap; + +typedef struct { + OkMap map; + OkUnit units[OK_MAX_UNITS]; + int unit_count; + int selected; + bool running; + bool survivors_win; + bool scavengers_win; + uint32_t tick; +} OkGame; + +#endif diff --git a/include/ok_unit.h b/include/ok_unit.h new file mode 100644 index 0000000..0a5a98f --- /dev/null +++ b/include/ok_unit.h @@ -0,0 +1,5 @@ +#ifndef OK_UNIT_H +#define OK_UNIT_H +#include "ok_types.h" +void ok_units_update(OkGame *g, float dt); +#endif