render: extract color palette; convert floating labels to enum

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I29c5feb6099fe321e227e0313282f1546a6a6964
This commit is contained in:
raf 2026-04-08 14:48:43 +03:00 committed by raf
commit eed5c3aff3
4 changed files with 151 additions and 53 deletions

View file

@ -46,13 +46,13 @@ void render_enemies(const Enemy *enemies, int count) {
Color enemy_color;
switch (enemies[i].type) {
case ENEMY_GOBLIN:
enemy_color = (Color){150, 50, 50, 255}; // dark red
enemy_color = COLOR_ENEMY_GOBLIN; // dark red
break;
case ENEMY_SKELETON:
enemy_color = (Color){200, 200, 200, 255}; // light gray
enemy_color = COLOR_ENEMY_SKELETON; // light gray
break;
case ENEMY_ORC:
enemy_color = (Color){50, 150, 50, 255}; // dark green
enemy_color = COLOR_ENEMY_ORC; // dark green
break;
default:
enemy_color = RED;
@ -91,13 +91,13 @@ void render_items(const Item *items, int count) {
Color item_color;
switch (items[i].type) {
case ITEM_POTION:
item_color = (Color){255, 100, 100, 255}; // red/pink
item_color = COLOR_ITEM_POTION; // red/pink
break;
case ITEM_WEAPON:
item_color = (Color){255, 255, 100, 255}; // yellow
item_color = COLOR_ITEM_WEAPON; // yellow
break;
case ITEM_ARMOR:
item_color = (Color){100, 100, 255, 255}; // blue
item_color = COLOR_ITEM_ARMOR; // blue
break;
default:
item_color = GREEN;
@ -405,34 +405,60 @@ void render_inventory_overlay(const Player *p, int selected) {
}
static Color label_color(FloatingText *ft, int alpha) {
if (ft->label[0] == '\0')
return (Color){255, 100, 100, alpha}; // numeric damage default
if (strcmp(ft->label, "DODGE") == 0)
return (Color){160, 160, 160, alpha};
if (strcmp(ft->label, "BLOCK") == 0)
return (Color){80, 130, 220, alpha};
if (strcmp(ft->label, "CRIT!") == 0)
return (Color){255, 200, 50, alpha};
if (strcmp(ft->label, "SLAIN") == 0)
return (Color){220, 50, 50, alpha};
if (ft->label == LABEL_NONE)
return FLOAT_DAMAGE; // numeric damage default
// 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};
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 (Color){200, 200, 200, alpha};
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)
@ -443,13 +469,14 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
float alpha = (float)texts[i].lifetime / 60.0f;
int a = (int)(255 * alpha);
if (texts[i].label[0] != '\0') {
// Label text (DODGE, BLOCK, CRIT!, proc name, SLAIN)
// Check for "CRIT!" specifically rather than just 'C' prefix
int font_size = (strcmp(texts[i].label, "CRIT!") == 0) ? 16 : 14;
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);
int text_w = MeasureText(texts[i].label, font_size);
DrawText(texts[i].label, x - text_w / 2, y, font_size, color);
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};