forked from NotAShelf/rogged
Squashed commit of the following:
commit a53942249c82ae8c17bd2f89271430b16a0f9412
Author: A.M. Rowsell <amr@frzn.dev>
Date: Thu Apr 9 23:59:13 2026 -0400
font: extensive tweaks, looks much better
commit 64205e137c8e390f309b59c06f97cbdfd722adb0
Author: A.M. Rowsell <amr@frzn.dev>
Date: Thu Apr 9 12:13:00 2026 -0400
font: fully implemented font changes to UI, size/spacing need tweaking
commit 901f063696b37700065cc094f7bc22b040f6f682
Author: A.M. Rowsell <amr@frzn.dev>
Date: Wed Apr 8 09:36:03 2026 -0400
font: tweak sizes of stats
commit 20f8c71fdf49a2da357081889c46d011e08d0726
Author: A.M. Rowsell <amr@frzn.dev>
Date: Wed Apr 8 09:28:22 2026 -0400
render: implement experimental font change, needs work
705 lines
26 KiB
C
705 lines
26 KiB
C
#include "render.h"
|
|
#include "items.h"
|
|
#include "settings.h"
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
void render_map(const Map *map) {
|
|
for (int y = 0; y < MAP_HEIGHT; y++) {
|
|
for (int x = 0; x < MAP_WIDTH; x++) {
|
|
Rectangle rect = {(float)(x * TILE_SIZE), (float)(y * TILE_SIZE), (float)TILE_SIZE, (float)TILE_SIZE};
|
|
int visible = map->visible[y][x];
|
|
int remembered = map->remembered[y][x];
|
|
|
|
if (!visible && !remembered) {
|
|
DrawRectangleRec(rect, (Color){5, 5, 10, 255});
|
|
continue;
|
|
}
|
|
|
|
Color wall_color = visible ? DARKGRAY : (Color){25, 25, 30, 255};
|
|
Color floor_color = visible ? BLACK : (Color){15, 15, 20, 255};
|
|
Color stairs_color = visible ? (Color){100, 100, 100, 255} : (Color){40, 40, 45, 255};
|
|
|
|
switch (map->tiles[y][x]) {
|
|
case TILE_WALL:
|
|
DrawRectangleRec(rect, wall_color);
|
|
break;
|
|
case TILE_FLOOR:
|
|
DrawRectangleRec(rect, floor_color);
|
|
break;
|
|
case TILE_STAIRS:
|
|
DrawRectangleRec(rect, stairs_color);
|
|
if (visible)
|
|
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, WHITE);
|
|
else
|
|
DrawText(">", x * TILE_SIZE + 4, y * TILE_SIZE + 2, 12, (Color){60, 60, 65, 255});
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void render_player(const Player *p) {
|
|
Rectangle rect = {(float)(p->position.x * TILE_SIZE), (float)(p->position.y * TILE_SIZE), (float)TILE_SIZE,
|
|
(float)TILE_SIZE};
|
|
DrawRectangleRec(rect, BLUE);
|
|
}
|
|
|
|
void render_enemies(const Enemy *enemies, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
|
for (int i = 0; i < count; i++) {
|
|
if (!enemies[i].alive)
|
|
continue;
|
|
if (!visible[enemies[i].position.y][enemies[i].position.x])
|
|
continue;
|
|
|
|
Rectangle rect = {(float)(enemies[i].position.x * TILE_SIZE), (float)(enemies[i].position.y * TILE_SIZE),
|
|
(float)TILE_SIZE, (float)TILE_SIZE};
|
|
|
|
// Different colors based on enemy type
|
|
Color enemy_color;
|
|
switch (enemies[i].type) {
|
|
case ENEMY_GOBLIN:
|
|
enemy_color = COLOR_ENEMY_GOBLIN; // dark red
|
|
break;
|
|
case ENEMY_SKELETON:
|
|
enemy_color = COLOR_ENEMY_SKELETON; // light gray
|
|
break;
|
|
case ENEMY_ORC:
|
|
enemy_color = COLOR_ENEMY_ORC; // dark green
|
|
break;
|
|
default:
|
|
enemy_color = RED;
|
|
break;
|
|
}
|
|
|
|
DrawRectangleRec(rect, enemy_color);
|
|
|
|
// Draw hp bar above enemy, color-coded by health remaining
|
|
int hp_pixels = (enemies[i].hp * TILE_SIZE) / enemies[i].max_hp;
|
|
if (hp_pixels > 0) {
|
|
float hp_ratio = (float)enemies[i].hp / (float)enemies[i].max_hp;
|
|
Color bar_color;
|
|
if (hp_ratio > 0.5f)
|
|
bar_color = (Color){60, 180, 60, 255}; // green
|
|
else if (hp_ratio > 0.25f)
|
|
bar_color = (Color){200, 180, 40, 255}; // yellow
|
|
else
|
|
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),
|
|
(float)hp_pixels, 3};
|
|
DrawRectangleRec(hp_bar, bar_color);
|
|
}
|
|
}
|
|
}
|
|
|
|
void render_items(const Item *items, int count, const unsigned char visible[MAP_HEIGHT][MAP_WIDTH]) {
|
|
for (int i = 0; i < count; i++) {
|
|
if (items[i].picked_up)
|
|
continue;
|
|
if (!visible[items[i].y][items[i].x])
|
|
continue;
|
|
|
|
Rectangle rect = {(float)(items[i].x * TILE_SIZE), (float)(items[i].y * TILE_SIZE), (float)TILE_SIZE,
|
|
(float)TILE_SIZE};
|
|
|
|
// Different colors based on item type
|
|
Color item_color;
|
|
switch (items[i].type) {
|
|
case ITEM_POTION:
|
|
item_color = COLOR_ITEM_POTION; // red/pink
|
|
break;
|
|
case ITEM_WEAPON:
|
|
item_color = COLOR_ITEM_WEAPON; // yellow
|
|
break;
|
|
case ITEM_ARMOR:
|
|
item_color = COLOR_ITEM_ARMOR; // blue
|
|
break;
|
|
default:
|
|
item_color = GREEN;
|
|
break;
|
|
}
|
|
|
|
DrawRectangleRec(rect, item_color);
|
|
}
|
|
}
|
|
|
|
void render_ui(const Player *p, Font *font) {
|
|
// 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
|
|
|
|
// 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});
|
|
|
|
// Section dividers
|
|
int section1_end = 180; // after portrait + HP bar
|
|
int section2_end = 310; // after stats
|
|
int section3_end = 480; // after equipment
|
|
|
|
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});
|
|
|
|
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
|
|
DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 17}, BIG_FONT, NAR_CHAR_SPACE, 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 hp_color;
|
|
if (hp_percent > 0.6f) {
|
|
hp_color = (Color){60, 180, 60, 255};
|
|
} else if (hp_percent > 0.3f) {
|
|
hp_color = (Color){200, 180, 40, 255};
|
|
} else {
|
|
hp_color = (Color){200, 60, 60, 255};
|
|
}
|
|
|
|
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, 12);
|
|
DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, MEDIUM_FONT,
|
|
SMALL_CHAR_SPACE, WHITE);
|
|
|
|
// 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 = "";
|
|
switch (p->effects[i].type) {
|
|
case EFFECT_POISON:
|
|
eff_color = (Color){50, 200, 50, 255};
|
|
eff_label = "PSN";
|
|
break;
|
|
case EFFECT_BLEED:
|
|
eff_color = (Color){200, 50, 50, 255};
|
|
eff_label = "BLD";
|
|
break;
|
|
case EFFECT_STUN:
|
|
eff_color = (Color){200, 200, 50, 255};
|
|
eff_label = "STN";
|
|
break;
|
|
case EFFECT_WEAKEN:
|
|
eff_color = (Color){120, 120, 120, 255};
|
|
eff_label = "WKN";
|
|
break;
|
|
case EFFECT_BURN:
|
|
eff_color = (Color){230, 130, 30, 255};
|
|
eff_label = "BRN";
|
|
break;
|
|
default:
|
|
continue;
|
|
}
|
|
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}, SMALL_FONT, NAR_CHAR_SPACE, eff_color);
|
|
effect_x += 28;
|
|
}
|
|
}
|
|
|
|
int stats_x = section1_end + 15;
|
|
int stats_y = hud_y + 12;
|
|
int stat_spacing = 40;
|
|
|
|
// 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_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_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_CHAR_SPACE,
|
|
(Color){100, 150, 255, 255});
|
|
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}, MEDIUM_FONT, 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));
|
|
DrawTextEx(*font, weapon_text, (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){255, 220, 100, 255});
|
|
}
|
|
} else {
|
|
DrawTextEx(*font, "None [IMP]", (Vector2){equip_x, equip_y + 11}, 10, NAR_CHAR_SPACE, (Color){80, 75, 70, 255});
|
|
}
|
|
|
|
// Armor slot
|
|
DrawTextEx(*font, "ARMOR", (Vector2){equip_x, equip_y + 26}, MEDIUM_FONT, 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);
|
|
DrawTextEx(*font, armor_text, (Vector2){equip_x, equip_y + 37}, 10, NAR_CHAR_SPACE, (Color){100, 150, 255, 255});
|
|
}
|
|
} else {
|
|
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;
|
|
|
|
DrawTextEx(*font, "[WASD] Move [G] Pickup [I] Inventory [U] Use", (Vector2){ctrl_x, ctrl_y}, MEDIUM_FONT,
|
|
MED_CHAR_SPACE, (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
|
|
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);
|
|
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, Font *font) {
|
|
// 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});
|
|
DrawTextEx(*font, "MESSAGE LOG", (Vector2){log_x + 8, log_y + 6}, MEDIUM_FONT, 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);
|
|
|
|
// 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') {
|
|
// 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
|
|
}
|
|
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, Font *font) {
|
|
// Overlay dimensions
|
|
int ov_width = 360;
|
|
int ov_height = 320;
|
|
Rectangle overlay = {(float)(SCREEN_WIDTH - ov_width) / 2, (float)(SCREEN_HEIGHT - ov_height) / 2 - 60,
|
|
(float)ov_width, (float)ov_height};
|
|
DrawRectangleRec(overlay, (Color){12, 12, 12, 252});
|
|
DrawRectangleLines((int)overlay.x, (int)overlay.y, (int)overlay.width, (int)overlay.height, (Color){70, 70, 70, 255});
|
|
|
|
// Title
|
|
const char *title = "INVENTORY";
|
|
int title_w = MeasureText(title, 24);
|
|
Vector2 t_w = MeasureTextEx(*font, title, 30, NORM_CHAR_SPACE);
|
|
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
|
|
char slot_text[64];
|
|
int row_height = 26;
|
|
int start_y = overlay.y + 40;
|
|
|
|
for (int i = 0; i < MAX_INVENTORY; i++) {
|
|
int y_pos = start_y + (i * row_height);
|
|
|
|
if (i < p->inventory_count && !p->inventory[i].picked_up) {
|
|
const Item *item = &p->inventory[i];
|
|
|
|
// Selection highlight
|
|
if (i == selected) {
|
|
DrawRectangle((int)overlay.x + 6, y_pos, (int)overlay.width - 12, row_height - 2, (Color){45, 45, 45, 255});
|
|
DrawRectangleLines((int)overlay.x + 6, y_pos, (int)overlay.width - 12, row_height - 2,
|
|
(Color){180, 160, 80, 255});
|
|
}
|
|
|
|
// Slot number
|
|
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,
|
|
(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};
|
|
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);
|
|
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 150, y_pos + 4}, 14, NORM_CHAR_SPACE, YELLOW);
|
|
|
|
// Action
|
|
if (item->type == ITEM_POTION) {
|
|
DrawTextEx(*font, "[U]se", (Vector2){overlay.x + 200, y_pos + 4}, 14, NORM_CHAR_SPACE, GREEN);
|
|
} else {
|
|
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);
|
|
DrawTextEx(*font, slot_text, (Vector2){overlay.x + 16, y_pos + 4}, MEDIUM_FONT, SMALL_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";
|
|
Vector2 hint_w = MeasureTextEx(*font, hint, NORM_FONT, NAR_CHAR_SPACE);
|
|
DrawTextEx(*font, hint, (Vector2){overlay.x + (overlay.width - hint_w.x) / 2, overlay.y + overlay.height - 22},
|
|
NORM_FONT, NAR_CHAR_SPACE, (Color){80, 80, 80, 255});
|
|
}
|
|
|
|
static Color label_color(FloatingText *ft, int alpha) {
|
|
if (ft->label == LABEL_NONE)
|
|
return FLOAT_DAMAGE; // numeric damage default
|
|
|
|
switch (ft->label) {
|
|
case LABEL_DODGE:
|
|
return FLOAT_DODGE;
|
|
case LABEL_BLOCK:
|
|
return FLOAT_BLOCK;
|
|
case LABEL_CRIT:
|
|
return FLOAT_CRIT;
|
|
case LABEL_SLAIN:
|
|
return FLOAT_SLAIN;
|
|
case LABEL_PROC:
|
|
// Proc label, color driven by effect_type stored in the struct
|
|
switch (ft->effect_type) {
|
|
case EFFECT_POISON:
|
|
return (Color){50, 200, 50, alpha};
|
|
case EFFECT_BLEED:
|
|
return (Color){200, 50, 50, alpha};
|
|
case EFFECT_BURN:
|
|
return (Color){230, 130, 30, alpha};
|
|
case EFFECT_STUN:
|
|
return (Color){200, 200, 50, alpha};
|
|
case EFFECT_WEAKEN:
|
|
return (Color){120, 120, 120, alpha};
|
|
default:
|
|
return FLOAT_DEFAULT;
|
|
}
|
|
default:
|
|
return FLOAT_DAMAGE;
|
|
}
|
|
}
|
|
|
|
static const char *label_text(FloatingLabel label) {
|
|
switch (label) {
|
|
case LABEL_DODGE:
|
|
return "DODGE";
|
|
case LABEL_BLOCK:
|
|
return "BLOCK";
|
|
case LABEL_CRIT:
|
|
return "CRIT!";
|
|
case LABEL_SLAIN:
|
|
return "SLAIN";
|
|
case LABEL_PROC:
|
|
return "PROC";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
static int label_font_size(FloatingLabel label) {
|
|
return (label == LABEL_CRIT) ? FONT_SIZE_FLOAT_CRIT : FONT_SIZE_FLOAT_LABEL;
|
|
}
|
|
|
|
void render_floating_texts(FloatingText *texts, int count, int shake_x, int shake_y) {
|
|
for (int i = 0; i < count; i++) {
|
|
if (texts[i].lifetime <= 0)
|
|
continue;
|
|
|
|
int x = texts[i].x + shake_x;
|
|
int y = texts[i].y + shake_y - (60 - texts[i].lifetime); // rise over time
|
|
float alpha = (float)texts[i].lifetime / 60.0f;
|
|
int a = (int)(255 * alpha);
|
|
|
|
if (texts[i].label != LABEL_NONE) {
|
|
// Label text (DODGE, BLOCK, CRIT!, SLAIN, or PROC)
|
|
// CRIT! gets larger font size
|
|
int font_size = label_font_size(texts[i].label);
|
|
Color color = label_color(&texts[i], a);
|
|
const char *text = label_text(texts[i].label);
|
|
int text_w = MeasureText(text, font_size);
|
|
DrawText(text, x - text_w / 2, y, font_size, color);
|
|
} else {
|
|
// Numeric damage
|
|
Color color = texts[i].is_critical ? (Color){255, 200, 50, a} : (Color){255, 100, 100, a};
|
|
char text[16];
|
|
snprintf(text, sizeof(text), "%d", texts[i].value);
|
|
int text_w = MeasureText(text, 18);
|
|
DrawText(text, x - text_w / 2, y, 18, color);
|
|
}
|
|
}
|
|
}
|
|
|
|
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) {
|
|
// Semi-transparent overlay
|
|
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
|
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
|
|
|
// 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);
|
|
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;
|
|
int box_y = 110;
|
|
int box_w = 400;
|
|
int box_h = 350;
|
|
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
|
|
DrawTextEx(*font, "Kills:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", kills);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Items:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", items);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Damage Dealt:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", damage_dealt);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Damage Taken:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", damage_taken);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 140, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Crits:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", crits);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 80, row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Times Hit:", (Vector2){col1_x, row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", times_hit);
|
|
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;
|
|
DrawTextEx(*font, "Potions:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", potions);
|
|
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
col2_row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Floors:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", floors);
|
|
DrawTextEx(*font, line, (Vector2){col2_x + 80, col2_row_y}, 18, NORM_CHAR_SPACE, value_color);
|
|
col2_row_y += line_height;
|
|
|
|
DrawTextEx(*font, "Turns:", (Vector2){col2_x, col2_row_y}, 18, NORM_CHAR_SPACE, label_color);
|
|
snprintf(line, sizeof(line), "%d", turns);
|
|
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;
|
|
DrawTextEx(*font, "SCORE:", (Vector2){col1_x, row_y}, 22, NORM_CHAR_SPACE, GOLD);
|
|
snprintf(line, sizeof(line), "%d", score);
|
|
DrawTextEx(*font, line, (Vector2){col1_x + 90, col2_row_y}, 22, NORM_CHAR_SPACE, 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) {
|
|
const char *subtitle = "Press R to play again or Q to quit";
|
|
int sub_width = MeasureText(subtitle, 20);
|
|
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);
|
|
DrawTextEx(*font, subtitle, (Vector2){(SCREEN_WIDTH - sub_width) / 2.0f, SCREEN_HEIGHT - 50}, 20, NORM_CHAR_SPACE,
|
|
LIGHTGRAY);
|
|
}
|
|
}
|
|
|
|
void render_message(const char *message, Font *font) {
|
|
if (message == NULL)
|
|
return;
|
|
|
|
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);
|
|
|
|
// 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});
|
|
|
|
// 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;
|
|
}
|
|
|
|
DrawTextEx(*font, message, (Vector2){text_x, text_y}, font_size, NORM_CHAR_SPACE, 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);
|
|
}
|