From d5ceea9c943829d2a31f2334d5364aee15db5fcb Mon Sep 17 00:00:00 2001 From: doyle Date: Fri, 6 Oct 2023 23:55:57 +1100 Subject: [PATCH] fp: Mock up the buy trigger anim and logic --- feely_pona.cpp | 28 ++++++++++++++++++++++++++-- feely_pona_game.h | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 39c7dfc..01f81e5 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -2218,8 +2218,19 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) { 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; + sprite->asset = TELY_Asset_MakeAnimatedSprite(&game->atlas_sprite_sheet, mapping.menu_anim, TELY_AssetFlip_No); + sprite->started_at_clock_ms = game->clock_ms; + } + + bool trigger_buy_anim = false; + uint64_t buy_duration_ms = 500; + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) { + game->player_trigger_purchase_timestamp = game->clock_ms + buy_duration_ms; + } else if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_J)) { + trigger_buy_anim = true; + if (game->clock_ms > game->player_trigger_purchase_timestamp) { + // TODO(doyle): Do buy logic + } } uint64_t elapsed_ms = game->clock_ms - sprite->started_at_clock_ms; @@ -2241,6 +2252,19 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) Dqn_V2_Zero /*rotate origin*/, 0.f /*rotation*/, TELY_COLOUR_WHITE_V4); + + if (trigger_buy_anim) { + uint64_t start_buy_time = game->player_trigger_purchase_timestamp - buy_duration_ms; + uint64_t elapsed_time = game->clock_ms - start_buy_time; + + Dqn_f32 buy_t = DQN_MIN(elapsed_time / DQN_CAST(Dqn_f32)buy_duration_ms, 1.f); + Dqn_Rect buy_lerp_rect = {}; + buy_lerp_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.68f, 0.215f)); + buy_lerp_rect.size.w = (merchant_menu_rect.size.w * 0.211f) * buy_t; + buy_lerp_rect.size.h = merchant_menu_rect.size.h * .611f; + + TELY_Render_RectColourV4(renderer, buy_lerp_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, 0.5f)); + } } // NOTE: Render the merchant button diff --git a/feely_pona_game.h b/feely_pona_game.h index 55d0c0c..c4a2632 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -260,6 +260,7 @@ struct FP_Game FP_GameEntityHandle player; FP_GameRenderSprite player_merchant_menu; + uint64_t player_trigger_purchase_timestamp; FP_GameEntityHandle merchant_terry; FP_GameEntityHandle merchant_graveyard;