From 64205e137c8e390f309b59c06f97cbdfd722adb0 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Thu, 9 Apr 2026 12:13:00 -0400 Subject: [PATCH] font: fully implemented font changes to UI, size/spacing need tweaking --- src/main.c | 8 ++-- src/render.c | 127 +++++++++++++++++++++++++------------------------ src/render.h | 8 ++-- src/settings.h | 4 ++ 4 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/main.c b/src/main.c index c96a3ab..030fa6d 100644 --- a/src/main.c +++ b/src/main.c @@ -564,16 +564,16 @@ static void game_loop(void) { render_ui(&gs.player, &fontTTF); // Draw action log - render_action_log(gs.action_log, gs.log_count, gs.log_head); + render_action_log(gs.action_log, gs.log_count, gs.log_head, &fontTTF); // Draw inventory overlay if active if (gs.show_inventory) { - render_inventory_overlay(&gs.player, gs.inv_selected); + render_inventory_overlay(&gs.player, gs.inv_selected, &fontTTF); } // Draw message if any if (gs.last_message != NULL && gs.message_timer > 0) { - render_message(gs.last_message); + render_message(gs.last_message, &fontTTF); } // Draw game over screen @@ -586,7 +586,7 @@ static void game_loop(void) { } 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); + gs.final_score, &fontTTF); } EndDrawing(); diff --git a/src/render.c b/src/render.c index 206e23a..9d5571f 100644 --- a/src/render.c +++ b/src/render.c @@ -110,8 +110,6 @@ void render_items(const Item *items, int count) { } void render_ui(const Player *p, Font *font) { - float nar_space = 1.0; - float norm_space = 4.0; // HUD Panel const int hud_y = MAP_HEIGHT * TILE_SIZE; const int hud_height = 60; @@ -155,7 +153,7 @@ void render_ui(const Player *p, Font *font) { int bar_height = 16; // HP Label, above bar - DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 11}, 14, nar_space, text_dim); + DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 11}, 14, NAR_CHAR_SPACE, text_dim); // HP Bar background DrawRectangle(bar_x, bar_y, bar_width, bar_height, (Color){20, 15, 15, 255}); @@ -181,7 +179,7 @@ void render_ui(const Player *p, Font *font) { char hp_text[32]; snprintf(hp_text, sizeof(hp_text), "%d/%d", p->hp, p->max_hp); int hp_text_w = MeasureText(hp_text, 12); - DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, 12, nar_space, WHITE); + DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, 12, NAR_CHAR_SPACE, WHITE); // Status effects int effect_x = bar_x; @@ -216,7 +214,7 @@ void render_ui(const Player *p, Font *font) { if (p->effects[i].duration > 0) { char eff_text[16]; snprintf(eff_text, sizeof(eff_text), "%s%d", eff_label, p->effects[i].duration); - DrawTextEx(*font, eff_text, (Vector2){effect_x, effect_y}, 9, nar_space, eff_color); + DrawTextEx(*font, eff_text, (Vector2){effect_x, effect_y}, 9, NAR_CHAR_SPACE, eff_color); effect_x += 28; } } @@ -228,66 +226,68 @@ void render_ui(const Player *p, Font *font) { // Floor char floor_text[16]; snprintf(floor_text, sizeof(floor_text), "F%d", p->floor); - DrawTextEx(*font, floor_text, (Vector2){stats_x, stats_y}, 16, norm_space, text_bright); - DrawTextEx(*font, "Floor", (Vector2){stats_x, stats_y + 16}, 12, nar_space, text_dim); + DrawTextEx(*font, floor_text, (Vector2){stats_x, stats_y}, 16, NORM_CHAR_SPACE, text_bright); + DrawTextEx(*font, "Floor", (Vector2){stats_x, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim); // ATK char atk_text[16]; snprintf(atk_text, sizeof(atk_text), "%d", p->attack); - DrawTextEx(*font, atk_text, (Vector2){stats_x + stat_spacing, stats_y}, 16, norm_space, YELLOW); - DrawTextEx(*font, "ATK", (Vector2){stats_x + stat_spacing, stats_y + 16}, 12, nar_space, text_dim); + DrawTextEx(*font, atk_text, (Vector2){stats_x + stat_spacing, stats_y}, 16, NORM_CHAR_SPACE, YELLOW); + DrawTextEx(*font, "ATK", (Vector2){stats_x + stat_spacing, stats_y + 16}, 12, NAR_CHAR_SPACE, text_dim); // DEF char def_text[16]; snprintf(def_text, sizeof(def_text), "%d", p->defense); - DrawTextEx(*font, def_text, (Vector2){stats_x + stat_spacing * 2, stats_y}, 16, norm_space, + DrawTextEx(*font, def_text, (Vector2){stats_x + stat_spacing * 2, stats_y}, 16, NORM_CHAR_SPACE, (Color){100, 150, 255, 255}); - DrawTextEx(*font, "DEF", (Vector2){stats_x + stat_spacing * 2, stats_y + 16}, 12, nar_space, 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_y = hud_y + 8; // Weapon slot - DrawTextEx(*font, "WEAPON", (Vector2){equip_x, equip_y}, 12, nar_space, text_dim); + DrawTextEx(*font, "WEAPON", (Vector2){equip_x, equip_y}, 12, NAR_CHAR_SPACE, text_dim); if (p->has_weapon) { 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}); + DrawTextEx(*font, weapon_text, (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){255, 220, 100, 255}); } } else { - DrawText("None [IMP]", equip_x, equip_y + 11, 10, (Color){80, 75, 70, 255}); + DrawTextEx(*font, "None [IMP]", (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255}); } // Armor slot - DrawText("ARMOR", equip_x, equip_y + 26, 9, text_dim); + DrawTextEx(*font, "ARMOR", (Vector2){equip_x, equip_y + 26}, 9, NAR_CHAR_SPACE, text_dim); if (p->has_armor) { 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}); + DrawTextEx(*font, armor_text, (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){100, 150, 255, 255}); } } else { - DrawText("None", equip_x, equip_y + 37, 10, (Color){80, 75, 70, 255}); + DrawTextEx(*font, "None", (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){80, 75, 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}); + DrawTextEx(*font, "[WASD] Move [G] Pickup [I] Inventory [U] Use", (Vector2){ctrl_x, ctrl_y}, 11, + NORM_CHAR_SPACE, (Color){139, 119, 89, 255}); + DrawTextEx(*font, "[E] Equip [D] Drop [Q] Quit", (Vector2){ctrl_x, ctrl_y + 16}, 11, NORM_CHAR_SPACE, + (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); + DrawTextEx(*font, inv_text, (Vector2){SCREEN_WIDTH - inv_width - 10, hud_y + 5}, 10, NAR_CHAR_SPACE, GREEN); } -void render_action_log(const char log[5][128], int count, int head) { +void render_action_log(const char log[5][128], int count, int head, Font *font) { // Roguelike scroll/log panel styling const int log_width = 250; const int log_height = 90; @@ -309,7 +309,7 @@ void render_action_log(const char log[5][128], int count, int head) { // 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}); + DrawTextEx(*font, "MESSAGE LOG", (Vector2){log_x + 8, log_y + 6}, 10, NAR_CHAR_SPACE, (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); @@ -334,12 +334,12 @@ void render_action_log(const char log[5][128], int count, int head) { } else { text_color = (Color){120, 110, 100, 200}; // oldest: dim } - DrawText(log[idx], text_x, text_start_y + i * line_height, 10, text_color); + DrawTextEx(*font, log[idx], (Vector2){text_x, text_start_y + i * line_height}, 10, NAR_CHAR_SPACE, text_color); } } } -void render_inventory_overlay(const Player *p, int selected) { +void render_inventory_overlay(const Player *p, int selected, Font *font) { // Overlay dimensions int ov_width = 360; int ov_height = 300; @@ -351,7 +351,8 @@ void render_inventory_overlay(const Player *p, int selected) { // Title const char *title = "INVENTORY"; int title_w = MeasureText(title, 24); - DrawText(title, overlay.x + (overlay.width - title_w) / 2, overlay.y + 12, 24, WHITE); + DrawTextEx(*font, title, (Vector2){overlay.x + (overlay.width - title_w) / 2, overlay.y + 12}, 24, NORM_CHAR_SPACE, + WHITE); // Draw each inventory slot char slot_text[64]; @@ -373,39 +374,38 @@ void render_inventory_overlay(const Player *p, int selected) { // Slot number snprintf(slot_text, sizeof(slot_text), "%d.", i + 1); - DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){80, 80, 80, 255}); + DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, 14, NORM_CHAR_SPACE, (Color){80, 80, 80, 255}); // Item name const char *name = item_get_name(item); if (name) { Color name_color = (item->type == ITEM_POTION) ? (Color){255, 140, 140, 255} - : (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255} - : (Color){140, 140, 255, 255}; - DrawText(name, overlay.x + 45, y_pos + 4, 14, name_color); + : (item->type == ITEM_WEAPON) ? (Color){255, 255, 140, 255} + : (Color){140, 140, 255, 255}; + DrawTextEx(*font, name, (Vector2){overlay.x + 45, y_pos + 4}, 14, NORM_CHAR_SPACE, name_color); } - // Power snprintf(slot_text, sizeof(slot_text), "+%d", item->power); - DrawText(slot_text, overlay.x + 150, y_pos + 4, 14, YELLOW); + DrawTextEx(*font, slot_text, (Vector2){overlay.x + 150, y_pos + 4}, 14, NORM_CHAR_SPACE, YELLOW); // Action if (item->type == ITEM_POTION) { - DrawText("[U]se", overlay.x + 200, y_pos + 4, 14, GREEN); + DrawTextEx(*font, "[U]se", (Vector2){overlay.x + 200, y_pos + 4}, 14, NORM_CHAR_SPACE, GREEN); } else { - DrawText("[E]quip [D]rop", overlay.x + 200, y_pos + 4, 14, GOLD); + DrawTextEx(*font, "[E]quip [D]rop", (Vector2){overlay.x + 200, y_pos + 4}, 14, NORM_CHAR_SPACE, GOLD); } } else { // Empty slot snprintf(slot_text, sizeof(slot_text), "%d.", i + 1); - DrawText(slot_text, overlay.x + 16, y_pos + 4, 14, (Color){40, 40, 40, 255}); + DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, 14, NORM_CHAR_SPACE, (Color){40, 40, 40, 255}); } } // Instructions at bottom const char *hint = "[1-0] Select [E] Equip [U] Use [D] Drop [I/ESC] Close"; int hint_w = MeasureText(hint, 12); - DrawText(hint, overlay.x + (overlay.width - hint_w) / 2, overlay.y + overlay.height - 22, 12, - (Color){65, 65, 65, 255}); + DrawTextEx(*font, hint, (Vector2){overlay.x + (overlay.width - hint_w) / 2, overlay.y + overlay.height - 22}, 12, + NORM_CHAR_SPACE, (Color){65, 65, 65, 255}); } static Color label_color(FloatingText *ft, int alpha) { @@ -493,7 +493,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, - int times_hit, int potions, int floors, int turns, int score) { + int times_hit, int potions, int floors, int turns, int score, Font *font) { // Semi-transparent overlay Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT}; DrawRectangleRec(overlay, (Color){0, 0, 0, 210}); @@ -503,7 +503,8 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i 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); + DrawTextEx(*font, title, (Vector2){(SCREEN_WIDTH - title_width) / 2.0f, 30}, title_font_size, NORM_CHAR_SPACE, + title_color); // Stats box int box_x = SCREEN_WIDTH / 2 - 200; @@ -523,71 +524,73 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i Color value_color = WHITE; // Column 1 - DrawText("Kills:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Kills:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", kills); - DrawText(line, col1_x + 80, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color); row_y += line_height; - DrawText("Items:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Items:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", items); - DrawText(line, col1_x + 80, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color); row_y += line_height; - DrawText("Damage Dealt:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Damage Dealt:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", damage_dealt); - DrawText(line, col1_x + 140, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color); row_y += line_height; - DrawText("Damage Taken:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Damage Taken:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", damage_taken); - DrawText(line, col1_x + 140, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color); row_y += line_height; - DrawText("Crits:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Crits:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", crits); - DrawText(line, col1_x + 80, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color); row_y += line_height; - DrawText("Times Hit:", col1_x, row_y, 18, label_color); + DrawTextEx(*font, "Times Hit:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", times_hit); - DrawText(line, col1_x + 80, row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, 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); + DrawTextEx(*font, "Potions:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", potions); - DrawText(line, col2_x + 80, col2_row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color); col2_row_y += line_height; - DrawText("Floors:", col2_x, col2_row_y, 18, label_color); + DrawTextEx(*font, "Floors:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", floors); - DrawText(line, col2_x + 80, col2_row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color); col2_row_y += line_height; - DrawText("Turns:", col2_x, col2_row_y, 18, label_color); + DrawTextEx(*font, "Turns:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color); snprintf(line, sizeof(line), "%d", turns); - DrawText(line, col2_x + 80, col2_row_y, 18, value_color); + DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, 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); + DrawTextEx(*font, "SCORE:", (Vector2){col1_x, row_y}, 22, NORM_CHAR_SPACE, GOLD); snprintf(line, sizeof(line), "%d", score); - DrawText(line, col1_x + 90, row_y, 22, GOLD); + DrawTextEx(*font, line, (Vector2){col1_x + 90, col2_row_y}, 22, NORM_CHAR_SPACE, 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); + DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE, + 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); + DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE, + LIGHTGRAY); } } -void render_message(const char *message) { +void render_message(const char *message, Font *font) { if (message == NULL) return; @@ -656,5 +659,5 @@ void render_message(const char *message) { text_y = (int)box_y + padding_y; } - DrawText(message, text_x, text_y, font_size, WHITE); + DrawTextEx(*font, message, (Vector2){text_x, text_y}, font_size, NORM_CHAR_SPACE, WHITE); } diff --git a/src/render.h b/src/render.h index 19939a8..7f662ee 100644 --- a/src/render.h +++ b/src/render.h @@ -89,19 +89,19 @@ void render_items(const Item *items, int count); void render_ui(const Player *p, Font *font); // Render action log (bottom left corner) -void render_action_log(const char log[5][128], int count, int head); +void render_action_log(const char log[5][128], int count, int head, Font *font); // Render inventory selection overlay -void render_inventory_overlay(const Player *p, int selected); +void render_inventory_overlay(const Player *p, int selected, Font *font); // Render floating damage text void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y); // 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); + int times_hit, int potions, int floors, int turns, int score, Font *font); // Render a message popup -void render_message(const char *message); +void render_message(const char *message, Font *font); #endif // RENDER_H diff --git a/src/settings.h b/src/settings.h index 8b8ac54..6d6a2c5 100644 --- a/src/settings.h +++ b/src/settings.h @@ -8,6 +8,10 @@ #define SCREEN_WIDTH (MAP_WIDTH * TILE_SIZE) #define SCREEN_HEIGHT (MAP_HEIGHT * TILE_SIZE) +// Font constants +#define NORM_CHAR_SPACE 4.0f +#define NAR_CHAR_SPACE 1.0f + // Game Limits #define MAX_ENEMIES 64 #define MAX_ITEMS 128