diff --git a/build.zig b/build.zig index 76a85b1..4d6f6b2 100644 --- a/build.zig +++ b/build.zig @@ -4,55 +4,8 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const c_flags = [_][]const u8{ - "-std=c99", - "-Wall", - "-Wextra", - "-O2", - }; - - // RNG library - const rng_lib = b.addLibrary(.{ - .name = "rng", - .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, - .link_libc = true, - }), - }); - rng_lib.addCSourceFiles(.{ - .files = &[_][]const u8{"libs/rng/rng.c"}, - .flags = &c_flags, - }); - rng_lib.addIncludePath(b.path("libs/rng")); - - // Map library - const map_lib = b.addLibrary(.{ - .name = "map", - .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, - .link_libc = true, - }), - }); - map_lib.addCSourceFiles(.{ - .files = &[_][]const u8{ - "libs/map/map.c", - "libs/map/utils.c", - }, - .flags = &c_flags, - }); - // map.h includes common.h and settings.h which live in src/ - map_lib.addIncludePath(b.path("src")); - // map.c includes rng/rng.h via libs/ root - map_lib.addIncludePath(b.path("libs")); - // utils.h is co-located with map.c - map_lib.addIncludePath(b.path("libs/map")); - - // Zig combat library. This must be compiled as an object and linked - // directly to bypassing the archive step, or it yields a corrupt - // archive that forces the user to clear the cache each time. - const combat_obj = b.addObject(.{ + // Zig combat library + const combat_lib = b.addLibrary(.{ .name = "combat", .root_module = b.createModule(.{ .root_source_file = b.path("libs/combat/combat.zig"), @@ -61,20 +14,29 @@ pub fn build(b: *std.Build) void { .link_libc = true, }), }); - // common.h and settings.h live in src/; rng.h exposed bare from libs/rng - combat_obj.addIncludePath(b.path("src")); - combat_obj.addIncludePath(b.path("libs/rng")); + combat_lib.addIncludePath(b.path("src")); + combat_lib.linkSystemLibrary("raylib"); - // C sources remaining in src/ + // C sources (everything except combat, which is now Zig) const c_sources = [_][]const u8{ "src/audio.c", "src/enemy.c", "src/items.c", "src/main.c", - "src/movement.c", + "src/map.c", "src/player.c", + "src/movement.c", "src/render.c", + "src/rng.c", "src/settings.c", + "src/utils.c", + }; + + const c_flags = [_][]const u8{ + "-std=c99", + "-Wall", + "-Wextra", + "-O2", }; // Main executable @@ -92,13 +54,8 @@ pub fn build(b: *std.Build) void { .flags = &c_flags, }); - // src/ for own headers; libs/ so "rng/rng.h" and "map/map.h" resolve exe.addIncludePath(b.path("src")); - exe.addIncludePath(b.path("libs")); - - exe.linkLibrary(rng_lib); - exe.linkLibrary(map_lib); - exe.addObject(combat_obj); + exe.linkLibrary(combat_lib); exe.linkSystemLibrary("raylib"); exe.linkSystemLibrary("m"); exe.linkSystemLibrary("pthread"); diff --git a/src/audio.c b/src/audio.c index 93114c2..36db553 100644 --- a/src/audio.c +++ b/src/audio.c @@ -1,4 +1,6 @@ #include "audio.h" +#include "raylib.h" +#include "common.h" #include #include diff --git a/src/audio.h b/src/audio.h index ff71fa6..56ecd92 100644 --- a/src/audio.h +++ b/src/audio.h @@ -1,6 +1,6 @@ #ifndef AUDIO_H #define AUDIO_H -#include "game_state.h" +#include "common.h" // Initialize audio system void audio_init(void); diff --git a/src/common.h b/src/common.h index fe87edf..9fda4d3 100644 --- a/src/common.h +++ b/src/common.h @@ -2,7 +2,7 @@ #define COMMON_H #include "settings.h" -#include +#include typedef struct { int x, y; @@ -114,5 +114,68 @@ typedef struct { int effect_count; } Enemy; +// Floating damage text +typedef enum { LABEL_NONE = 0, LABEL_DODGE, LABEL_BLOCK, LABEL_CRIT, LABEL_SLAIN, LABEL_PROC } FloatingLabel; + +typedef struct { + int x, y; + int value; + int lifetime; // frames remaining + int is_critical; + FloatingLabel label; // label type instead of string + StatusEffectType effect_type; // used to pick color for proc labels +} FloatingText; + +// AudioAssets +typedef struct { + Sound attack1, attack2, attack3; + Sound pickup; + Sound staircase; + Sound dodge1, dodge2, dodge3; + Sound crit; +} AudioAssets; + +// GameState - encapsulates all game state for testability and save/load +typedef struct { + Player player; + Map map; + Dungeon dungeon; + Enemy enemies[MAX_ENEMIES]; + int enemy_count; + Item items[MAX_ITEMS]; + int item_count; + int game_over; + int game_won; + const char *last_message; + int message_timer; + int turn_count; + int awaiting_descend; // 0 = normal, 1 = waiting for Y/N + int show_inventory; // 0 = hidden, 1 = show overlay + int inv_selected; // currently selected inventory index + // action log + char action_log[5][128]; + int log_count; + int log_head; + // visual effects + FloatingText floating_texts[8]; + int floating_count; + int screen_shake; // frames of screen shake remaining + int shake_x; + int shake_y; + AudioAssets sounds; + // Statistics + int total_kills; + int items_collected; + int damage_dealt; + int damage_taken; + int crits_landed; + int times_hit; + int potions_used; + int floors_reached; + int final_score; + // Seed for this run + unsigned int run_seed; +} GameState; + #endif // COMMON_H diff --git a/src/enemy.c b/src/enemy.c index 6832386..57eff34 100644 --- a/src/enemy.c +++ b/src/enemy.c @@ -1,9 +1,9 @@ #include "enemy.h" #include "combat.h" #include "common.h" -#include "map/map.h" +#include "map.h" #include "movement.h" -#include "rng/rng.h" +#include "rng.h" #include "settings.h" #include diff --git a/src/game_state.h b/src/game_state.h deleted file mode 100644 index e0d7711..0000000 --- a/src/game_state.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef GAME_STATE_H -#define GAME_STATE_H - -#include "common.h" -#include - -// Floating damage text -typedef enum { LABEL_NONE = 0, LABEL_DODGE, LABEL_BLOCK, LABEL_CRIT, LABEL_SLAIN, LABEL_PROC } FloatingLabel; - -typedef struct { - int x, y; - int value; - int lifetime; // frames remaining - int is_critical; - FloatingLabel label; // label type instead of string - StatusEffectType effect_type; // used to pick color for proc labels -} FloatingText; - -// AudioAssets -typedef struct { - Sound attack1, attack2, attack3; - Sound pickup; - Sound staircase; - Sound dodge1, dodge2, dodge3; - Sound crit; -} AudioAssets; - -// GameState - encapsulates all game state for testability and save/load -typedef struct { - Player player; - Map map; - Dungeon dungeon; - Enemy enemies[MAX_ENEMIES]; - int enemy_count; - Item items[MAX_ITEMS]; - int item_count; - int game_over; - int game_won; - const char *last_message; - int message_timer; - int turn_count; - int awaiting_descend; // 0 = normal, 1 = waiting for Y/N - int show_inventory; // 0 = hidden, 1 = show overlay - int inv_selected; // currently selected inventory index - // action log - char action_log[5][128]; - int log_count; - int log_head; - // visual effects - FloatingText floating_texts[8]; - int floating_count; - int screen_shake; // frames of screen shake remaining - int shake_x; - int shake_y; - AudioAssets sounds; - // Statistics - int total_kills; - int items_collected; - int damage_dealt; - int damage_taken; - int crits_landed; - int times_hit; - int potions_used; - int floors_reached; - int final_score; - // Seed for this run - unsigned int run_seed; -} GameState; - -#endif // GAME_STATE_H diff --git a/src/items.c b/src/items.c index 27f343d..e5bf212 100644 --- a/src/items.c +++ b/src/items.c @@ -1,6 +1,6 @@ #include "common.h" -#include "map/map.h" -#include "rng/rng.h" +#include "map.h" +#include "rng.h" #include "settings.h" #include diff --git a/src/main.c b/src/main.c index 404eaa9..6aba2a4 100644 --- a/src/main.c +++ b/src/main.c @@ -1,13 +1,14 @@ #include "audio.h" #include "combat.h" -#include "game_state.h" +#include "common.h" #include "enemy.h" #include "items.h" -#include "map/map.h" +#include "map.h" #include "movement.h" #include "player.h" +#include "raylib.h" #include "render.h" -#include "rng/rng.h" +#include "rng.h" #include "settings.h" #include #include diff --git a/libs/map/map.c b/src/map.c similarity index 99% rename from libs/map/map.c rename to src/map.c index 911d487..011c06b 100644 --- a/libs/map/map.c +++ b/src/map.c @@ -1,5 +1,5 @@ #include "map.h" -#include "rng/rng.h" +#include "rng.h" #include "settings.h" #include "utils.h" #include diff --git a/libs/map/map.h b/src/map.h similarity index 100% rename from libs/map/map.h rename to src/map.h diff --git a/src/movement.c b/src/movement.c index 89e74e1..0f7fd8f 100644 --- a/src/movement.c +++ b/src/movement.c @@ -1,6 +1,6 @@ #include "movement.h" #include "enemy.h" -#include "map/map.h" +#include "map.h" #include // Check if position is occupied by player diff --git a/src/render.c b/src/render.c index 5a4c434..1b4ac8f 100644 --- a/src/render.c +++ b/src/render.c @@ -1,5 +1,7 @@ #include "render.h" +#include "common.h" #include "items.h" +#include "raylib.h" #include "settings.h" #include #include diff --git a/src/render.h b/src/render.h index 3dd376a..7fafbf5 100644 --- a/src/render.h +++ b/src/render.h @@ -2,7 +2,7 @@ #ifndef RENDER_H #define RENDER_H -#include "game_state.h" +#include "common.h" // HUD colors #define HUD_BG (Color){25, 20, 15, 255} diff --git a/libs/rng/rng.c b/src/rng.c similarity index 100% rename from libs/rng/rng.c rename to src/rng.c diff --git a/libs/rng/rng.h b/src/rng.h similarity index 100% rename from libs/rng/rng.h rename to src/rng.h diff --git a/libs/map/utils.c b/src/utils.c similarity index 100% rename from libs/map/utils.c rename to src/utils.c diff --git a/libs/map/utils.h b/src/utils.h similarity index 100% rename from libs/map/utils.h rename to src/utils.h