1
0
Fork 0
forked from NotAShelf/rogged

render: clean up font management; account for differing container sizes

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Icd554815388ec44886245406ac9ea0be6a6a6964
This commit is contained in:
raf 2026-04-22 02:58:39 +03:00
commit e00424a918
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 247 additions and 130 deletions

View file

@ -431,7 +431,6 @@ static int handle_movement_input(GameState *gs) {
}
}
Vec2 direction = {0, 0};
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))
direction.y = -1;
@ -448,7 +447,6 @@ static int handle_movement_input(GameState *gs) {
// Reset combat event before player acts
combat_reset_event();
int new_x = gs->player.position.x + direction.x;
int new_y = gs->player.position.y + direction.y;
@ -519,7 +517,7 @@ void load_audio_assets(GameState *gs) {
}
// Main game loop
static void game_loop(unsigned int run_seed) {
static void game_loop(unsigned int run_seed, FontManager *fm) {
GameState gs;
memset(&gs, 0, sizeof(GameState));
gs.run_seed = run_seed;
@ -527,7 +525,7 @@ static void game_loop(unsigned int run_seed) {
// sound
load_audio_assets(&gs);
// font
Font fontTTF = LoadFontEx("./assets/fonts/spartan_500.ttf", 36, NULL, 0);
init_fonts(fm);
// Initialize first floor
init_floor(&gs, 1);
@ -553,6 +551,7 @@ static void game_loop(unsigned int run_seed) {
gs.game_over = 0;
gs.game_won = 0;
load_audio_assets(&gs);
init_fonts(fm);
init_floor(&gs, 1);
// Update window title with new seed
char title[128];
@ -585,19 +584,19 @@ static void game_loop(unsigned int run_seed) {
// Floating texts follow world shake
render_floating_texts(gs.floating_texts, gs.floating_count, gs.shake_x, gs.shake_y);
render_ui(&gs.player, &fontTTF);
render_ui(&gs.player, fm);
// Draw action log
render_action_log(gs.action_log, gs.log_count, gs.log_head, &fontTTF);
render_action_log(gs.action_log, gs.log_count, gs.log_head, fm);
// Draw inventory overlay if active
if (gs.show_inventory) {
render_inventory_overlay(&gs.player, gs.inv_selected, &fontTTF);
render_inventory_overlay(&gs.player, gs.inv_selected, fm);
}
// Draw message if any
if (gs.last_message != NULL && gs.message_timer > 0) {
render_message(gs.last_message, &fontTTF);
render_message(gs.last_message, fm);
}
// Draw persistent seed display in top right
@ -613,7 +612,7 @@ static void game_loop(unsigned int run_seed) {
}
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.run_seed, &fontTTF);
gs.final_score, gs.run_seed, fm);
}
EndDrawing();
@ -621,6 +620,9 @@ static void game_loop(unsigned int run_seed) {
// small delay for key repeat control
WaitTime(0.08);
}
// Cleanup
destroy_fonts(fm);
}
// Check if a string is a valid unsigned integer
@ -683,11 +685,13 @@ int main(int argc, char **argv) {
SetTargetFPS(60);
// Run game
game_loop(run_seed);
FontManager fm;
init_fonts(&fm);
game_loop(run_seed, &fm);
// Cleanup
CloseWindow();
audio_close();
return 0;
}
}