From 760da9d39f3bc919078fe516cda76f954ed6cc83 Mon Sep 17 00:00:00 2001 From: doyle Date: Tue, 3 Oct 2023 21:05:16 +1100 Subject: [PATCH] fp: Only allow buildings to be placed in build zones --- feely_pona.cpp | 31 +++++++++++++++++++++++++++---- feely_pona_game.h | 3 ++- project.rdbg | Bin 1353 -> 1569 bytes 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 2f76fa2..b27c792 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -1375,10 +1375,29 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input if (entity->flags & FP_GameEntityFlag_CameraTracking) game->camera.world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) - Dqn_V2_InitV2I(platform->core.window_size) * .5f; + game->build_mode_can_place_building = false; if (game->build_mode) { - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_E)) { - Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, entity->handle); - Dqn_V2 placement_pos = Dqn_Rect_Center(dest_rect); + + Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, entity->handle); + Dqn_V2 placement_pos = Dqn_Rect_Center(dest_rect); + + for (FP_GameEntityIterator zone_it = {}; + !game->build_mode_can_place_building && FP_Game_DFSPostOrderWalkEntityTree(game, &zone_it, game->root_entity); + ) { + FP_GameEntity *zone = zone_it.entity; + if ((zone->flags & FP_GameEntityFlag_BuildZone) == 0) + continue; + + Dqn_Rect zone_hit_box = FP_Game_CalcEntityWorldHitBox(game, zone->handle); + zone_hit_box.pos += dest_rect.size * .5f; + zone_hit_box.size -= dest_rect.size; + zone_hit_box.size = Dqn_V2_Max(zone_hit_box.size, Dqn_V2_Zero); + + game->build_mode_can_place_building = Dqn_Rect_ContainsPoint(zone_hit_box, placement_pos); + } + + if (game->build_mode_can_place_building && + TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_E)) { FP_Entity_CreateClubTerry(game, placement_pos, "Club Terry"); } } @@ -1767,6 +1786,10 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) FP_EntityRenderData club_terry_render_data = FP_Entity_GetRenderData(game, FP_EntityType_ClubTerry, FP_EntityClubTerryState_Idle, entity->direction); Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, entity->handle); + Dqn_V4 colour = game->build_mode_can_place_building ? + TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, 0.5f) : + TELY_Colour_V4Alpha(TELY_COLOUR_RED_V4, 0.5f); + TELY_Render_RectColourV4(renderer, dest_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_BLUE_CADET_V4, 0.5f)); TELY_Render_TextureColourV4(renderer, club_terry_render_data.sheet->tex_handle, @@ -1774,7 +1797,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) dest_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotation*/, - TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, 0.5f)); + colour); } // NOTE: Render hot/active entity ========================================================== diff --git a/feely_pona_game.h b/feely_pona_game.h index 13b42c7..50b1402 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -256,7 +256,8 @@ struct FP_Game uint64_t clock_ms; Dqn_PCG32 rng; - bool build_mode; + bool build_mode; + bool build_mode_can_place_building; }; struct FP_GameAStarNode diff --git a/project.rdbg b/project.rdbg index 33e9f5ec184a3e485df5eb82898ee97b56c26d88..2f87f4bff2bb704a8d120a83a252cc3cd2b2e96f 100644 GIT binary patch delta 264 zcmX@fwUB3mBP%Zh1B2=0jf~Qhy_xv9OHy+x(3aU?@%f!y;1eMlebVgFhQIL~Zl9peT3pCS)(GDgv zc?P2dBS^0rOL}5%>SRGiJrr$|IT?B2Ch`F-*RebTyUPyWO-IC059oJ7ytkO delta 169 zcmZ3;bCPRB4EubJd02QYImIzf3_jLtA|-qebc)S|q^9KGa%0yVIx zHxm~th^GzZ2{YP3Rr5{EXPqp=Bs_U5qXoi<$txLo;70RJ4q}vHglXlTtiZ^@3Umhp Y_vBdS2b29-UNUk|c4Q3&k_%ZI0OvF=#{d8T