Compare commits
1 commit
3ab42c3f65
...
ef0a20c1f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
ef0a20c1f8 |
8 changed files with 84 additions and 81 deletions
19
build.zig
19
build.zig
|
|
@ -48,11 +48,14 @@ pub fn build(b: *std.Build) void {
|
||||||
map_lib.addIncludePath(b.path("libs"));
|
map_lib.addIncludePath(b.path("libs"));
|
||||||
// utils.h is co-located with map.c
|
// utils.h is co-located with map.c
|
||||||
map_lib.addIncludePath(b.path("libs/map"));
|
map_lib.addIncludePath(b.path("libs/map"));
|
||||||
|
map_lib.linkLibrary(rng_lib);
|
||||||
|
// map.c doesn't call raylib, but common.h (via map.h) includes raylib.h;
|
||||||
|
// add the include path without linking the library into the static archive
|
||||||
|
const raylib_include = std.mem.trim(u8, b.run(&.{ "pkg-config", "--variable=includedir", "raylib" }), "\n ");
|
||||||
|
map_lib.addSystemIncludePath(.{ .cwd_relative = raylib_include });
|
||||||
|
|
||||||
// Zig combat library. This must be compiled as an object and linked
|
// Zig combat library
|
||||||
// directly to bypassing the archive step, or it yields a corrupt
|
const combat_lib = b.addLibrary(.{
|
||||||
// archive that forces the user to clear the cache each time.
|
|
||||||
const combat_obj = b.addObject(.{
|
|
||||||
.name = "combat",
|
.name = "combat",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = b.path("libs/combat/combat.zig"),
|
.root_source_file = b.path("libs/combat/combat.zig"),
|
||||||
|
|
@ -62,8 +65,10 @@ pub fn build(b: *std.Build) void {
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
// common.h and settings.h live in src/; rng.h exposed bare from libs/rng
|
// common.h and settings.h live in src/; rng.h exposed bare from libs/rng
|
||||||
combat_obj.addIncludePath(b.path("src"));
|
combat_lib.addIncludePath(b.path("src"));
|
||||||
combat_obj.addIncludePath(b.path("libs/rng"));
|
combat_lib.addIncludePath(b.path("libs/rng"));
|
||||||
|
combat_lib.linkLibrary(rng_lib);
|
||||||
|
combat_lib.linkSystemLibrary("raylib");
|
||||||
|
|
||||||
// C sources remaining in src/
|
// C sources remaining in src/
|
||||||
const c_sources = [_][]const u8{
|
const c_sources = [_][]const u8{
|
||||||
|
|
@ -98,7 +103,7 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
exe.linkLibrary(rng_lib);
|
exe.linkLibrary(rng_lib);
|
||||||
exe.linkLibrary(map_lib);
|
exe.linkLibrary(map_lib);
|
||||||
exe.addObject(combat_obj);
|
exe.linkLibrary(combat_lib);
|
||||||
exe.linkSystemLibrary("raylib");
|
exe.linkSystemLibrary("raylib");
|
||||||
exe.linkSystemLibrary("m");
|
exe.linkSystemLibrary("m");
|
||||||
exe.linkSystemLibrary("pthread");
|
exe.linkSystemLibrary("pthread");
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "common.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef AUDIO_H
|
#ifndef AUDIO_H
|
||||||
#define AUDIO_H
|
#define AUDIO_H
|
||||||
#include "game_state.h"
|
#include "common.h"
|
||||||
|
|
||||||
// Initialize audio system
|
// Initialize audio system
|
||||||
void audio_init(void);
|
void audio_init(void);
|
||||||
|
|
|
||||||
65
src/common.h
65
src/common.h
|
|
@ -2,7 +2,7 @@
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <stdbool.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
@ -114,5 +114,68 @@ typedef struct {
|
||||||
int effect_count;
|
int effect_count;
|
||||||
} Enemy;
|
} 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
|
#endif // COMMON_H
|
||||||
|
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
#ifndef GAME_STATE_H
|
|
||||||
#define GAME_STATE_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
#include "game_state.h"
|
#include "common.h"
|
||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
#include "map/map.h"
|
#include "map/map.h"
|
||||||
#include "movement.h"
|
#include "movement.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "raylib.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "rng/rng.h"
|
#include "rng/rng.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
#include "common.h"
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
|
#include "raylib.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#ifndef RENDER_H
|
#ifndef RENDER_H
|
||||||
#define RENDER_H
|
#define RENDER_H
|
||||||
|
|
||||||
#include "game_state.h"
|
#include "common.h"
|
||||||
|
|
||||||
// HUD colors
|
// HUD colors
|
||||||
#define HUD_BG (Color){25, 20, 15, 255}
|
#define HUD_BG (Color){25, 20, 15, 255}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue