Add font loading and use font for menu

main
En Yi 2025-01-18 09:39:36 +08:00
parent 1e0ec6edfb
commit 15162c64e8
2 changed files with 21 additions and 3 deletions

View File

@ -7,6 +7,7 @@ typedef enum AssetInfoType
TEXTURE_INFO,
SPRITE_INFO,
SOUND_INFO,
FONT_INFO,
EMITTER_INFO,
LEVELPACK_INFO,
INVALID_INFO
@ -80,6 +81,8 @@ static inline AssetInfoType_t get_asset_type(const char* str)
if (strcmp(str, "LevelPack") == 0) return LEVELPACK_INFO;
if (strcmp(str, "Font") == 0) return FONT_INFO;
return INVALID_INFO;
}
@ -272,12 +275,22 @@ bool load_from_infofile(const char* file, Assets_t* assets)
{
if (add_sound(assets, name, info_str) == NULL)
{
printf("Unable to add texture at line %lu\n", line_num);
printf("Unable to add sound at line %lu\n", line_num);
break;
}
printf("Added sound %s as %s\n", info_str, name);
}
break;
case FONT_INFO:
{
if (add_font(assets, name, info_str) == NULL)
{
printf("Unable to add font at line %lu\n", line_num);
break;
}
printf("Added font %s as %s\n", info_str, name);
}
break;
case LEVELPACK_INFO:
{
//if (add_level_pack(assets, name, info_str) == NULL)

View File

@ -11,12 +11,17 @@ static void menu_scene_render_func(Scene_t* scene)
Sprite_t* title_spr = get_sprite(&scene->engine->assets, "title_board");
Sprite_t* title_select = get_sprite(&scene->engine->assets, "title_select");
Rectangle render_rec = scene->layers.render_layers[0].render_area;
Font* menu_font = get_font(&scene->engine->assets, "MenuFont");
BeginTextureMode(scene->layers.render_layers[0].layer_tex);
ClearBackground(RAYWHITE);
draw_sprite(spr, 0, (Vector2){0, 0}, 0, false);
draw_sprite(title_spr, 0, (Vector2){32, 10}, 0, false);
int title_width = MeasureText("Bunny's Spelunking Adventure", 32);
DrawText("Bunny's Spelunking Adventure", (render_rec.width - title_width) / 2, 20, 32, BLACK);
Vector2 title_sz = MeasureTextEx(*menu_font, "Bunny's Spelunking Adventure", 56, 0);
Vector2 title_pos = {
.x = (render_rec.width - title_sz.x) / 2,
.y = 32 + (title_spr->frame_size.y - title_sz.y) / 2
};
DrawTextEx(*menu_font, "Bunny's Spelunking Adventure", title_pos, 56, 0, BLACK);
const char* OPTIONS[3] = {"Start", "Credits", "Exit"};
for (uint8_t i = 0; i < 3; ++i)