render: (relatively) minor UI overhaul #10

Merged
NotAShelf merged 8 commits from notashelf/push-lnksylnmlvzq into main 2026-04-08 12:39:10 +00:00
6 changed files with 431 additions and 81 deletions

View file

@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void {
}),
});
combat_lib.addIncludePath(b.path("src"));
combat_lib.linkSystemLibrary("raylib");
// C sources (everything except combat, which is now Zig)
const c_sources = [_][]const u8{

84
build.zig.zon Normal file
View file

@ -0,0 +1,84 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .rogged,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.1.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x5576c549acfcf6f2,
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.15.2",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL. If the contents of a URL change this will result in a hash mismatch
// // which will prevent zig from using it.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//
// // When this is set to `true`, a package is declared to be lazily
// // fetched. This makes the dependency only get fetched if it is
// // actually used.
// .lazy = false,
//},
},
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"libs",
},
}

View file

@ -150,6 +150,16 @@ typedef struct {
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;

View file

@ -115,6 +115,7 @@ static void init_floor(GameState *gs, int floor_num) {
// Initialize player position if first floor
if (floor_num == 1) {
player_init(&gs->player, start_x, start_y);
gs->floors_reached = 1;
} else {
// Move player to new floor position
gs->player.x = start_x;
@ -190,7 +191,8 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
audio_play_dodge(gs);
} else {
if (combat_get_last_damage() > 0)
spawn_floating_text(gs, ex, ey, combat_get_last_damage(), combat_was_critical());
gs->damage_dealt += combat_get_last_damage();
spawn_floating_text(gs, ex, ey, combat_get_last_damage(), combat_was_critical());
audio_play_attack(gs);
if (combat_was_blocked()) {
spawn_floating_label(gs, ex, ey - 10, "BLOCK", EFFECT_NONE);
@ -199,6 +201,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
if (combat_was_critical()) {
spawn_floating_label(gs, ex + 8, ey - 10, "CRIT!", EFFECT_NONE);
audio_play_crit(gs);
gs->crits_landed++;
}
StatusEffectType applied = combat_get_applied_effect();
if (applied != EFFECT_NONE) {
@ -208,6 +211,7 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
if (!attacked_enemy->alive) {
spawn_floating_label(gs, ex, ey - 20, "SLAIN", EFFECT_NONE);
audio_play_enemy_death(gs);
gs->total_kills++;
}
}
}
@ -219,6 +223,8 @@ static void post_action(GameState *gs, Enemy *attacked_enemy) {
if (combat_was_player_damage() && combat_get_last_damage() > 0) {
audio_play_player_damage(gs);
gs->screen_shake = 8;
gs->damage_taken += combat_get_last_damage();
gs->times_hit++;
spawn_floating_text(gs, gs->player.x * TILE_SIZE + 8, gs->player.y * TILE_SIZE, combat_get_last_damage(),
combat_was_critical());
}
@ -309,6 +315,7 @@ static int handle_inventory_input(GameState *gs) {
if (item != NULL) {
if (item->type == ITEM_POTION) {
player_use_item(&gs->player, item);
gs->potions_used++;
player_remove_inventory_item(&gs->player, gs->inv_selected);
gs->last_message = "Used potion!";
gs->message_timer = 60;
@ -350,6 +357,8 @@ static int handle_descend_input(GameState *gs) {
if (IsKeyPressed(KEY_Y)) {
if (gs->player.floor < NUM_FLOORS) {
audio_play_stairs(gs);
if (gs->player.floor + 1 > gs->floors_reached)
gs->floors_reached = gs->player.floor + 1;
init_floor(gs, gs->player.floor + 1);
gs->last_message = "Descended to next floor!";
gs->message_timer = 60;
@ -383,6 +392,7 @@ static int handle_movement_input(GameState *gs) {
Item *item = get_item_at_floor(gs->items, gs->item_count, gs->player.x, gs->player.y);
if (item != NULL) {
if (player_pickup(&gs->player, item)) {
gs->items_collected++;
char pickup_msg[64];
snprintf(pickup_msg, sizeof(pickup_msg), "Picked up %s", item_get_name(item));
add_log(gs, pickup_msg);
@ -400,6 +410,7 @@ static int handle_movement_input(GameState *gs) {
// Check for item usage (U key - use first potion)
if (IsKeyPressed(KEY_U)) {
if (gs->player.inventory_count > 0 && player_use_first_item(&gs->player)) {
gs->potions_used++;
gs->last_message = "Used potion!";
gs->message_timer = 60;
audio_play_item_pickup(gs);
@ -509,6 +520,7 @@ static void game_loop(void) {
memset(&gs, 0, sizeof(GameState));
gs.game_over = 0;
gs.game_won = 0;
load_audio_assets(&gs);
init_floor(&gs, 1);
}
}
@ -554,13 +566,15 @@ static void game_loop(void) {
// Draw game over screen
if (gs.game_over) {
render_game_over();
// Compute final score
gs.final_score = gs.total_kills * 100 + gs.items_collected * 30 + gs.floors_reached * 200 + gs.crits_landed * 25 +
gs.damage_dealt * 2 - gs.damage_taken * 2 - gs.times_hit * 15;
if (gs.game_won) {
// Draw win message
const char *win_msg = "YOU WIN! ESCAPED THE DUNGEON!";
int msg_w = MeasureText(win_msg, 30);
DrawText(win_msg, (SCREEN_WIDTH - msg_w) / 2, SCREEN_HEIGHT / 2 - 80, 30, GOLD);
gs.final_score = (gs.final_score * 3) / 2;
}
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.final_score);
}
EndDrawing();

View file

@ -109,27 +109,58 @@ void render_items(const Item *items, int count) {
}
void render_ui(const Player *p) {
// UI background bar (taller for two rows)
Rectangle ui_bg = {0, (float)(MAP_HEIGHT * TILE_SIZE), (float)SCREEN_WIDTH, 60};
DrawRectangleRec(ui_bg, (Color){15, 15, 15, 255});
// HUD Panel
const int hud_y = MAP_HEIGHT * TILE_SIZE;
const int hud_height = 60;
const Color hud_bg = {25, 20, 15, 255}; // dark parchment
const Color hud_border = {139, 119, 89, 255}; // bronze/brown border
const Color text_dim = {160, 150, 140, 255}; // dimmed text
const Color text_bright = {240, 230, 220, 255}; // bright text
// Draw dividing line
DrawLine(0, MAP_HEIGHT * TILE_SIZE, SCREEN_WIDTH, MAP_HEIGHT * TILE_SIZE, (Color){50, 50, 50, 255});
// Main HUD background with border
Rectangle ui_bg = {0, (float)hud_y, (float)SCREEN_WIDTH, (float)hud_height};
DrawRectangleRec(ui_bg, hud_bg);
DrawRectangleLines(0, hud_y, SCREEN_WIDTH, hud_height, hud_border);
DrawLine(0, hud_y + 1, SCREEN_WIDTH, hud_y + 1, (Color){60, 55, 50, 255});
DrawLine(0, hud_y + hud_height - 2, SCREEN_WIDTH, hud_y + hud_height - 2, (Color){15, 12, 10, 255});
// HP Bar (row 1, left)
int bar_x = 10;
int bar_y = MAP_HEIGHT * TILE_SIZE + 10;
int bar_width = 140;
int bar_height = 18;
// Section dividers
int section1_end = 180; // after portrait + HP bar
int section2_end = 310; // after stats
int section3_end = 480; // after equipment
// Bar background
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){30, 30, 30, 255});
DrawLine(section1_end, hud_y + 5, section1_end, hud_y + hud_height - 5, (Color){60, 55, 50, 255});
DrawLine(section1_end + 1, hud_y + 5, section1_end + 1, hud_y + hud_height - 5, (Color){15, 12, 10, 255});
// Bar fill based on HP percentage
DrawLine(section2_end, hud_y + 5, section2_end, hud_y + hud_height - 5, (Color){60, 55, 50, 255});
DrawLine(section2_end + 1, hud_y + 5, section2_end + 1, hud_y + hud_height - 5, (Color){15, 12, 10, 255});
int portrait_x = 8;
int portrait_y = hud_y + 8;
int portrait_size = 44;
// FIXME: for now this is just a blue square indicating the player. Once we
// model the player, add classes, sprites, etc. this will need to be revisited.
DrawRectangle(portrait_x, portrait_y, portrait_size, portrait_size, (Color){30, 30, 45, 255});
DrawRectangle(portrait_x + 2, portrait_y + 2, portrait_size - 4, portrait_size - 4, BLUE);
DrawRectangleLines(portrait_x, portrait_y, portrait_size, portrait_size, (Color){139, 119, 89, 255});
// HP Bar, to the right of portrait
int bar_x = portrait_x + portrait_size + 8;
int bar_y = hud_y + 20;
int bar_width = 100;
int bar_height = 16;
// HP Label, above bar
DrawText("HP", bar_x, bar_y - 11, 9, text_dim);
// HP Bar background
DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255});
DrawRectangleLines(bar_x, bar_y, bar_width, bar_height, (Color){80, 70, 60, 255});
// HP Bar fill
float hp_percent = (float)p->hp / p->max_hp;
int fill_width = (int)(bar_width * hp_percent);
// Color gradient: green > yellow > red
Color hp_color;
if (hp_percent > 0.6f) {
hp_color = (Color){60, 180, 60, 255};
@ -138,16 +169,20 @@ void render_ui(const Player *p) {
} else {
hp_color = (Color){200, 60, 60, 255};
}
DrawRectangle(bar_x, bar_y, fill_width, bar_height, hp_color);
// HP text inside bar
if (fill_width > 0) {
DrawRectangle(bar_x + 1, bar_y + 1, fill_width - 2, bar_height - 2, hp_color);
}
// HP text, centered in bar
char hp_text[32];
snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp);
int hp_text_w = MeasureText(hp_text, 14);
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 14, WHITE);
int hp_text_w = MeasureText(hp_text, 10);
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 10, WHITE);
// Status effect indicators next to HP bar
int effect_x = bar_x + bar_width + 5;
// Status effects
int effect_x = bar_x;
int effect_y = bar_y + bar_height + 5;
for (int i = 0; i < p->effect_count && i < MAX_EFFECTS; i++) {
Color eff_color;
const char *eff_label = "";
@ -178,52 +213,124 @@ void render_ui(const Player *p) {
if (p->effects[i].duration > 0) {
char eff_text[16];
snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration);
DrawText(eff_text, effect_x, bar_y, 12, eff_color);
effect_x += 40;
DrawText(eff_text, effect_x, effect_y, 9, eff_color);
effect_x += 28;
}
}
// Stats row 1: Floor, ATK, DEF, Inv
int stats_x_start = (effect_x > bar_x + bar_width + 15) ? effect_x + 10 : bar_x + bar_width + 15;
int stats_y = bar_y;
DrawText("F1", stats_x_start, stats_y, 14, WHITE);
DrawText("ATK", stats_x_start + 35, stats_y, 14, YELLOW);
DrawText("DEF", stats_x_start + 85, stats_y, 14, BLUE);
DrawText("INV", stats_x_start + 130, stats_y, 14, GREEN);
int stats_x = section1_end + 15;
int stats_y = hud_y + 12;
int stat_spacing = 40;
// Row 2: equipment slots and controls
int row2_y = stats_y + 24;
// Floor
char floor_text[16];
snprintf(floor_text, sizeof(floor_text), "F%d", p->floor);
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
// Equipment (left side of row 2)
// ATK
char atk_text[16];
snprintf(atk_text, sizeof(atk_text), "%d", p->attack);
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
// DEF
char def_text[16];
snprintf(def_text, sizeof(def_text), "%d", p->defense);
DrawText(def_text, stats_x + stat_spacing * 2, stats_y, 14, (Color){100, 150, 255, 255});
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
int equip_x = section2_end + 15;
int equip_y = hud_y + 8;
// Weapon slot
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
if (p->has_weapon) {
char weapon_text[64];
snprintf(weapon_text, sizeof(weapon_text), "Wpn:%s +%d [%s]", item_get_name(&p->equipped_weapon),
p->equipped_weapon.power, dmg_class_get_short(p->equipped_weapon.dmg_class));
DrawText(weapon_text, 10, row2_y, 12, YELLOW);
const char *weapon_name = item_get_name(&p->equipped_weapon);
if (weapon_name) {
char weapon_text[64];
snprintf(weapon_text, sizeof(weapon_text), "%s +%d [%s]", weapon_name, p->equipped_weapon.power,
dmg_class_get_short(p->equipped_weapon.dmg_class));
DrawText(weapon_text, equip_x, equip_y + 11, 10, (Color){255, 220, 100, 255});
}
} else {
DrawText("Wpn:--- [IMP]", 10, row2_y, 12, (Color){60, 60, 60, 255});
DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255});
}
// Armor slot
DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim);
if (p->has_armor) {
char armor_text[48];
snprintf(armor_text, sizeof(armor_text), "Arm:%s +%d", item_get_name(&p->equipped_armor), p->equipped_armor.power);
DrawText(armor_text, 150, row2_y, 12, BLUE);
const char *armor_name = item_get_name(&p->equipped_armor);
if (armor_name) {
char armor_text[48];
snprintf(armor_text, sizeof(armor_text), "%s +%d", armor_name, p->equipped_armor.power);
DrawText(armor_text, equip_x, equip_y + 37, 10, (Color){100, 150, 255, 255});
}
} else {
DrawText("Arm:---", 150, row2_y, 12, (Color){60, 60, 60, 255});
DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255});
}
// Controls hint (right side)
DrawText("[G] Pickup [I] Inventory [E] Equip [D] Drop", 350, row2_y, 12, (Color){70, 70, 70, 255});
int ctrl_x = section3_end + 20;
int ctrl_y = hud_y + 14;
DrawText("[WASD] Move [G] Pickup [I] Inventory [U] Use", ctrl_x, ctrl_y, 11, (Color){139, 119, 89, 255});
DrawText("[E] Equip [D] Drop [Q] Quit", ctrl_x, ctrl_y + 16, 11, (Color){139, 119, 89, 255});
// INV count in top-right corner of HUD
char inv_text[16];
snprintf(inv_text, sizeof(inv_text), "INV: %d/%d", p->inventory_count, MAX_INVENTORY);
int inv_width = MeasureText(inv_text, 10);
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) {
int log_x = 10;
int log_y = MAP_HEIGHT * TILE_SIZE - 75;
// Roguelike scroll/log panel styling
const int log_width = 250;
const int log_height = 90;
const int log_x = 2;
const int log_y = MAP_HEIGHT * TILE_SIZE - log_height - 5;
const Color log_bg = {15, 12, 10, 230}; // dark parchment
const Color log_border = {100, 85, 65, 255}; // bronze border
const Color log_border_dark = {60, 50, 40, 255}; // shadow
// Background panel with border
Rectangle log_rect = {(float)log_x, (float)log_y, (float)log_width, (float)log_height};
DrawRectangleRec(log_rect, log_bg);
DrawRectangleLines(log_x, log_y, log_width, log_height, log_border);
// Inner shadow line
DrawLine(log_x + 1, log_y + log_height - 1, log_x + log_width - 1, log_y + log_height - 1, log_border_dark);
DrawLine(log_x + log_width - 1, log_y + 1, log_x + log_width - 1, log_y + log_height - 1, log_border_dark);
// Title bar
DrawRectangle(log_x + 4, log_y + 4, log_width - 8, 16, (Color){30, 25, 20, 255});
DrawText("MESSAGE LOG", log_x + 8, log_y + 6, 10, (Color){180, 160, 130, 255});
// Separator line under title
DrawLine(log_x + 4, log_y + 22, log_x + log_width - 5, log_y + 22, log_border_dark);
// Log entries
int text_x = log_x + 8;
int text_start_y = log_y + 28;
int line_height = 12;
for (int i = 0; i < count && i < 5; i++) {
int idx = (head - count + i + 5) % 5;
if (log[idx][0] != '\0') {
DrawText(log[idx], log_x, log_y + i * 14, 12, (Color){140, 140, 140, 255});
// Fade older messages
int age = count - i - 1;
Color text_color;
if (age == 0) {
text_color = (Color){220, 210, 200, 255}; // newest: bright
} else if (age == 1) {
text_color = (Color){180, 170, 160, 255}; // recent
} else if (age == 2) {
text_color = (Color){150, 140, 130, 230}; // older
} else {
text_color = (Color){120, 110, 100, 200}; // oldest: dim
}
DrawText(log[idx], text_x, text_start_y + i * line_height, 10, text_color);
}
}
}
@ -336,7 +443,8 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
if (texts[i].label[0] != '\0') {
// Label text (DODGE, BLOCK, CRIT!, proc name, SLAIN)
int font_size = (texts[i].label[0] == 'C') ? 16 : 14; // CRIT! slightly larger
// Check for "CRIT!" specifically rather than just 'C' prefix
int font_size = (strcmp(texts[i].label, "CRIT!") == 0) ? 16 : 14;
Color color = label_color(&texts[i], a);
int text_w = MeasureText(texts[i].label, font_size);
DrawText(texts[i].label, x - text_w / 2, y, font_size, color);
@ -351,37 +459,169 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
}
}
void render_game_over(void) {
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) {
// Semi-transparent overlay
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
// Game over text
const char *title = "GAME OVER";
int title_width = MeasureText(title, 60);
DrawText(title, (SCREEN_WIDTH - title_width) / 2, SCREEN_HEIGHT / 2 - 30, 60, RED);
// Title
const char *title = is_victory ? "YOU ESCAPED!" : "GAME OVER";
int title_font_size = 60;
Color title_color = is_victory ? GOLD : RED;
int title_width = MeasureText(title, title_font_size);
DrawText(title, (SCREEN_WIDTH - title_width) / 2, 30, title_font_size, title_color);
const char *subtitle = "Press R to restart or Q to quit";
int sub_width = MeasureText(subtitle, 20);
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT / 2 + 40, 20, WHITE);
// Stats box
int box_x = SCREEN_WIDTH / 2 - 200;
int box_y = 110;
int box_w = 400;
int box_h = 320;
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});
// Stats content
char line[64];
int col1_x = box_x + 20;
int col2_x = box_x + 210;
int row_y = box_y + 20;
int line_height = 24;
Color label_color = LIGHTGRAY;
Color value_color = WHITE;
// Column 1
DrawText("Kills:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", kills);
DrawText(line, col1_x + 80, row_y, 18, value_color);
row_y += line_height;
DrawText("Items:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", items);
DrawText(line, col1_x + 80, row_y, 18, value_color);
row_y += line_height;
DrawText("Damage Dealt:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", damage_dealt);
DrawText(line, col1_x + 140, row_y, 18, value_color);
row_y += line_height;
DrawText("Damage Taken:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", damage_taken);
DrawText(line, col1_x + 140, row_y, 18, value_color);
row_y += line_height;
DrawText("Crits:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", crits);
DrawText(line, col1_x + 80, row_y, 18, value_color);
row_y += line_height;
DrawText("Times Hit:", col1_x, row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", times_hit);
DrawText(line, col1_x + 80, row_y, 18, value_color);
row_y += line_height;
// Column 2
int col2_row_y = box_y + 20;
DrawText("Potions:", col2_x, col2_row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", potions);
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
col2_row_y += line_height;
DrawText("Floors:", col2_x, col2_row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", floors);
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
col2_row_y += line_height;
DrawText("Turns:", col2_x, col2_row_y, 18, label_color);
snprintf(line, sizeof(line), "%d", turns);
DrawText(line, col2_x + 80, col2_row_y, 18, value_color);
col2_row_y += line_height;
// Score: placed below the last row of the longer column (6 items, row_y is already there)
row_y += 10;
DrawText("SCORE:", col1_x, row_y, 22, GOLD);
snprintf(line, sizeof(line), "%d", score);
DrawText(line, col1_x + 90, row_y, 22, GOLD);
if (is_victory) {
const char *subtitle = "Press R to play again or Q to quit";
int sub_width = MeasureText(subtitle, 20);
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
} else {
const char *subtitle = "Press R to restart or Q to quit";
int sub_width = MeasureText(subtitle, 20);
DrawText(subtitle, (SCREEN_WIDTH - sub_width) / 2, SCREEN_HEIGHT - 50, 20, LIGHTGRAY);
}
}
void render_message(const char *message) {
if (message == NULL)
return;
int msg_len = strlen(message);
float msg_ratio = 13.5;
const int font_size = 20;
const int line_height = font_size + 4;
const int padding_x = 20;
const int padding_y = 15;
const int max_box_width = (int)(SCREEN_WIDTH * 0.75f);
const int max_line_width = max_box_width - (padding_x * 2);
// Draw message box
// TODO: Separate out the calculation of the x/y and width/height so that if a message takes up more than, say,
// 75% of the screen width, we add a line break and increase the height. That would then require calculating the
// width based on the longest line.
Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2.0f - ((msg_ratio / 2.03f) * msg_len)),
(float)(SCREEN_HEIGHT / 2.0f - 30.0f), msg_ratio * msg_len, 60};
// Calculate line breaks by iterating through message
int line_count = 1;
int current_line_width = 0;
int longest_line_width = 0;
const char *msg_ptr = message;
while (*msg_ptr && line_count <= 10) {
// Estimate character width (average ~10px for 20pt font)
int char_width = 10;
current_line_width += char_width;
if (current_line_width > max_line_width && *msg_ptr == ' ') {
if (current_line_width > longest_line_width)
longest_line_width = current_line_width;
line_count++;
current_line_width = 0;
}
msg_ptr++;
}
if (current_line_width > longest_line_width)
longest_line_width = current_line_width;
// Measure full message
int total_msg_width = MeasureText(message, font_size);
int box_width = total_msg_width + (padding_x * 2);
// If message is too long, use wrapped width
if (box_width > max_box_width) {
box_width = max_box_width;
}
// Ensure minimum width
if (box_width < 200)
box_width = 200;
// Calculate box height based on line count
int box_height = (line_count * line_height) + (padding_y * 2);
// Center the box
float box_x = (SCREEN_WIDTH - box_width) / 2.0f;
float box_y = (SCREEN_HEIGHT - box_height) / 2.0f;
// Draw message box background
Rectangle msg_bg = {box_x, box_y, (float)box_width, (float)box_height};
DrawRectangleRec(msg_bg, (Color){45, 45, 45, 235});
DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, (Color){180, 180, 180, 255});
int msg_width = MeasureText(message, 20);
DrawText(message, (SCREEN_WIDTH - msg_width) / 2, SCREEN_HEIGHT / 2 - 10, 20, WHITE);
// Draw text centered
int text_x = (SCREEN_WIDTH - total_msg_width) / 2;
int text_y = (SCREEN_HEIGHT - font_size) / 2;
// For wrapped text, draw at box center with padding
if (line_count > 1) {
text_x = (int)box_x + padding_x;
text_y = (int)box_y + padding_y;
}
DrawText(message, text_x, text_y, font_size, WHITE);
}

View file

@ -27,8 +27,9 @@ void render_inventory_overlay(const Player *p, int selected);
// Render floating damage text
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y);
// Render game over screen
void render_game_over(void);
// 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,
int times_hit, int potions, int floors, int turns, int score);
// Render a message popup
void render_message(const char *message);