Compare commits
2 commits
main
...
notashelf/
| Author | SHA1 | Date | |
|---|---|---|---|
|
dbf8d4886c |
|||
|
c2412ac4b1 |
25 changed files with 294 additions and 503 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
76
build.zig
76
build.zig
|
|
@ -4,55 +4,8 @@ pub fn build(b: *std.Build) void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const c_flags = [_][]const u8{
|
// Zig combat library
|
||||||
"-std=c99",
|
const combat_lib = b.addLibrary(.{
|
||||||
"-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(.{
|
|
||||||
.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"),
|
||||||
|
|
@ -61,20 +14,28 @@ pub fn build(b: *std.Build) void {
|
||||||
.link_libc = true,
|
.link_libc = true,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
// common.h and settings.h live in src/; rng.h exposed bare from libs/rng
|
combat_lib.addIncludePath(b.path("src"));
|
||||||
combat_obj.addIncludePath(b.path("src"));
|
combat_lib.linkSystemLibrary("raylib");
|
||||||
combat_obj.addIncludePath(b.path("libs/rng"));
|
|
||||||
|
|
||||||
// C sources remaining in src/
|
// C sources (everything except combat, which is now Zig)
|
||||||
const c_sources = [_][]const u8{
|
const c_sources = [_][]const u8{
|
||||||
"src/audio.c",
|
"src/audio.c",
|
||||||
"src/enemy.c",
|
"src/enemy.c",
|
||||||
"src/items.c",
|
"src/items.c",
|
||||||
"src/main.c",
|
"src/main.c",
|
||||||
"src/movement.c",
|
"src/map.c",
|
||||||
"src/player.c",
|
"src/player.c",
|
||||||
"src/render.c",
|
"src/render.c",
|
||||||
|
"src/rng.c",
|
||||||
"src/settings.c",
|
"src/settings.c",
|
||||||
|
"src/utils.c",
|
||||||
|
};
|
||||||
|
|
||||||
|
const c_flags = [_][]const u8{
|
||||||
|
"-std=c99",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Main executable
|
// Main executable
|
||||||
|
|
@ -92,13 +53,8 @@ pub fn build(b: *std.Build) void {
|
||||||
.flags = &c_flags,
|
.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("src"));
|
||||||
exe.addIncludePath(b.path("libs"));
|
exe.linkLibrary(combat_lib);
|
||||||
|
|
||||||
exe.linkLibrary(rng_lib);
|
|
||||||
exe.linkLibrary(map_lib);
|
|
||||||
exe.addObject(combat_obj);
|
|
||||||
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);
|
||||||
|
|
|
||||||
71
src/common.h
71
src/common.h
|
|
@ -2,11 +2,7 @@
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <stdbool.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x, y;
|
|
||||||
} Vec2;
|
|
||||||
|
|
||||||
// Tile types
|
// Tile types
|
||||||
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS } TileType;
|
typedef enum { TILE_WALL, TILE_FLOOR, TILE_STAIRS } TileType;
|
||||||
|
|
@ -63,7 +59,7 @@ typedef struct {
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vec2 position;
|
int x, y;
|
||||||
int hp, max_hp;
|
int hp, max_hp;
|
||||||
int attack;
|
int attack;
|
||||||
int defense;
|
int defense;
|
||||||
|
|
@ -89,7 +85,7 @@ typedef enum { ENEMY_GOBLIN, ENEMY_SKELETON, ENEMY_ORC } EnemyType;
|
||||||
|
|
||||||
// Enemy
|
// Enemy
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vec2 position;
|
int x, y;
|
||||||
int hp;
|
int hp;
|
||||||
int max_hp;
|
int max_hp;
|
||||||
int attack;
|
int attack;
|
||||||
|
|
@ -114,5 +110,66 @@ 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;
|
||||||
|
} GameState;
|
||||||
|
|
||||||
|
|
||||||
#endif // COMMON_H
|
#endif // COMMON_H
|
||||||
|
|
|
||||||
95
src/enemy.c
95
src/enemy.c
|
|
@ -1,9 +1,8 @@
|
||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "map/map.h"
|
#include "map.h"
|
||||||
#include "movement.h"
|
#include "rng.h"
|
||||||
#include "rng/rng.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
@ -31,7 +30,7 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
get_random_floor_tile(map, &ex, &ey, 50);
|
get_random_floor_tile(map, &ex, &ey, 50);
|
||||||
|
|
||||||
// Don't spawn on player position
|
// Don't spawn on player position
|
||||||
if (ex == p->position.x && ey == p->position.y) {
|
if (ex == p->x && ey == p->y) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,8 +42,8 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
// Create enemy
|
// Create enemy
|
||||||
Enemy e;
|
Enemy e;
|
||||||
memset(&e, 0, sizeof(Enemy));
|
memset(&e, 0, sizeof(Enemy));
|
||||||
e.position.x = ex;
|
e.x = ex;
|
||||||
e.position.y = ey;
|
e.y = ey;
|
||||||
e.alive = 1;
|
e.alive = 1;
|
||||||
e.type = rng_int(ENEMY_GOBLIN, max_type);
|
e.type = rng_int(ENEMY_GOBLIN, max_type);
|
||||||
e.effect_count = 0;
|
e.effect_count = 0;
|
||||||
|
|
@ -133,7 +132,7 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
|
||||||
// Check if position has an enemy
|
// Check if position has an enemy
|
||||||
int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (enemies[i].alive && enemies[i].position.x == x && enemies[i].position.y == y) {
|
if (enemies[i].alive && enemies[i].x == x && enemies[i].y == y) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,35 +141,43 @@ int is_enemy_at(const Enemy *enemies, int count, int x, int y) {
|
||||||
|
|
||||||
// Check if enemy can see player (within view range and line of sight)
|
// Check if enemy can see player (within view range and line of sight)
|
||||||
static int can_see_player(Enemy *e, Player *p, Map *map) {
|
static int can_see_player(Enemy *e, Player *p, Map *map) {
|
||||||
return can_see_entity(map, e->position.x, e->position.y, p->position.x, p->position.y, e->vision_range);
|
return can_see_entity(map, e->x, e->y, p->x, p->y, e->vision_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if position is occupied by player
|
||||||
|
static int is_player_at(Player *p, int x, int y) {
|
||||||
|
return (p->x == x && p->y == y);
|
||||||
|
}
|
||||||
|
|
||||||
// Move enemy toward player
|
// Move enemy toward player
|
||||||
static void enemy_move_toward_player(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_count) {
|
static void enemy_move_toward_player(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
|
|
||||||
if (p->position.x > e->position.x)
|
if (p->x > e->x)
|
||||||
dx = 1;
|
dx = 1;
|
||||||
else if (p->position.x < e->position.x)
|
else if (p->x < e->x)
|
||||||
dx = -1;
|
dx = -1;
|
||||||
|
|
||||||
if (p->position.y > e->position.y)
|
if (p->y > e->y)
|
||||||
dy = 1;
|
dy = 1;
|
||||||
else if (p->position.y < e->position.y)
|
else if (p->y < e->y)
|
||||||
dy = -1;
|
dy = -1;
|
||||||
|
|
||||||
Vec2 dir = {dx, 0};
|
// Try horizontal first, then vertical
|
||||||
if (dx != 0) {
|
int new_x = e->x + dx;
|
||||||
MoveResult r = try_move_entity(&e->position, dir, map, p, all_enemies, enemy_count, false);
|
int new_y = e->y;
|
||||||
if (r == MOVE_RESULT_MOVED)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dir.x = 0;
|
if (dx != 0 && is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y) &&
|
||||||
dir.y = dy;
|
!is_player_at(p, new_x, new_y)) {
|
||||||
if (dy != 0) {
|
e->x = new_x;
|
||||||
try_move_entity(&e->position, dir, map, p, all_enemies, enemy_count, false);
|
} else if (dy != 0) {
|
||||||
|
new_x = e->x;
|
||||||
|
new_y = e->y + dy;
|
||||||
|
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y) &&
|
||||||
|
!is_player_at(p, new_x, new_y)) {
|
||||||
|
e->x = new_x;
|
||||||
|
e->y = new_y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,12 +192,12 @@ static void enemy_patrol(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count
|
||||||
if (dx == 0 && dy == 0)
|
if (dx == 0 && dy == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int new_x = e->position.x + dx;
|
int new_x = e->x + dx;
|
||||||
int new_y = e->position.y + dy;
|
int new_y = e->y + dy;
|
||||||
|
|
||||||
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
||||||
e->position.x = new_x;
|
e->x = new_x;
|
||||||
e->position.y = new_y;
|
e->y = new_y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,31 +205,31 @@ static void enemy_patrol(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count
|
||||||
static void enemy_move_to_last_known(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count) {
|
static void enemy_move_to_last_known(Enemy *e, Map *map, Enemy *all_enemies, int enemy_count) {
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
|
|
||||||
if (e->last_known_x > e->position.x)
|
if (e->last_known_x > e->x)
|
||||||
dx = 1;
|
dx = 1;
|
||||||
else if (e->last_known_x < e->position.x)
|
else if (e->last_known_x < e->x)
|
||||||
dx = -1;
|
dx = -1;
|
||||||
|
|
||||||
if (e->last_known_y > e->position.y)
|
if (e->last_known_y > e->y)
|
||||||
dy = 1;
|
dy = 1;
|
||||||
else if (e->last_known_y < e->position.y)
|
else if (e->last_known_y < e->y)
|
||||||
dy = -1;
|
dy = -1;
|
||||||
|
|
||||||
int new_x = e->position.x + dx;
|
int new_x = e->x + dx;
|
||||||
int new_y = e->position.y;
|
int new_y = e->y;
|
||||||
|
|
||||||
if (dx != 0 && is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
if (dx != 0 && is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
||||||
e->position.x = new_x;
|
e->x = new_x;
|
||||||
} else if (dy != 0) {
|
} else if (dy != 0) {
|
||||||
new_x = e->position.x;
|
new_x = e->x;
|
||||||
new_y = e->position.y + dy;
|
new_y = e->y + dy;
|
||||||
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
if (is_floor(map, new_x, new_y) && !is_enemy_at(all_enemies, enemy_count, new_x, new_y)) {
|
||||||
e->position.x = new_x;
|
e->x = new_x;
|
||||||
e->position.y = new_y;
|
e->y = new_y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->position.x == e->last_known_x && e->position.y == e->last_known_y)
|
if (e->x == e->last_known_x && e->y == e->last_known_y)
|
||||||
e->alert = 0;
|
e->alert = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,8 +238,8 @@ static int is_nearby_enemy(const Enemy *enemies, int count, int x, int y, int ra
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (!enemies[i].alive)
|
if (!enemies[i].alive)
|
||||||
continue;
|
continue;
|
||||||
int dx = enemies[i].position.x - x;
|
int dx = enemies[i].x - x;
|
||||||
int dy = enemies[i].position.y - y;
|
int dy = enemies[i].y - y;
|
||||||
if (dx * dx + dy * dy <= radius * radius)
|
if (dx * dx + dy * dy <= radius * radius)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +254,7 @@ static void propagate_alert(Enemy *trigger_enemy, Enemy *all_enemies, int enemy_
|
||||||
continue;
|
continue;
|
||||||
if (e->alert)
|
if (e->alert)
|
||||||
continue;
|
continue;
|
||||||
if (is_nearby_enemy(all_enemies, enemy_count, e->position.x, e->position.y, 5)) {
|
if (is_nearby_enemy(all_enemies, enemy_count, e->x, e->y, 5)) {
|
||||||
e->alert = 1;
|
e->alert = 1;
|
||||||
e->last_known_x = trigger_enemy->last_known_x;
|
e->last_known_x = trigger_enemy->last_known_x;
|
||||||
e->last_known_y = trigger_enemy->last_known_y;
|
e->last_known_y = trigger_enemy->last_known_y;
|
||||||
|
|
@ -269,12 +276,12 @@ void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_coun
|
||||||
// If we can see the player, update alert state and last known position
|
// If we can see the player, update alert state and last known position
|
||||||
if (can_see) {
|
if (can_see) {
|
||||||
e->alert = 1;
|
e->alert = 1;
|
||||||
e->last_known_x = p->position.x;
|
e->last_known_x = p->x;
|
||||||
e->last_known_y = p->position.y;
|
e->last_known_y = p->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attack if adjacent to player
|
// Attack if adjacent to player
|
||||||
if (can_see && can_see_entity(map, e->position.x, e->position.y, p->position.x, p->position.y, 1)) {
|
if (can_see && can_see_entity(map, e->x, e->y, p->x, p->y, 1)) {
|
||||||
combat_enemy_attack(e, p);
|
combat_enemy_attack(e, p);
|
||||||
propagate_alert(e, all_enemies, enemy_count);
|
propagate_alert(e, all_enemies, enemy_count);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -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,6 +1,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "map/map.h"
|
#include "map.h"
|
||||||
#include "rng/rng.h"
|
#include "rng.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
|
||||||
173
src/main.c
173
src/main.c
|
|
@ -1,20 +1,17 @@
|
||||||
#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.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.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <ctype.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
// Add message to action log
|
// Add message to action log
|
||||||
static void add_log(GameState *gs, const char *msg) {
|
static void add_log(GameState *gs, const char *msg) {
|
||||||
|
|
@ -104,14 +101,11 @@ static void update_effects(GameState *gs) {
|
||||||
|
|
||||||
// Initialize a new floor
|
// Initialize a new floor
|
||||||
static void init_floor(GameState *gs, int floor_num) {
|
static void init_floor(GameState *gs, int floor_num) {
|
||||||
// Seed RNG with run seed combined with floor number for deterministic generation
|
|
||||||
rng_seed(gs->run_seed + floor_num * 54321);
|
|
||||||
|
|
||||||
// Generate dungeon
|
// Generate dungeon
|
||||||
dungeon_generate(&gs->dungeon, &gs->map, floor_num);
|
dungeon_generate(&gs->dungeon, &gs->map, floor_num);
|
||||||
|
|
||||||
// Seed rng for this floor's content
|
// Seed rng for this floor's content
|
||||||
rng_seed(gs->run_seed + floor_num * 98765);
|
rng_seed(floor_num * 54321);
|
||||||
|
|
||||||
// Find spawn position
|
// Find spawn position
|
||||||
int start_x, start_y;
|
int start_x, start_y;
|
||||||
|
|
@ -123,13 +117,13 @@ static void init_floor(GameState *gs, int floor_num) {
|
||||||
gs->floors_reached = 1;
|
gs->floors_reached = 1;
|
||||||
} else {
|
} else {
|
||||||
// Move player to new floor position
|
// Move player to new floor position
|
||||||
gs->player.position.x = start_x;
|
gs->player.x = start_x;
|
||||||
gs->player.position.y = start_y;
|
gs->player.y = start_y;
|
||||||
}
|
}
|
||||||
gs->player.floor = floor_num;
|
gs->player.floor = floor_num;
|
||||||
|
|
||||||
// Calculate initial visibility
|
// Calculate initial visibility
|
||||||
calculate_visibility(&gs->map, gs->player.position.x, gs->player.position.y);
|
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||||
|
|
||||||
// Spawn enemies
|
// Spawn enemies
|
||||||
enemy_spawn(gs->enemies, &gs->enemy_count, &gs->map, &gs->player, floor_num);
|
enemy_spawn(gs->enemies, &gs->enemy_count, &gs->map, &gs->player, floor_num);
|
||||||
|
|
@ -146,8 +140,7 @@ static void tick_all_effects(GameState *gs) {
|
||||||
// Player effects
|
// Player effects
|
||||||
int player_effect_dmg = combat_tick_effects(&gs->player);
|
int player_effect_dmg = combat_tick_effects(&gs->player);
|
||||||
if (player_effect_dmg > 0) {
|
if (player_effect_dmg > 0) {
|
||||||
spawn_floating_text(gs, gs->player.position.x * TILE_SIZE + 8, gs->player.position.y * TILE_SIZE, player_effect_dmg,
|
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, player_effect_dmg, 0);
|
||||||
0);
|
|
||||||
gs->screen_shake = SHAKE_EFFECT_DURATION;
|
gs->screen_shake = SHAKE_EFFECT_DURATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +158,7 @@ static void tick_all_effects(GameState *gs) {
|
||||||
continue;
|
continue;
|
||||||
int enemy_effect_dmg = combat_tick_enemy_effects(e);
|
int enemy_effect_dmg = combat_tick_enemy_effects(e);
|
||||||
if (enemy_effect_dmg > 0) {
|
if (enemy_effect_dmg > 0) {
|
||||||
spawn_floating_text(gs, e->position.x * TILE_SIZE + 8, e->position.y * TILE_SIZE, enemy_effect_dmg, 0);
|
spawn_floating_text(gs, e->x * TILE_SIZE + 8, e->y * TILE_SIZE, enemy_effect_dmg, 0);
|
||||||
}
|
}
|
||||||
if (!e->alive) {
|
if (!e->alive) {
|
||||||
add_log(gs, "Enemy died from effects!");
|
add_log(gs, "Enemy died from effects!");
|
||||||
|
|
@ -183,7 +176,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if stepped on stairs
|
// Check if stepped on stairs
|
||||||
if (gs->map.tiles[gs->player.position.y][gs->player.position.x] == TILE_STAIRS) {
|
if (gs->map.tiles[gs->player.y][gs->player.x] == TILE_STAIRS) {
|
||||||
gs->awaiting_descend = 1;
|
gs->awaiting_descend = 1;
|
||||||
gs->last_message = "Descend to next floor? (Y/N)";
|
gs->last_message = "Descend to next floor? (Y/N)";
|
||||||
gs->message_timer = 120;
|
gs->message_timer = 120;
|
||||||
|
|
@ -192,8 +185,8 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
|
|
||||||
// combat feedback - player attacked an enemy this turn
|
// combat feedback - player attacked an enemy this turn
|
||||||
if (attacked_enemy != NULL) {
|
if (attacked_enemy != NULL) {
|
||||||
int ex = attacked_enemy->position.x * TILE_SIZE + 8;
|
int ex = attacked_enemy->x * TILE_SIZE + 8;
|
||||||
int ey = attacked_enemy->position.y * TILE_SIZE;
|
int ey = attacked_enemy->y * TILE_SIZE;
|
||||||
|
|
||||||
if (combat_was_dodged()) {
|
if (combat_was_dodged()) {
|
||||||
spawn_floating_label(gs, ex, ey, LABEL_DODGE, EFFECT_NONE);
|
spawn_floating_label(gs, ex, ey, LABEL_DODGE, EFFECT_NONE);
|
||||||
|
|
@ -226,7 +219,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update visibility based on player's new position
|
// Update visibility based on player's new position
|
||||||
calculate_visibility(&gs->map, gs->player.position.x, gs->player.position.y);
|
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||||
|
|
||||||
// Enemy turns - uses speed/cooldown system
|
// Enemy turns - uses speed/cooldown system
|
||||||
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
||||||
|
|
@ -237,8 +230,8 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
|
||||||
gs->screen_shake = SHAKE_PLAYER_DAMAGE_DURATION;
|
gs->screen_shake = SHAKE_PLAYER_DAMAGE_DURATION;
|
||||||
gs->damage_taken += combat_get_last_damage();
|
gs->damage_taken += combat_get_last_damage();
|
||||||
gs->times_hit++;
|
gs->times_hit++;
|
||||||
spawn_floating_text(gs, gs->player.position.x * TILE_SIZE + 8, gs->player.position.y * TILE_SIZE,
|
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, combat_get_last_damage(),
|
||||||
combat_get_last_damage(), combat_was_critical());
|
combat_was_critical());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set message and check game over
|
// Set message and check game over
|
||||||
|
|
@ -259,7 +252,7 @@ static int handle_stun_turn(GameState *gs) {
|
||||||
if (gs->game_over)
|
if (gs->game_over)
|
||||||
return 1;
|
return 1;
|
||||||
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
enemy_update_all(gs->enemies, gs->enemy_count, &gs->player, &gs->map);
|
||||||
calculate_visibility(&gs->map, gs->player.position.x, gs->player.position.y);
|
calculate_visibility(&gs->map, gs->player.x, gs->player.y);
|
||||||
if (gs->player.hp <= 0)
|
if (gs->player.hp <= 0)
|
||||||
gs->game_over = 1;
|
gs->game_over = 1;
|
||||||
gs->last_message = "You are stunned!";
|
gs->last_message = "You are stunned!";
|
||||||
|
|
@ -402,7 +395,7 @@ static int handle_movement_input(GameState *gs) {
|
||||||
|
|
||||||
// Check for manual item pickup (G key)
|
// Check for manual item pickup (G key)
|
||||||
if (IsKeyPressed(KEY_G)) {
|
if (IsKeyPressed(KEY_G)) {
|
||||||
Item *item = get_item_at_floor(gs->items, gs->item_count, gs->player.position.x, gs->player.position.y);
|
Item *item = get_item_at_floor(gs->items, gs->item_count, gs->player.x, gs->player.y);
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
if (player_pickup(&gs->player, item)) {
|
if (player_pickup(&gs->player, item)) {
|
||||||
gs->items_collected++;
|
gs->items_collected++;
|
||||||
|
|
@ -431,45 +424,38 @@ static int handle_movement_input(GameState *gs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Movement: use IsKeyDown for held-key repeat
|
||||||
Vec2 direction = {0, 0};
|
int dx = 0, dy = 0;
|
||||||
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))
|
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))
|
||||||
direction.y = -1;
|
dy = -1;
|
||||||
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))
|
else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))
|
||||||
direction.y = 1;
|
dy = 1;
|
||||||
else if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))
|
else if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))
|
||||||
direction.x = -1;
|
dx = -1;
|
||||||
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))
|
else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))
|
||||||
direction.x = 1;
|
dx = 1;
|
||||||
|
|
||||||
if (direction.x == 0 && direction.y == 0)
|
if (dx == 0 && dy == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Reset combat event before player acts
|
// Reset combat event before player acts
|
||||||
combat_reset_event();
|
combat_reset_event();
|
||||||
|
|
||||||
|
int new_x = gs->player.x + dx;
|
||||||
int new_x = gs->player.position.x + direction.x;
|
int new_y = gs->player.y + dy;
|
||||||
int new_y = gs->player.position.y + direction.y;
|
|
||||||
|
|
||||||
Enemy *target = NULL;
|
|
||||||
int action = 0;
|
int action = 0;
|
||||||
|
|
||||||
MoveResult result =
|
// Attack enemy at target tile, or move into it
|
||||||
try_move_entity(&gs->player.position, direction, &gs->map, &gs->player, gs->enemies, gs->enemy_count, true);
|
Enemy *target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
||||||
if (result == MOVE_RESULT_MOVED) {
|
if (target != NULL) {
|
||||||
player_on_move(&gs->player);
|
player_attack(&gs->player, target);
|
||||||
action = 1;
|
action = 1;
|
||||||
} else if (result == MOVE_RESULT_BLOCKED_ENEMY) {
|
} else {
|
||||||
target = player_find_enemy_at(gs->enemies, gs->enemy_count, new_x, new_y);
|
action = player_move(&gs->player, dx, dy, &gs->map);
|
||||||
if (target != NULL) {
|
|
||||||
player_attack(&gs->player, target);
|
|
||||||
action = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
post_action(gs, target);
|
post_action(gs, target); // target is NULL on move, enemy ptr on attack
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
@ -483,13 +469,7 @@ static int handle_input(GameState *gs) {
|
||||||
// Check for restart (works during game over)
|
// Check for restart (works during game over)
|
||||||
if (IsKeyPressed(KEY_R) && gs->game_over) {
|
if (IsKeyPressed(KEY_R) && gs->game_over) {
|
||||||
memset(gs, 0, sizeof(GameState));
|
memset(gs, 0, sizeof(GameState));
|
||||||
// Generate a new random seed for the new run
|
|
||||||
gs->run_seed = (unsigned int)time(NULL);
|
|
||||||
init_floor(gs, 1);
|
init_floor(gs, 1);
|
||||||
// Update window title with new seed
|
|
||||||
char title[128];
|
|
||||||
snprintf(title, sizeof(title), "Roguelike - Seed: %u", gs->run_seed);
|
|
||||||
SetWindowTitle(title);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -519,16 +499,12 @@ void load_audio_assets(GameState *gs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
static void game_loop(unsigned int run_seed) {
|
static void game_loop(void) {
|
||||||
GameState gs;
|
GameState gs;
|
||||||
memset(&gs, 0, sizeof(GameState));
|
memset(&gs, 0, sizeof(GameState));
|
||||||
gs.run_seed = run_seed;
|
|
||||||
// load external assets
|
|
||||||
// sound
|
|
||||||
load_audio_assets(&gs);
|
load_audio_assets(&gs);
|
||||||
// font
|
|
||||||
Font fontTTF = LoadFontEx("./assets/fonts/spartan_500.ttf", 36, NULL, 0);
|
|
||||||
// Initialize first floor
|
// Initialize first floor
|
||||||
|
rng_seed(12345);
|
||||||
init_floor(&gs, 1);
|
init_floor(&gs, 1);
|
||||||
|
|
||||||
// Disable esc to exit
|
// Disable esc to exit
|
||||||
|
|
@ -548,16 +524,10 @@ static void game_loop(unsigned int run_seed) {
|
||||||
break;
|
break;
|
||||||
if (IsKeyPressed(KEY_R)) {
|
if (IsKeyPressed(KEY_R)) {
|
||||||
memset(&gs, 0, sizeof(GameState));
|
memset(&gs, 0, sizeof(GameState));
|
||||||
// Generate a new random seed for the new run
|
|
||||||
gs.run_seed = (unsigned int)time(NULL);
|
|
||||||
gs.game_over = 0;
|
gs.game_over = 0;
|
||||||
gs.game_won = 0;
|
gs.game_won = 0;
|
||||||
load_audio_assets(&gs);
|
load_audio_assets(&gs);
|
||||||
init_floor(&gs, 1);
|
init_floor(&gs, 1);
|
||||||
// Update window title with new seed
|
|
||||||
char title[128];
|
|
||||||
snprintf(title, sizeof(title), "Roguelike - Seed: %u", gs.run_seed);
|
|
||||||
SetWindowTitle(title);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -585,24 +555,21 @@ static void game_loop(unsigned int run_seed) {
|
||||||
|
|
||||||
// Floating texts follow world shake
|
// Floating texts follow world shake
|
||||||
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
|
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
|
||||||
render_ui(&gs.player, &fontTTF);
|
render_ui(&gs.player);
|
||||||
|
|
||||||
// Draw action log
|
// Draw action log
|
||||||
render_action_log(gs.action_log, gs.log_count, gs.log_head, &fontTTF);
|
render_action_log(gs.action_log, gs.log_count, gs.log_head);
|
||||||
|
|
||||||
// Draw inventory overlay if active
|
// Draw inventory overlay if active
|
||||||
if (gs.show_inventory) {
|
if (gs.show_inventory) {
|
||||||
render_inventory_overlay(&gs.player, gs.inv_selected, &fontTTF);
|
render_inventory_overlay(&gs.player, gs.inv_selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw message if any
|
// Draw message if any
|
||||||
if (gs.last_message != NULL && gs.message_timer > 0) {
|
if (gs.last_message != NULL && gs.message_timer > 0) {
|
||||||
render_message(gs.last_message, &fontTTF);
|
render_message(gs.last_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw persistent seed display in top right
|
|
||||||
render_seed_display(gs.run_seed);
|
|
||||||
|
|
||||||
// Draw game over screen
|
// Draw game over screen
|
||||||
if (gs.game_over) {
|
if (gs.game_over) {
|
||||||
// Compute final score
|
// Compute final score
|
||||||
|
|
@ -613,7 +580,7 @@ static void game_loop(unsigned int run_seed) {
|
||||||
}
|
}
|
||||||
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
||||||
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
||||||
gs.final_score, gs.run_seed, &fontTTF);
|
gs.final_score);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
@ -623,67 +590,17 @@ static void game_loop(unsigned int run_seed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a string is a valid unsigned integer
|
int main(void) {
|
||||||
static int is_valid_uint(const char *str) {
|
|
||||||
if (str == NULL || *str == '\0')
|
|
||||||
return 0;
|
|
||||||
// Check for optional leading +
|
|
||||||
if (*str == '+')
|
|
||||||
str++;
|
|
||||||
// Must have at least one digit
|
|
||||||
if (*str == '\0')
|
|
||||||
return 0;
|
|
||||||
// All characters must be digits
|
|
||||||
for (const char *p = str; *p != '\0'; p++) {
|
|
||||||
if (!isdigit((unsigned char)*p))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
// Parse command-line arguments
|
|
||||||
unsigned int run_seed = 0;
|
|
||||||
int seed_provided = 0;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
if (strcmp(argv[i], "--seed") == 0) {
|
|
||||||
if (i + 1 >= argc) {
|
|
||||||
fprintf(stderr, "Error: --seed requires a value\n");
|
|
||||||
fprintf(stderr, "Usage: %s [--seed <number>]\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
const char *seed_str = argv[i + 1];
|
|
||||||
if (!is_valid_uint(seed_str)) {
|
|
||||||
fprintf(stderr, "Error: Invalid seed value: %s\n", seed_str);
|
|
||||||
fprintf(stderr, "Seed must be a non-negative integer\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
run_seed = (unsigned int)strtoul(seed_str, NULL, 10);
|
|
||||||
seed_provided = 1;
|
|
||||||
i++; // Skip the value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no seed provided, generate random seed from time
|
|
||||||
if (!seed_provided) {
|
|
||||||
run_seed = (unsigned int)time(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Starting game with seed: %u\n", run_seed);
|
|
||||||
|
|
||||||
// Initialize audio
|
// Initialize audio
|
||||||
audio_init();
|
audio_init();
|
||||||
// Initialize random number generator
|
// Initialize random number generator
|
||||||
SetRandomSeed(88435);
|
SetRandomSeed(88435);
|
||||||
// Initialize window with seed in title
|
// Initialize window
|
||||||
char title[128];
|
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT + 60, "Roguelike");
|
||||||
snprintf(title, sizeof(title), "Roguelike - Seed: %u", run_seed);
|
|
||||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT + 60, title);
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
// Run game
|
// Run game
|
||||||
game_loop(run_seed);
|
game_loop();
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "rng/rng.h"
|
#include "rng.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -170,6 +170,9 @@ void get_random_floor_tile(Map *map, int *x, int *y, int attempts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dungeon_generate(Dungeon *d, Map *map, int floor_num) {
|
void dungeon_generate(Dungeon *d, Map *map, int floor_num) {
|
||||||
|
// Seed RNG with floor number for deterministic generation
|
||||||
|
rng_seed(floor_num * 12345);
|
||||||
|
|
||||||
// Initialize map to all walls
|
// Initialize map to all walls
|
||||||
map_init(map);
|
map_init(map);
|
||||||
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
#include "movement.h"
|
|
||||||
#include "enemy.h"
|
|
||||||
#include "map/map.h"
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
// Check if position is occupied by player
|
|
||||||
static int is_player_at(Player *p, int x, int y) {
|
|
||||||
return (p->position.x == x && p->position.y == y);
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveResult try_move_entity(Vec2 *p, Vec2 direction, Map *map, Player *player, Enemy *enemies, int enemy_count,
|
|
||||||
bool moving_is_player) {
|
|
||||||
int new_x = p->x + direction.x;
|
|
||||||
int new_y = p->y + direction.y;
|
|
||||||
|
|
||||||
if (!is_floor(map, new_x, new_y))
|
|
||||||
return MOVE_RESULT_BLOCKED_WALL;
|
|
||||||
|
|
||||||
if (is_enemy_at(enemies, enemy_count, new_x, new_y))
|
|
||||||
return MOVE_RESULT_BLOCKED_ENEMY;
|
|
||||||
if (!moving_is_player) {
|
|
||||||
if (is_player_at(player, new_x, new_y))
|
|
||||||
return MOVE_RESULT_BLOCKED_PLAYER;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->x = new_x;
|
|
||||||
p->y = new_y;
|
|
||||||
return MOVE_RESULT_MOVED;
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef MOVEMENT_H
|
|
||||||
#define MOVEMENT_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
MOVE_RESULT_MOVED,
|
|
||||||
MOVE_RESULT_BLOCKED_WALL,
|
|
||||||
MOVE_RESULT_BLOCKED_PLAYER,
|
|
||||||
MOVE_RESULT_BLOCKED_ENEMY
|
|
||||||
} MoveResult;
|
|
||||||
|
|
||||||
// Attempts to move entity in a given direction. Returns outcome of action.
|
|
||||||
MoveResult try_move_entity(Vec2 *p, Vec2 direction, Map *map, Player *player, Enemy *enemies, int enemy_count,
|
|
||||||
bool moving_is_player);
|
|
||||||
|
|
||||||
#endif // MOVEMENT_H
|
|
||||||
31
src/player.c
31
src/player.c
|
|
@ -2,12 +2,15 @@
|
||||||
#include "combat.h"
|
#include "combat.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
|
#include "map.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void player_init(Player *p, int x, int y) {
|
void player_init(Player *p, int x, int y) {
|
||||||
p->position.x = x;
|
p->x = x;
|
||||||
p->position.y = y;
|
p->y = y;
|
||||||
p->hp = PLAYER_BASE_HP;
|
p->hp = PLAYER_BASE_HP;
|
||||||
p->max_hp = PLAYER_BASE_HP;
|
p->max_hp = PLAYER_BASE_HP;
|
||||||
p->attack = PLAYER_BASE_ATTACK;
|
p->attack = PLAYER_BASE_ATTACK;
|
||||||
|
|
@ -40,20 +43,36 @@ Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y) {
|
||||||
if (count > MAX_ENEMIES)
|
if (count > MAX_ENEMIES)
|
||||||
count = MAX_ENEMIES;
|
count = MAX_ENEMIES;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (enemies[i].alive && enemies[i].position.x == x && enemies[i].position.y == y)
|
if (enemies[i].alive && enemies[i].x == x && enemies[i].y == y)
|
||||||
return &enemies[i];
|
return &enemies[i];
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_on_move(Player *p) {
|
int player_move(Player *p, int dx, int dy, Map *map) {
|
||||||
|
int new_x = p->x + dx;
|
||||||
|
int new_y = p->y + dy;
|
||||||
|
|
||||||
|
// Check bounds
|
||||||
|
if (!in_bounds(new_x, new_y, MAP_WIDTH, MAP_HEIGHT))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Check if walkable
|
||||||
|
if (!is_floor(map, new_x, new_y))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Move player
|
||||||
|
p->x = new_x;
|
||||||
|
p->y = new_y;
|
||||||
p->step_count += 1;
|
p->step_count += 1;
|
||||||
|
// Regen suppressed while poisoned, bleeding, or burning
|
||||||
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
|
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
|
||||||
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
|
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
|
||||||
p->hp += 1;
|
p->hp += 1;
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_attack(Player *p, Enemy *e) {
|
void player_attack(Player *p, Enemy *e) {
|
||||||
|
|
@ -209,8 +228,8 @@ int player_drop_item(Player *p, int inv_index, Item *items, int item_count) {
|
||||||
if (items[i].picked_up) {
|
if (items[i].picked_up) {
|
||||||
// Place dropped item at this position
|
// Place dropped item at this position
|
||||||
items[i] = *item;
|
items[i] = *item;
|
||||||
items[i].x = p->position.x;
|
items[i].x = p->x;
|
||||||
items[i].y = p->position.y;
|
items[i].y = p->y;
|
||||||
items[i].picked_up = 0;
|
items[i].picked_up = 0;
|
||||||
// Remove from inventory
|
// Remove from inventory
|
||||||
player_remove_inventory_item(p, inv_index);
|
player_remove_inventory_item(p, inv_index);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
// Initialize player at position
|
// Initialize player at position
|
||||||
void player_init(Player *p, int x, int y);
|
void player_init(Player *p, int x, int y);
|
||||||
|
|
||||||
// Apply status effects, healing, etc
|
// Move player to (x+dx, y+dy); returns 1 if moved, 0 if blocked
|
||||||
void player_on_move(Player *p);
|
int player_move(Player *p, int dx, int dy, Map *map);
|
||||||
|
|
||||||
// Find a living enemy at tile (x, y); returns NULL if none
|
// Find a living enemy at tile (x, y); returns NULL if none
|
||||||
Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y);
|
Enemy *player_find_enemy_at(Enemy *enemies, int count, int x, int y);
|
||||||
|
|
|
||||||
186
src/render.c
186
src/render.c
|
|
@ -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>
|
||||||
|
|
@ -41,8 +43,7 @@ void render_map(const Map *map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_player(const Player *p) {
|
void render_player(const Player *p) {
|
||||||
Rectangle rect = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
|
Rectangle rect = {(float)(p->x * TILE_SIZE), (float)(p->y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
||||||
(float)TILE_SIZE};
|
|
||||||
DrawRectangleRec(rect, BLUE);
|
DrawRectangleRec(rect, BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,11 +51,11 @@ void render_enemies(const Enemy *enemies, int count, const unsigned char visible
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (!enemies[i].alive)
|
if (!enemies[i].alive)
|
||||||
continue;
|
continue;
|
||||||
if (!visible[enemies[i].position.y][enemies[i].position.x])
|
if (!visible[enemies[i].y][enemies[i].x])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
|
Rectangle rect = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE), (float)TILE_SIZE,
|
||||||
(float)TILE_SIZE, (float)TILE_SIZE};
|
(float)TILE_SIZE};
|
||||||
|
|
||||||
// Different colors based on enemy type
|
// Different colors based on enemy type
|
||||||
Color enemy_color;
|
Color enemy_color;
|
||||||
|
|
@ -86,8 +87,8 @@ void render_enemies(const Enemy *enemies, int count, const unsigned char visible
|
||||||
bar_color = (Color){200, 180, 40, 255}; // yellow
|
bar_color = (Color){200, 180, 40, 255}; // yellow
|
||||||
else
|
else
|
||||||
bar_color = (Color){200, 60, 60, 255}; // red
|
bar_color = (Color){200, 60, 60, 255}; // red
|
||||||
Rectangle hp_bar = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE - 4),
|
Rectangle hp_bar = {(float)(enemies[i].x * TILE_SIZE), (float)(enemies[i].y * TILE_SIZE - 4), (float)hp_pixels,
|
||||||
(float)hp_pixels, 3};
|
3};
|
||||||
DrawRectangleRec(hp_bar, bar_color);
|
DrawRectangleRec(hp_bar, bar_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +125,7 @@ void render_items(const Item *items, int count, const unsigned char visible[MAP_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_ui(const Player *p, Font *font) {
|
void render_ui(const Player *p) {
|
||||||
// HUD Panel
|
// HUD Panel
|
||||||
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
const int hud_y = MAP_HEIGHT * TILE_SIZE;
|
||||||
const int hud_height = 60;
|
const int hud_height = 60;
|
||||||
|
|
@ -168,8 +169,7 @@ void render_ui(const Player *p, Font *font) {
|
||||||
int bar_height = 16;
|
int bar_height = 16;
|
||||||
|
|
||||||
// HP Label, above bar
|
// HP Label, above bar
|
||||||
// Vector2 hp_width = MeasureTextEx(*font, "HP", BIG_FONT, NAR_CHAR_SPACE);
|
DrawText("HP", bar_x, bar_y - 11, 9, text_dim);
|
||||||
DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 17}, BIG_FONT, NAR_CHAR_SPACE, text_dim);
|
|
||||||
|
|
||||||
// HP Bar background
|
// HP Bar background
|
||||||
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
|
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
|
||||||
|
|
@ -194,9 +194,8 @@ void render_ui(const Player *p, Font *font) {
|
||||||
// HP text, centered in bar
|
// HP text, centered in bar
|
||||||
char hp_text[32];
|
char hp_text[32];
|
||||||
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
|
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
|
||||||
int hp_text_w = MeasureText(hp_text, 12);
|
int hp_text_w = MeasureText(hp_text, 10);
|
||||||
DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, MEDIUM_FONT,
|
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 10, WHITE);
|
||||||
SMALL_CHAR_SPACE, WHITE);
|
|
||||||
|
|
||||||
// Status effects
|
// Status effects
|
||||||
int effect_x = bar_x;
|
int effect_x = bar_x;
|
||||||
|
|
@ -231,7 +230,7 @@ void render_ui(const Player *p, Font *font) {
|
||||||
if (p->effects[i].duration > 0) {
|
if (p->effects[i].duration > 0) {
|
||||||
char eff_text[16];
|
char eff_text[16];
|
||||||
snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration);
|
snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration);
|
||||||
DrawTextEx(*font, eff_text, (Vector2){effect_x, effect_y}, SMALL_FONT, NAR_CHAR_SPACE, eff_color);
|
DrawText(eff_text, effect_x, effect_y, 9, eff_color);
|
||||||
effect_x += 28;
|
effect_x += 28;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,68 +242,65 @@ void render_ui(const Player *p, Font *font) {
|
||||||
// Floor
|
// Floor
|
||||||
char floor_text[16];
|
char floor_text[16];
|
||||||
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
|
||||||
DrawTextEx(*font, floor_text, (Vector2){stats_x, stats_y}, 16, NORM_CHAR_SPACE, text_bright);
|
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
|
||||||
DrawTextEx(*font, "Floor", (Vector2){stats_x, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
|
||||||
|
|
||||||
// ATK
|
// ATK
|
||||||
char atk_text[16];
|
char atk_text[16];
|
||||||
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
|
||||||
DrawTextEx(*font, atk_text, (Vector2){stats_x + stat_spacing, stats_y}, 16, NORM_CHAR_SPACE, YELLOW);
|
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
|
||||||
DrawTextEx(*font, "ATK", (Vector2){stats_x + stat_spacing, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
|
||||||
|
|
||||||
// DEF
|
// DEF
|
||||||
char def_text[16];
|
char def_text[16];
|
||||||
snprintf(def_text, sizeof(def_text), "%d", p->defense);
|
snprintf(def_text, sizeof(def_text), "%d", p->defense);
|
||||||
DrawTextEx(*font, def_text, (Vector2){stats_x + stat_spacing * 2, stats_y}, 16, NORM_CHAR_SPACE,
|
DrawText(def_text, stats_x + stat_spacing * 2, stats_y, 14, (Color){100, 150, 255, 255});
|
||||||
(Color){100, 150, 255, 255});
|
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
|
||||||
DrawTextEx(*font, "DEF", (Vector2){stats_x + stat_spacing * 2, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim);
|
|
||||||
|
|
||||||
int equip_x = section2_end + 15;
|
int equip_x = section2_end + 15;
|
||||||
int equip_y = hud_y + 8;
|
int equip_y = hud_y + 8;
|
||||||
|
|
||||||
// Weapon slot
|
// Weapon slot
|
||||||
DrawTextEx(*font, "WEAPON", (Vector2){equip_x, equip_y}, MEDIUM_FONT, NAR_CHAR_SPACE, text_dim);
|
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
|
||||||
if (p->has_weapon) {
|
if (p->has_weapon) {
|
||||||
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
const char *weapon_name = item_get_name(&p->equipped_weapon);
|
||||||
if (weapon_name) {
|
if (weapon_name) {
|
||||||
char weapon_text[64];
|
char weapon_text[64];
|
||||||
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
|
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
|
||||||
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
dmg_class_get_short(p->equipped_weapon.dmg_class));
|
||||||
DrawTextEx(*font, weapon_text, (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){255, 220, 100, 255});
|
DrawText(weapon_text, equip_x, equip_y + 11, 10, (Color){255, 220, 100, 255});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawTextEx(*font, "None [IMP]", (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255});
|
DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Armor slot
|
// Armor slot
|
||||||
DrawTextEx(*font, "ARMOR", (Vector2){equip_x, equip_y + 26}, MEDIUM_FONT, NAR_CHAR_SPACE, text_dim);
|
DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim);
|
||||||
if (p->has_armor) {
|
if (p->has_armor) {
|
||||||
const char *armor_name = item_get_name(&p->equipped_armor);
|
const char *armor_name = item_get_name(&p->equipped_armor);
|
||||||
if (armor_name) {
|
if (armor_name) {
|
||||||
char armor_text[48];
|
char armor_text[48];
|
||||||
snprintf(armor_text, sizeof(armor_text), "%s +%d", armor_name, p->equipped_armor.power);
|
snprintf(armor_text, sizeof(armor_text), "%s +%d", armor_name, p->equipped_armor.power);
|
||||||
DrawTextEx(*font, armor_text, (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){100, 150, 255, 255});
|
DrawText(armor_text, equip_x, equip_y + 37, 10, (Color){100, 150, 255, 255});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawTextEx(*font, "None", (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255});
|
DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
int ctrl_x = section3_end + 20;
|
int ctrl_x = section3_end + 20;
|
||||||
int ctrl_y = hud_y + 14;
|
int ctrl_y = hud_y + 14;
|
||||||
|
|
||||||
DrawTextEx(*font, "[WASD] Move [G] Pickup [I] Inventory [U] Use", (Vector2){ctrl_x, ctrl_y}, MEDIUM_FONT,
|
DrawText("[WASD] Move [G] Pickup [I] Inventory [U] Use", ctrl_x, ctrl_y, 11, (Color){139, 119, 89, 255});
|
||||||
MED_CHAR_SPACE, (Color){139, 119, 89, 255});
|
DrawText("[E] Equip [D] Drop [Q] Quit", ctrl_x, ctrl_y + 16, 11, (Color){139, 119, 89, 255});
|
||||||
DrawTextEx(*font, "[E] Equip [D] Drop [Q] Quit", (Vector2){ctrl_x, ctrl_y + 16}, MEDIUM_FONT, MED_CHAR_SPACE,
|
|
||||||
(Color){139, 119, 89, 255});
|
|
||||||
|
|
||||||
// INV count in top-right corner of HUD
|
// INV count in top-right corner of HUD
|
||||||
char inv_text[16];
|
char inv_text[16];
|
||||||
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
|
||||||
int inv_width = MeasureText(inv_text, 10);
|
int inv_width = MeasureText(inv_text, 10);
|
||||||
DrawTextEx(*font, inv_text, (Vector2){SCREEN_WIDTH - inv_width - 10, hud_y + 5}, 10, NAR_CHAR_SPACE, GREEN);
|
DrawText(inv_text, SCREEN_WIDTH - inv_width - 10, hud_y + 5, 10, GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_action_log(const char log[5][128], int count, int head, Font *font) {
|
void render_action_log(const char log[5][128], int count, int head) {
|
||||||
// Roguelike scroll/log panel styling
|
// Roguelike scroll/log panel styling
|
||||||
const int log_width = 250;
|
const int log_width = 250;
|
||||||
const int log_height = 90;
|
const int log_height = 90;
|
||||||
|
|
@ -326,8 +322,7 @@ void render_action_log(const char log[5][128], int count, int head, Font *font)
|
||||||
|
|
||||||
// Title bar
|
// Title bar
|
||||||
DrawRectangle(log_x + 4, log_y + 4, log_width - 8, 16, (Color){30, 25, 20, 255});
|
DrawRectangle(log_x + 4, log_y + 4, log_width - 8, 16, (Color){30, 25, 20, 255});
|
||||||
DrawTextEx(*font, "MESSAGE LOG", (Vector2){log_x + 8, log_y + 6}, MEDIUM_FONT, NAR_CHAR_SPACE,
|
DrawText("MESSAGE LOG", log_x + 8, log_y + 6, 10, (Color){180, 160, 130, 255});
|
||||||
(Color){180, 160, 130, 255});
|
|
||||||
|
|
||||||
// Separator line under title
|
// Separator line under title
|
||||||
DrawLine(log_x + 4, log_y + 22, log_x + log_width - 5, log_y + 22, log_border_dark);
|
DrawLine(log_x + 4, log_y + 22, log_x + log_width - 5, log_y + 22, log_border_dark);
|
||||||
|
|
@ -352,16 +347,15 @@ void render_action_log(const char log[5][128], int count, int head, Font *font)
|
||||||
} else {
|
} else {
|
||||||
text_color = (Color){120, 110, 100, 200}; // oldest: dim
|
text_color = (Color){120, 110, 100, 200}; // oldest: dim
|
||||||
}
|
}
|
||||||
DrawTextEx(*font, log[idx], (Vector2){text_x, text_start_y + i * line_height}, NORM_FONT, SMALL_CHAR_SPACE,
|
DrawText(log[idx], text_x, text_start_y + i * line_height, 10, text_color);
|
||||||
text_color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_inventory_overlay(const Player *p, int selected, Font *font) {
|
void render_inventory_overlay(const Player *p, int selected) {
|
||||||
// Overlay dimensions
|
// Overlay dimensions
|
||||||
int ov_width = 360;
|
int ov_width = 360;
|
||||||
int ov_height = 320;
|
int ov_height = 300;
|
||||||
Rectangle overlay = {(float)(SCREEN_WIDTH - ov_width) / 2, (float)(SCREEN_HEIGHT - ov_height) / 2 - 60,
|
Rectangle overlay = {(float)(SCREEN_WIDTH - ov_width) / 2, (float)(SCREEN_HEIGHT - ov_height) / 2 - 60,
|
||||||
(float)ov_width, (float)ov_height};
|
(float)ov_width, (float)ov_height};
|
||||||
DrawRectangleRec(overlay, (Color){12, 12, 12, 252});
|
DrawRectangleRec(overlay, (Color){12, 12, 12, 252});
|
||||||
|
|
@ -369,15 +363,13 @@ void render_inventory_overlay(const Player *p, int selected, Font *font) {
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
const char *title = "INVENTORY";
|
const char *title = "INVENTORY";
|
||||||
// int title_w = MeasureText(title, 24);
|
int title_w = MeasureText(title, 24);
|
||||||
Vector2 t_w = MeasureTextEx(*font, title, 30, NORM_CHAR_SPACE);
|
DrawText(title, overlay.x + (overlay.width - title_w) / 2, overlay.y + 12, 24, WHITE);
|
||||||
DrawTextEx(*font, title, (Vector2){overlay.x + (overlay.width - t_w.x) / 2, overlay.y + 10}, HUGE_FONT,
|
|
||||||
NORM_CHAR_SPACE, WHITE);
|
|
||||||
|
|
||||||
// Draw each inventory slot
|
// Draw each inventory slot
|
||||||
char slot_text[64];
|
char slot_text[64];
|
||||||
int row_height = 26;
|
int row_height = 26;
|
||||||
int start_y = overlay.y + 40;
|
int start_y = overlay.y + 50;
|
||||||
|
|
||||||
for (int i = 0; i < MAX_INVENTORY; i++) {
|
for (int i = 0; i < MAX_INVENTORY; i++) {
|
||||||
int y_pos = start_y + (i * row_height);
|
int y_pos = start_y + (i * row_height);
|
||||||
|
|
@ -394,8 +386,7 @@ void render_inventory_overlay(const Player *p, int selected, Font *font) {
|
||||||
|
|
||||||
// Slot number
|
// Slot number
|
||||||
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
||||||
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, MEDIUM_FONT, SMALL_CHAR_SPACE,
|
DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){80, 80, 80, 255});
|
||||||
(Color){80, 80, 80, 255});
|
|
||||||
|
|
||||||
// Item name
|
// Item name
|
||||||
const char *name = item_get_name(item);
|
const char *name = item_get_name(item);
|
||||||
|
|
@ -403,31 +394,31 @@ void render_inventory_overlay(const Player *p, int selected, Font *font) {
|
||||||
Color name_color = (item->type == ITEM_POTION) ? (Color){255, 140, 140, 255}
|
Color name_color = (item->type == ITEM_POTION) ? (Color){255, 140, 140, 255}
|
||||||
: (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255}
|
: (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255}
|
||||||
: (Color){140, 140, 255, 255};
|
: (Color){140, 140, 255, 255};
|
||||||
DrawTextEx(*font, name, (Vector2){overlay.x + 45, y_pos + 4}, NORM_FONT, SMALL_CHAR_SPACE, name_color);
|
DrawText(name, overlay.x + 45, y_pos + 4, 14, name_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Power
|
// Power
|
||||||
snprintf(slot_text, sizeof(slot_text), "+%d", item->power);
|
snprintf(slot_text, sizeof(slot_text), "+%d", item->power);
|
||||||
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 150, y_pos + 4}, NORM_FONT, SMALL_CHAR_SPACE, YELLOW);
|
DrawText(slot_text, overlay.x + 150, y_pos + 4, 14, YELLOW);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
if (item->type == ITEM_POTION) {
|
if (item->type == ITEM_POTION) {
|
||||||
DrawTextEx(*font, "[U]se", (Vector2){overlay.x + 200, y_pos + 4}, NORM_FONT, SMALL_CHAR_SPACE, GREEN);
|
DrawText("[U]se", overlay.x + 200, y_pos + 4, 14, GREEN);
|
||||||
} else {
|
} else {
|
||||||
DrawTextEx(*font, "[E]quip [D]rop", (Vector2){overlay.x + 200, y_pos + 4}, NORM_FONT, SMALL_CHAR_SPACE, GOLD);
|
DrawText("[E]quip [D]rop", overlay.x + 200, y_pos + 4, 14, GOLD);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Empty slot
|
// Empty slot
|
||||||
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
snprintf(slot_text, sizeof(slot_text), "%d.", i + 1);
|
||||||
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, MEDIUM_FONT, SMALL_CHAR_SPACE,
|
DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){40, 40, 40, 255});
|
||||||
(Color){40, 40, 40, 255});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instructions at bottom
|
// Instructions at bottom
|
||||||
const char *hint = "[1-0] Select [E] Equip [U] Use [D] Drop [I/ESC] Close";
|
const char *hint = "[1-0] Select [E] Equip [U] Use [D] Drop [I/ESC] Close";
|
||||||
Vector2 hint_w = MeasureTextEx(*font, hint, SMALL_FONT, NAR_CHAR_SPACE);
|
int hint_w = MeasureText(hint, 12);
|
||||||
DrawTextEx(*font, hint, (Vector2){overlay.x + (overlay.width - hint_w.x) / 2.0f, overlay.y + overlay.height - 22},
|
DrawText(hint, overlay.x + (overlay.width - hint_w) / 2, overlay.y + overlay.height - 22, 12,
|
||||||
SMALL_FONT, NAR_CHAR_SPACE, (Color){80, 80, 80, 255});
|
(Color){65, 65, 65, 255});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Color label_color(FloatingText *ft, int alpha) {
|
static Color label_color(FloatingText *ft, int alpha) {
|
||||||
|
|
@ -515,7 +506,7 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score, unsigned int seed, Font *font) {
|
int times_hit, int potions, int floors, int turns, int score) {
|
||||||
// Semi-transparent overlay
|
// Semi-transparent overlay
|
||||||
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
||||||
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
||||||
|
|
@ -525,14 +516,13 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
int title_font_size = 60;
|
int title_font_size = 60;
|
||||||
Color title_color = is_victory ? GOLD : RED;
|
Color title_color = is_victory ? GOLD : RED;
|
||||||
int title_width = MeasureText(title, title_font_size);
|
int title_width = MeasureText(title, title_font_size);
|
||||||
DrawTextEx(*font, title, (Vector2){(SCREEN_WIDTH - title_width) / 2.0f, 30}, title_font_size, NORM_CHAR_SPACE,
|
DrawText(title, (SCREEN_WIDTH - title_width) / 2, 30, title_font_size, title_color);
|
||||||
title_color);
|
|
||||||
|
|
||||||
// Stats box
|
// Stats box
|
||||||
int box_x = SCREEN_WIDTH / 2 - 200;
|
int box_x = SCREEN_WIDTH / 2 - 200;
|
||||||
int box_y = 110;
|
int box_y = 110;
|
||||||
int box_w = 400;
|
int box_w = 400;
|
||||||
int box_h = 350;
|
int box_h = 320;
|
||||||
DrawRectangle(box_x, box_y, box_w, box_h, (Color){20, 20, 20, 240});
|
DrawRectangle(box_x, box_y, box_w, box_h, (Color){20, 20, 20, 240});
|
||||||
DrawRectangleLines(box_x, box_y, box_w, box_h, (Color){100, 100, 100, 255});
|
DrawRectangleLines(box_x, box_y, box_w, box_h, (Color){100, 100, 100, 255});
|
||||||
|
|
||||||
|
|
@ -546,80 +536,71 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
Color value_color = WHITE;
|
Color value_color = WHITE;
|
||||||
|
|
||||||
// Column 1
|
// Column 1
|
||||||
DrawTextEx(*font, "Kills:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Kills:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", kills);
|
snprintf(line, sizeof(line), "%d", kills);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Items:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Items:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", items);
|
snprintf(line, sizeof(line), "%d", items);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Damage Dealt:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Damage Dealt:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", damage_dealt);
|
snprintf(line, sizeof(line), "%d", damage_dealt);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 140, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Damage Taken:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Damage Taken:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", damage_taken);
|
snprintf(line, sizeof(line), "%d", damage_taken);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 140, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Crits:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Crits:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", crits);
|
snprintf(line, sizeof(line), "%d", crits);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Times Hit:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Times Hit:", col1_x, row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", times_hit);
|
snprintf(line, sizeof(line), "%d", times_hit);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col1_x + 80, row_y, 18, value_color);
|
||||||
row_y += line_height;
|
row_y += line_height;
|
||||||
|
|
||||||
// Column 2
|
// Column 2
|
||||||
int col2_row_y = box_y + 20;
|
int col2_row_y = box_y + 20;
|
||||||
DrawTextEx(*font, "Potions:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Potions:", col2_x, col2_row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", potions);
|
snprintf(line, sizeof(line), "%d", potions);
|
||||||
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Floors:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Floors:", col2_x, col2_row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", floors);
|
snprintf(line, sizeof(line), "%d", floors);
|
||||||
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
DrawTextEx(*font, "Turns:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
DrawText("Turns:", col2_x, col2_row_y, 18, label_color);
|
||||||
snprintf(line, sizeof(line), "%d", turns);
|
snprintf(line, sizeof(line), "%d", turns);
|
||||||
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
|
||||||
col2_row_y += line_height;
|
col2_row_y += line_height;
|
||||||
|
|
||||||
// Score: placed below the last row of the longer column (6 items, row_y is already there)
|
// Score: placed below the last row of the longer column (6 items, row_y is already there)
|
||||||
row_y += 10;
|
row_y += 10;
|
||||||
DrawTextEx(*font, "SCORE:", (Vector2){col1_x, row_y}, 22, NORM_CHAR_SPACE, GOLD);
|
DrawText("SCORE:", col1_x, row_y, 22, GOLD);
|
||||||
snprintf(line, sizeof(line), "%d", score);
|
snprintf(line, sizeof(line), "%d", score);
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 90, col2_row_y}, 22, NORM_CHAR_SPACE, GOLD);
|
DrawText(line, col1_x + 90, row_y, 22, GOLD);
|
||||||
row_y += 35;
|
|
||||||
|
|
||||||
// Seed display
|
|
||||||
DrawTextEx(*font, "SEED:", (Vector2){col1_x, row_y}, 18, SMALL_CHAR_SPACE, label_color);
|
|
||||||
snprintf(line, sizeof(line), "%u", seed);
|
|
||||||
DrawTextEx(*font, line, (Vector2){col1_x + 60, row_y}, 18, SMALL_CHAR_SPACE, END_SEED);
|
|
||||||
|
|
||||||
// Instructions
|
|
||||||
if (is_victory) {
|
if (is_victory) {
|
||||||
const char *subtitle = "Press R to play again or Q to quit";
|
const char *subtitle = "Press R to play again or Q to quit";
|
||||||
int sub_width = MeasureText(subtitle, 20);
|
int sub_width = MeasureText(subtitle, 20);
|
||||||
DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE,
|
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
|
||||||
LIGHTGRAY);
|
|
||||||
} else {
|
} else {
|
||||||
const char *subtitle = "Press R to restart or Q to quit";
|
const char *subtitle = "Press R to restart or Q to quit";
|
||||||
int sub_width = MeasureText(subtitle, 20);
|
int sub_width = MeasureText(subtitle, 20);
|
||||||
DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE,
|
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
|
||||||
LIGHTGRAY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_message(const char *message, Font *font) {
|
void render_message(const char *message) {
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -654,8 +635,8 @@ void render_message(const char *message, Font *font) {
|
||||||
longest_line_width = current_line_width;
|
longest_line_width = current_line_width;
|
||||||
|
|
||||||
// Measure full message
|
// Measure full message
|
||||||
Vector2 total_msg_width = MeasureTextEx(*font, message, font_size, NORM_CHAR_SPACE);
|
int total_msg_width = MeasureText(message, font_size);
|
||||||
int box_width = total_msg_width.x + (padding_x * 2);
|
int box_width = total_msg_width + (padding_x * 2);
|
||||||
|
|
||||||
// If message is too long, use wrapped width
|
// If message is too long, use wrapped width
|
||||||
if (box_width > max_box_width) {
|
if (box_width > max_box_width) {
|
||||||
|
|
@ -679,7 +660,7 @@ void render_message(const char *message, Font *font) {
|
||||||
DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, (Color){180, 180, 180, 255});
|
DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, (Color){180, 180, 180, 255});
|
||||||
|
|
||||||
// Draw text centered
|
// Draw text centered
|
||||||
int text_x = (SCREEN_WIDTH - total_msg_width.x) / 2;
|
int text_x = (SCREEN_WIDTH - total_msg_width) / 2;
|
||||||
int text_y = (SCREEN_HEIGHT - font_size) / 2;
|
int text_y = (SCREEN_HEIGHT - font_size) / 2;
|
||||||
|
|
||||||
// For wrapped text, draw at box center with padding
|
// For wrapped text, draw at box center with padding
|
||||||
|
|
@ -688,20 +669,5 @@ void render_message(const char *message, Font *font) {
|
||||||
text_y = (int)box_y + padding_y;
|
text_y = (int)box_y + padding_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTextEx(*font, message, (Vector2){text_x, text_y}, font_size, NORM_CHAR_SPACE, WHITE);
|
DrawText(message, text_x, text_y, font_size, WHITE);
|
||||||
}
|
|
||||||
|
|
||||||
void render_seed_display(unsigned int seed) {
|
|
||||||
char seed_text[64];
|
|
||||||
snprintf(seed_text, sizeof(seed_text), "Seed: %u", seed);
|
|
||||||
|
|
||||||
const int font_size = 14;
|
|
||||||
int text_width = MeasureText(seed_text, font_size);
|
|
||||||
|
|
||||||
// Position at top right with padding
|
|
||||||
int x = SCREEN_WIDTH - text_width - 10;
|
|
||||||
int y = 5;
|
|
||||||
|
|
||||||
// Draw with non-obstructive dim text color
|
|
||||||
DrawText(seed_text, x, y, font_size, TEXT_DIM);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/render.h
17
src/render.h
|
|
@ -1,8 +1,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}
|
||||||
|
|
@ -69,7 +68,6 @@
|
||||||
#define END_OVERLAY (Color){0, 0, 0, 210}
|
#define END_OVERLAY (Color){0, 0, 0, 210}
|
||||||
#define END_BOX_BG (Color){20, 20, 20, 240}
|
#define END_BOX_BG (Color){20, 20, 20, 240}
|
||||||
#define END_BOX_BORDER (Color){100, 100, 100, 255}
|
#define END_BOX_BORDER (Color){100, 100, 100, 255}
|
||||||
#define END_SEED (Color){150, 200, 255, 255}
|
|
||||||
|
|
||||||
// Portrait placeholder
|
// Portrait placeholder
|
||||||
// FIXME: remove when player sprites are available
|
// FIXME: remove when player sprites are available
|
||||||
|
|
@ -88,25 +86,22 @@ void render_enemies(const Enemy *enemies, int count, const unsigned char visible
|
||||||
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]);
|
||||||
|
|
||||||
// Render UI overlay
|
// Render UI overlay
|
||||||
void render_ui(const Player *p, Font *font);
|
void render_ui(const Player *p);
|
||||||
|
|
||||||
// Render action log (bottom left corner)
|
// Render action log (bottom left corner)
|
||||||
void render_action_log(const char log[5][128], int count, int head, Font *font);
|
void render_action_log(const char log[5][128], int count, int head);
|
||||||
|
|
||||||
// Render inventory selection overlay
|
// Render inventory selection overlay
|
||||||
void render_inventory_overlay(const Player *p, int selected, Font *font);
|
void render_inventory_overlay(const Player *p, int selected);
|
||||||
|
|
||||||
// Render floating damage text
|
// Render floating damage text
|
||||||
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
|
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
|
||||||
|
|
||||||
// Render end screen (victory or death) with stats breakdown
|
// Render end screen (victory or death) with stats breakdown
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score, unsigned int seed, Font *font);
|
int times_hit, int potions, int floors, int turns, int score);
|
||||||
|
|
||||||
// Render a message popup
|
// Render a message popup
|
||||||
void render_message(const char *message, Font *font);
|
void render_message(const char *message);
|
||||||
|
|
||||||
// Render seed display at top right of screen
|
|
||||||
void render_seed_display(unsigned int seed);
|
|
||||||
|
|
||||||
#endif // RENDER_H
|
#endif // RENDER_H
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,6 @@
|
||||||
#define SCREEN_WIDTH (MAP_WIDTH * TILE_SIZE)
|
#define SCREEN_WIDTH (MAP_WIDTH * TILE_SIZE)
|
||||||
#define SCREEN_HEIGHT (MAP_HEIGHT * TILE_SIZE)
|
#define SCREEN_HEIGHT (MAP_HEIGHT * TILE_SIZE)
|
||||||
|
|
||||||
// Font constants
|
|
||||||
#define NORM_CHAR_SPACE 4.0f
|
|
||||||
#define MED_CHAR_SPACE 2.5f
|
|
||||||
#define SMALL_CHAR_SPACE 1.6f
|
|
||||||
#define NAR_CHAR_SPACE 1.0f
|
|
||||||
#define CRAMPED_CHAR_SPACE 0.5f
|
|
||||||
|
|
||||||
#define TINY_FONT 8
|
|
||||||
#define SMALL_FONT 10
|
|
||||||
#define NORM_FONT 12
|
|
||||||
#define MEDIUM_FONT 14
|
|
||||||
#define LARGE_FONT 18
|
|
||||||
#define BIG_FONT 22
|
|
||||||
#define HUGE_FONT 30
|
|
||||||
|
|
||||||
// Game Limits
|
// Game Limits
|
||||||
#define MAX_ENEMIES 64
|
#define MAX_ENEMIES 64
|
||||||
#define MAX_ITEMS 128
|
#define MAX_ITEMS 128
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue