diff --git a/feely_pona.cpp b/feely_pona.cpp index 4af6134..af2de43 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -2589,24 +2589,31 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, play->merchant_phone_company, }; + // NOTE: Calculate which merchant sound trigger flags to reset ============================= + FP_GameEntityHandle merchant_with_more_than_2_menus_open = {}; static bool sound_played_flags[DQN_ARRAY_UCOUNT(merchant_handles)] = {false, false, false, false}; DQN_FOR_UINDEX (merchant_index, DQN_ARRAY_UCOUNT(merchant_handles)) { - FP_GameEntityHandle merchant = merchant_handles[merchant_index]; - Dqn_V2 merchant_pos = FP_Game_CalcEntityWorldPos(game, merchant); - - bool all_players_are_far_away_from_merchant_menu_trigger = true; + FP_GameEntityHandle merchant = merchant_handles[merchant_index]; + Dqn_V2 merchant_pos = FP_Game_CalcEntityWorldPos(game, merchant); + Dqn_usize menu_activation_count = 0; + bool all_players_are_far_away_from_merchant_menu_trigger = true; DQN_FOR_UINDEX (player_index, game->play.players.size) { FP_GameEntityHandle player_handle = game->play.players.data[player_index]; Dqn_V2 player_pos = FP_Game_CalcEntityWorldPos(game, player_handle); Dqn_f32 dist_squared = Dqn_V2_LengthSq_V2x2(merchant_pos, player_pos); if (dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game->play, 4))) { all_players_are_far_away_from_merchant_menu_trigger = false; - break; + menu_activation_count++; } } if (all_players_are_far_away_from_merchant_menu_trigger) sound_played_flags[merchant_index] = false; + + if (menu_activation_count >= 2) { + DQN_ASSERT(merchant_with_more_than_2_menus_open.id == 0); + merchant_with_more_than_2_menus_open = merchant; + } } Dqn_Rect first_player_avatar_rect = {}; @@ -2629,10 +2636,10 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, FP_GameAudio audio_type; bool *sound_played; } merchants[] = { - {play->merchant_terry, &play->merchant_terry_menu_pos, g_anim_names.icon_attack, g_anim_names.merchant_terry_menu, g_anim_names.club_terry_dark, Dqn_V2_InitNx2(0.015f, +0.04f), &invent->clubs, &invent->clubs_base_price, &invent->health_base_price, FP_GameAudio_MerchantTerry, &sound_played_flags[0]}, - {play->merchant_graveyard, &play->merchant_graveyard_menu_pos, g_anim_names.icon_stamina, g_anim_names.merchant_graveyard_menu, g_anim_names.church_terry_dark, Dqn_V2_InitNx2(0.04f, -0.15f), &invent->churchs, &invent->churchs_base_price, &invent->stamina_base_price, FP_GameAudio_MerchantGhost, &sound_played_flags[1]}, - {play->merchant_gym, &play->merchant_gym_menu_pos, g_anim_names.icon_health, g_anim_names.merchant_gym_menu, g_anim_names.kennel_terry, Dqn_V2_InitNx2(0, +0), &invent->kennels, &invent->kennels_base_price, &invent->attack_base_price, FP_GameAudio_MerchantGym, &sound_played_flags[2]}, - {play->merchant_phone_company, &play->merchant_phone_company_menu_pos, g_anim_names.icon_phone, g_anim_names.merchant_phone_company_menu, g_anim_names.airport_terry, Dqn_V2_InitNx2(0, -0.1f), &invent->airports, &invent->airports_base_price, &invent->mobile_plan_base_price, FP_GameAudio_MerchantPhone, &sound_played_flags[3]}, + {play->merchant_terry, &player->merchant_terry_menu_pos, g_anim_names.icon_attack, g_anim_names.merchant_terry_menu, g_anim_names.club_terry_dark, Dqn_V2_InitNx2(0.015f, +0.04f), &invent->clubs, &invent->clubs_base_price, &invent->health_base_price, FP_GameAudio_MerchantTerry, &sound_played_flags[0]}, + {play->merchant_graveyard, &player->merchant_graveyard_menu_pos, g_anim_names.icon_stamina, g_anim_names.merchant_graveyard_menu, g_anim_names.church_terry_dark, Dqn_V2_InitNx2(0.04f, -0.15f), &invent->churchs, &invent->churchs_base_price, &invent->stamina_base_price, FP_GameAudio_MerchantGhost, &sound_played_flags[1]}, + {play->merchant_gym, &player->merchant_gym_menu_pos, g_anim_names.icon_health, g_anim_names.merchant_gym_menu, g_anim_names.kennel_terry, Dqn_V2_InitNx2(0, +0), &invent->kennels, &invent->kennels_base_price, &invent->attack_base_price, FP_GameAudio_MerchantGym, &sound_played_flags[2]}, + {play->merchant_phone_company, &player->merchant_phone_company_menu_pos, g_anim_names.icon_phone, g_anim_names.merchant_phone_company_menu, g_anim_names.airport_terry, Dqn_V2_InitNx2(0, -0.1f), &invent->airports, &invent->airports_base_price, &invent->mobile_plan_base_price, FP_GameAudio_MerchantPhone, &sound_played_flags[3]}, }; bool activated_merchant = false; @@ -2668,9 +2675,20 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, Dqn_Rect top_rect = Dqn_Rect_InitV2x2(world_pos - (src_rect.size * .5f) - Dqn_V2_InitNx2(0.f, src_rect.size.h), src_rect.size); Dqn_Rect bottom_rect = Dqn_Rect_InitV2x2(world_pos - (src_rect.size * .5f) + Dqn_V2_InitNx2(0.f, src_rect.size.h), src_rect.size); - // NOTE: Move the merchant menu if we overlap with it so as to not occlude the player - { - Dqn_V2 target_pos = {}; + // NOTE: Position the merchant menu ======================================== + if (merchant_with_more_than_2_menus_open == mapping.merchant) { + // NOTE: More than 2 players have activated the same merchant, we just + // draw the menus and overlap with the players. + if (player_index == 0) + *mapping.menu_pos = top_rect.pos; + else + *mapping.menu_pos = bottom_rect.pos; + } else { + // NOTE: Move the merchant menu if we overlap with it so as to not + // occlude the player. We *only* do this if the merchant is activated + // by 1 player only. If multiple players activate it, we just draw the + // menus-as-is. + Dqn_V2 target_pos = {}; Dqn_Rect camera_entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, player->handle); if (Dqn_Rect_Intersects(top_rect, camera_entity_hit_box)) { target_pos = bottom_rect.pos; diff --git a/feely_pona_game.h b/feely_pona_game.h index 0e58bd2..415ae65 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -274,6 +274,11 @@ struct FP_GameEntity Dqn_usize build_mode_building_index; FP_GameControls controls; + + Dqn_V2 merchant_terry_menu_pos; + Dqn_V2 merchant_graveyard_menu_pos; + Dqn_V2 merchant_gym_menu_pos; + Dqn_V2 merchant_phone_company_menu_pos; }; struct FP_GameEntityIterator