fp: Only allow buildings to be placed in build zones
This commit is contained in:
parent
efaf2ac1cc
commit
760da9d39f
@ -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);
|
||||
|
||||
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 ==========================================================
|
||||
|
@ -257,6 +257,7 @@ struct FP_Game
|
||||
Dqn_PCG32 rng;
|
||||
|
||||
bool build_mode;
|
||||
bool build_mode_can_place_building;
|
||||
};
|
||||
|
||||
struct FP_GameAStarNode
|
||||
|
BIN
project.rdbg
BIN
project.rdbg
Binary file not shown.
Loading…
Reference in New Issue
Block a user