build: CMake and public headers
This commit is contained in:
parent
1455cf7ac9
commit
87d99f7007
6 changed files with 107 additions and 0 deletions
34
CMakeLists.txt
Normal file
34
CMakeLists.txt
Normal file
|
|
@ -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)
|
||||||
7
include/ok_game.h
Normal file
7
include/ok_game.h
Normal file
|
|
@ -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
|
||||||
6
include/ok_map.h
Normal file
6
include/ok_map.h
Normal file
|
|
@ -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
|
||||||
9
include/ok_render.h
Normal file
9
include/ok_render.h
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef OK_RENDER_H
|
||||||
|
#define OK_RENDER_H
|
||||||
|
#include "ok_types.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
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
|
||||||
46
include/ok_types.h
Normal file
46
include/ok_types.h
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef OK_TYPES_H
|
||||||
|
#define OK_TYPES_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#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
|
||||||
5
include/ok_unit.h
Normal file
5
include/ok_unit.h
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue