fp: Introduce building zones

This commit is contained in:
doyle 2023-10-02 23:41:08 +11:00
parent 3efa397d1d
commit efaf2ac1cc
4 changed files with 75 additions and 3 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit 26f6dd7d348c5a732ddfb929bd2d9b01e644ac48 Subproject commit 4ccbde6fecb8ea17f9cde73df7c06da466311f3c

View File

@ -348,9 +348,9 @@ void TELY_DLL_Init(void *user_data)
} }
// NOTE: Map walls ============================================================================= // NOTE: Map walls =============================================================================
FP_GameEntity const *map = game->map;
Dqn_Rect const map_hit_box = FP_Game_CalcEntityWorldHitBox(game, map->handle);
{ {
FP_GameEntity const *map = game->map;
Dqn_Rect map_hit_box = FP_Game_CalcEntityWorldHitBox(game, map->handle);
Dqn_f32 wall_thickness = FP_Game_MetersToPixelsNx1(game, 1.f); Dqn_f32 wall_thickness = FP_Game_MetersToPixelsNx1(game, 1.f);
Dqn_f32 half_wall_thickness = wall_thickness * .5f; Dqn_f32 half_wall_thickness = wall_thickness * .5f;
@ -375,6 +375,37 @@ void TELY_DLL_Init(void *user_data)
Dqn_V2_InitNx2(map_hit_box.size.w, wall_thickness)); Dqn_V2_InitNx2(map_hit_box.size.w, wall_thickness));
} }
// NOTE: Map building zones
{
{
FP_Entity_CreatePermittedBuildZone(game,
Dqn_V2_InitNx2(0.f, -1206),
Dqn_V2_InitNx2(map_hit_box.size.w, 335),
"Building Zone");
}
{
FP_Entity_CreatePermittedBuildZone(game,
Dqn_V2_InitNx2(-839.9, -460),
Dqn_V2_InitNx2(2991.3, 670),
"Building Zone");
}
{
FP_Entity_CreatePermittedBuildZone(game,
Dqn_V2_InitNx2(-839.9, 460),
Dqn_V2_InitNx2(2991.3, 670),
"Building Zone");
}
{
FP_Entity_CreatePermittedBuildZone(game,
Dqn_V2_InitNx2(0.f, 1200),
Dqn_V2_InitNx2(map_hit_box.size.w, 335),
"Building Zone");
}
}
// NOTE: Hero ================================================================================== // NOTE: Hero ==================================================================================
{ {
FP_GameEntityHandle terry = FP_Entity_CreateTerry(game, Dqn_V2_InitNx2(1434, 11), "Terry"); FP_GameEntityHandle terry = FP_Entity_CreateTerry(game, Dqn_V2_InitNx2(1434, 11), "Terry");
@ -436,6 +467,7 @@ void TELY_DLL_Init(void *user_data)
FP_Entity_CreateHeart(game, base_mid_p, "Heart"); FP_Entity_CreateHeart(game, base_mid_p, "Heart");
uint16_t font_size = 18; uint16_t font_size = 18;
game->camera.scale = Dqn_V2_InitNx1(1); game->camera.scale = Dqn_V2_InitNx1(1);
game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size); game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), font_size);
@ -1553,6 +1585,8 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
TELY_Render_LineColourV4(renderer, start, end, TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, .25f), 1.f); TELY_Render_LineColourV4(renderer, start, end, TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, .25f), 1.f);
} }
TELY_Render_PushColourV4(renderer, TELY_COLOUR_BLACK_V4);
// NOTE: Draw entities ========================================================================= // NOTE: Draw entities =========================================================================
for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) { for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) {
FP_GameEntity *entity = it.entity; FP_GameEntity *entity = it.entity;
@ -1768,6 +1802,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Pos: (%.1f, %.1f)", world_pos.x, world_pos.y); draw_p.y += line_height; TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Pos: (%.1f, %.1f)", world_pos.x, world_pos.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Hit Box Size: %.1fx%.1f", world_hit_box.size.x, world_hit_box.size.y); draw_p.y += line_height; TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Hit Box Size: %.1fx%.1f", world_hit_box.size.x, world_hit_box.size.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Tile: %I32dx%I32d", player_tile.x, player_tile.y); draw_p.y += line_height; TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Tile: %I32dx%I32d", player_tile.x, player_tile.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Mouse Pos: (%.1f, %.1f)", world_mouse_p.x, world_mouse_p.y); draw_p.y += line_height;
} }
} }
} }

View File

@ -268,6 +268,42 @@ static FP_GameEntityHandle FP_Entity_CreateWallAtPos(FP_Game *game, Dqn_String8
return result; return result;
} }
static FP_GameEntityHandle FP_Entity_CreatePermittedBuildZone(FP_Game *game, Dqn_V2 pos, Dqn_V2 size, DQN_FMT_STRING_ANNOTATE char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
FP_GameEntity *entity = FP_Game_MakeEntityPointerFV(game, fmt, args);
FP_GameEntityHandle result = entity->handle;
va_end(args);
entity->local_pos = pos;
entity->local_hit_box_size = size;
entity->type = FP_EntityType_Nil;
entity->flags |= FP_GameEntityFlag_BuildZone;
FP_Entity_AddDebugEditorFlags(game, entity->handle);
FP_GameShape *wall = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
wall->type = FP_GameShapeType_Rect;
wall->p2 = entity->local_hit_box_size;
wall->colour = TELY_COLOUR_BLACK_V4;
Dqn_Rect local_hit_box = Dqn_Rect_InitV2x2(Dqn_V2_Zero, entity->local_hit_box_size);
FP_GameShape *line_1 = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
line_1->type = FP_GameShapeType_Line;
line_1->p1 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(0.f, 0.f)) - size * .5f;
line_1->p2 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(1.f, 1.f)) - size * .5f;
line_1->line_thickness = 1.f;
line_1->colour = TELY_COLOUR_BLACK_V4;
FP_GameShape *line_2 = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
line_2->type = FP_GameShapeType_Line;
line_2->p1 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(0.f, 1.f)) - size * .5f;
line_2->p2 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(1.f, 0.f)) - size * .5f;
line_2->line_thickness = 1.f;
line_2->colour = TELY_COLOUR_BLACK_V4;
return result;
}
static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos, Dqn_usize spawn_cap, char const *fmt, ...) static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos, Dqn_usize spawn_cap, char const *fmt, ...)
{ {
va_list args; va_list args;

View File

@ -21,6 +21,7 @@ enum FP_GameEntityFlag
FP_GameEntityFlag_ExperiencedClubTerry = 1 << 13, FP_GameEntityFlag_ExperiencedClubTerry = 1 << 13,
FP_GameEntityFlag_PointOfInterestHeart = 1 << 11, FP_GameEntityFlag_PointOfInterestHeart = 1 << 11,
FP_GameEntityFlag_CameraTracking = 1 << 14, FP_GameEntityFlag_CameraTracking = 1 << 14,
FP_GameEntityFlag_BuildZone = 1 << 15,
}; };
enum FP_GameShapeType enum FP_GameShapeType