From 09a83e3bfd383a0a85a785875686e682d9b91c98 Mon Sep 17 00:00:00 2001 From: doyle Date: Fri, 6 Oct 2023 23:30:09 +1100 Subject: [PATCH] fp: Render a $ amount on the merchant menu --- feely_pona.cpp | 63 ++++++++++++++++++++++++++++++++--------------- feely_pona_game.h | 1 + 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index a62cc31..39c7dfc 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -486,6 +486,7 @@ void TELY_DLL_Init(void *user_data) game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size); game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size); game->talkco_font = platform->func_load_font(assets, DQN_STRING8("Talkco"), DQN_STRING8("Data/Talkco.otf"), font_size); + game->talkco_font_large = platform->func_load_font(assets, DQN_STRING8("Talkco"), DQN_STRING8("Data/Talkco.otf"), DQN_CAST(uint16_t)(font_size * 1.5f)); game->audio[FP_GameAudio_TestAudio] = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); game->audio[FP_GameAudio_TerryHit] = platform->func_load_audio(assets, DQN_STRING8("Terry Hit"), DQN_STRING8("Data/Audio/terry_hit.ogg")); game->audio[FP_GameAudio_Smooch] = platform->func_load_audio(assets, DQN_STRING8("Smooch"), DQN_STRING8("Data/Audio/smooch.mp3")); @@ -2212,33 +2213,55 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) continue; activated_merchant = true; - FP_GameRenderSprite *sprite = &game->player_merchant_menu; - if (!sprite->asset.anim || sprite->asset.anim->label != mapping.menu_anim) { - sprite->asset = TELY_Asset_MakeAnimatedSprite(&game->atlas_sprite_sheet, mapping.menu_anim, TELY_AssetFlip_No); - sprite->started_at_clock_ms = game->clock_ms; + // NOTE: Render animated merchant menu + Dqn_Rect merchant_menu_rect = {}; + { + FP_GameRenderSprite *sprite = &game->player_merchant_menu; + if (!sprite->asset.anim || sprite->asset.anim->label != mapping.menu_anim) { + sprite->asset = TELY_Asset_MakeAnimatedSprite(&game->atlas_sprite_sheet, mapping.menu_anim, TELY_AssetFlip_No); + sprite->started_at_clock_ms = game->clock_ms; + } + + uint64_t elapsed_ms = game->clock_ms - sprite->started_at_clock_ms; + uint16_t raw_anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite->asset.anim->ms_per_frame); + uint16_t anim_frame = raw_anim_frame % sprite->asset.anim->count; + + Dqn_usize sprite_index = sprite->asset.anim->index + anim_frame; + Dqn_Rect src_rect = sprite->asset.sheet->rects.data[sprite_index]; + + merchant_menu_rect.size = src_rect.size; + merchant_menu_rect.pos = world_pos - (merchant_menu_rect.size * .5f) - Dqn_V2_InitNx2(0.f, src_rect.size.y); + Dqn_f32 sin_t = DQN_SINF(DQN_CAST(Dqn_f32)input->timer_s * 3.f); + merchant_menu_rect.pos.y += sin_t * 4.f; + + TELY_Render_TextureColourV4(renderer, + sprite->asset.sheet->tex_handle, + src_rect, + merchant_menu_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_WHITE_V4); } - uint64_t elapsed_ms = game->clock_ms - sprite->started_at_clock_ms; - uint16_t raw_anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite->asset.anim->ms_per_frame); - uint16_t anim_frame = raw_anim_frame % sprite->asset.anim->count; - - Dqn_usize sprite_index = sprite->asset.anim->index + anim_frame; - Dqn_Rect src_rect = sprite->asset.sheet->rects.data[sprite_index]; - - Dqn_Rect dest_rect = {}; - dest_rect.size = src_rect.size; - dest_rect.pos = world_pos - (dest_rect.size * .5f) - Dqn_V2_InitNx2(0.f, src_rect.size.y); - - Dqn_f32 sin_t = DQN_SINF(DQN_CAST(Dqn_f32)input->timer_s * 3.f); - dest_rect.pos.y += sin_t * 4.f; - + // NOTE: Render the merchant button + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.merchant_button_a); + Dqn_Rect button_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + Dqn_Rect dest_rect = {}; + dest_rect.size = button_rect.size * 1.5f; + dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.75f, 0.5f)); TELY_Render_TextureColourV4(renderer, - sprite->asset.sheet->tex_handle, - src_rect, + game->atlas_sprite_sheet.tex_handle, + button_rect, dest_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotation*/, TELY_COLOUR_WHITE_V4); + + TELY_Render_PushColourV4(renderer, TELY_COLOUR_WHITE_V4); + TELY_Render_PushFont(renderer, game->talkco_font_large); + TELY_Render_TextF(renderer, Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0.5f, -1)), Dqn_V2_InitNx2(0.5, 0.f), "$2"); + TELY_Render_PopFont(renderer); + TELY_Render_PopColourV4(renderer); } if (activated_merchant) { diff --git a/feely_pona_game.h b/feely_pona_game.h index 77f9f2d..55d0c0c 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -244,6 +244,7 @@ struct FP_Game TELY_AssetFontHandle inter_italic_font; TELY_AssetFontHandle jetbrains_mono_font; TELY_AssetFontHandle talkco_font; + TELY_AssetFontHandle talkco_font_large; TELY_AssetAudioHandle audio[FP_GameAudio_Count]; Dqn_Slice hero_sprite_anims;