render: implement experimental font change, needs work
This commit is contained in:
parent
6281c756a8
commit
59db4e7d79
5 changed files with 21 additions and 14 deletions
BIN
assets/fonts/Royal_Decree.ttf
Normal file
BIN
assets/fonts/Royal_Decree.ttf
Normal file
Binary file not shown.
BIN
assets/fonts/Royal_Decree_Bold.ttf
Normal file
BIN
assets/fonts/Royal_Decree_Bold.ttf
Normal file
Binary file not shown.
|
|
@ -496,7 +496,11 @@ void load_audio_assets(GameState *gs) {
|
||||||
static void game_loop(void) {
|
static void game_loop(void) {
|
||||||
GameState gs;
|
GameState gs;
|
||||||
memset(&gs, 0, sizeof(GameState));
|
memset(&gs, 0, sizeof(GameState));
|
||||||
|
// load external assets
|
||||||
|
// sound
|
||||||
load_audio_assets(&gs);
|
load_audio_assets(&gs);
|
||||||
|
// font
|
||||||
|
Font fontTTF = LoadFontEx("./assets/fonts/Royal_Decree_Bold.ttf", 14, 0, 250);
|
||||||
// Initialize first floor
|
// Initialize first floor
|
||||||
rng_seed(12345);
|
rng_seed(12345);
|
||||||
init_floor(&gs, 1);
|
init_floor(&gs, 1);
|
||||||
|
|
@ -549,7 +553,7 @@ static void game_loop(void) {
|
||||||
|
|
||||||
// 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);
|
render_ui(&gs.player, &fontTTF);
|
||||||
|
|
||||||
// Draw action log
|
// 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);
|
||||||
|
|
|
||||||
27
src/render.c
27
src/render.c
|
|
@ -108,7 +108,9 @@ void render_items(const Item *items, int count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_ui(const Player *p) {
|
void render_ui(const Player *p, Font *font) {
|
||||||
|
float nar_space = 1.0;
|
||||||
|
float norm_space = 4.0;
|
||||||
// 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;
|
||||||
|
|
@ -152,7 +154,7 @@ void render_ui(const Player *p) {
|
||||||
int bar_height = 16;
|
int bar_height = 16;
|
||||||
|
|
||||||
// HP Label, above bar
|
// HP Label, above bar
|
||||||
DrawText("HP", bar_x, bar_y - 11, 9, text_dim);
|
DrawTextEx(*font, "HP", (Vector2){bar_x, bar_y - 11}, 14, nar_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});
|
||||||
|
|
@ -177,8 +179,8 @@ void render_ui(const Player *p) {
|
||||||
// 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, 10);
|
int hp_text_w = MeasureText(hp_text, 12);
|
||||||
DrawText(hp_text, bar_x + (bar_width - hp_text_w) / 2, bar_y + 2, 10, WHITE);
|
DrawTextEx(*font, hp_text, (Vector2){bar_x + (bar_width - hp_text_w) / 2.0f, bar_y + 2}, 12, nar_space, WHITE);
|
||||||
|
|
||||||
// Status effects
|
// Status effects
|
||||||
int effect_x = bar_x;
|
int effect_x = bar_x;
|
||||||
|
|
@ -213,7 +215,7 @@ void render_ui(const Player *p) {
|
||||||
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);
|
||||||
DrawText(eff_text, effect_x, effect_y, 9, eff_color);
|
DrawTextEx(*font, eff_text, (Vector2){effect_x, effect_y}, 9, nar_space, eff_color);
|
||||||
effect_x += 28;
|
effect_x += 28;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -225,26 +227,27 @@ void render_ui(const Player *p) {
|
||||||
// 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);
|
||||||
DrawText(floor_text, stats_x, stats_y, 14, text_bright);
|
DrawTextEx(*font, floor_text, (Vector2){stats_x, stats_y}, 16, norm_space, text_bright);
|
||||||
DrawText("Floor", stats_x, stats_y + 16, 9, text_dim);
|
DrawTextEx(*font, "Floor", (Vector2){stats_x, stats_y + 16}, 12, nar_space, 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);
|
||||||
DrawText(atk_text, stats_x + stat_spacing, stats_y, 14, YELLOW);
|
DrawTextEx(*font, atk_text, (Vector2){stats_x + stat_spacing, stats_y}, 14, norm_space, YELLOW);
|
||||||
DrawText("ATK", stats_x + stat_spacing, stats_y + 16, 9, text_dim);
|
DrawTextEx(*font, "ATK", (Vector2){stats_x + stat_spacing, stats_y + 16}, 9, nar_space, 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);
|
||||||
DrawText(def_text, stats_x + stat_spacing * 2, stats_y, 14, (Color){100, 150, 255, 255});
|
DrawTextEx(*font, def_text, (Vector2){stats_x + stat_spacing * 2, stats_y}, 14, norm_space,
|
||||||
DrawText("DEF", stats_x + stat_spacing * 2, stats_y + 16, 9, text_dim);
|
(Color){100, 150, 255, 255});
|
||||||
|
DrawTextEx(*font, "DEF", (Vector2){stats_x + stat_spacing * 2, stats_y + 16}, 9, nar_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
|
||||||
DrawText("WEAPON", equip_x, equip_y, 9, text_dim);
|
DrawTextEx(*font, "WEAPON", (Vector2){equip_x, equip_y}, 9, nar_space, 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) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ void render_enemies(const Enemy *enemies, int count);
|
||||||
void render_items(const Item *items, int count);
|
void render_items(const Item *items, int count);
|
||||||
|
|
||||||
// Render UI overlay
|
// Render UI overlay
|
||||||
void render_ui(const Player *p);
|
void render_ui(const Player *p, Font *font);
|
||||||
|
|
||||||
// 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);
|
void render_action_log(const char log[5][128], int count, int head);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue