fp: Add walls to avoid going OOB
This commit is contained in:
parent
4f4868efb0
commit
c5a76e6b97
@ -280,7 +280,7 @@ void TELY_DLL_Init(void *user_data)
|
||||
game->root_entity = Dqn_VArray_Make(&game->entities, Dqn_ZeroMem_No);
|
||||
Dqn_FArray_Add(&game->parent_entity_stack, game->root_entity->handle);
|
||||
|
||||
// NOTE: Map
|
||||
// NOTE: Map ===================================================================================
|
||||
{
|
||||
TELY_AssetSpriteAnimation *sprite_anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.map);
|
||||
Dqn_Rect sprite_rect = game->atlas_sprite_sheet.rects.data[sprite_anim->index];
|
||||
@ -299,7 +299,35 @@ void TELY_DLL_Init(void *user_data)
|
||||
game->map = entity;
|
||||
}
|
||||
|
||||
// NOTE: Hero
|
||||
// NOTE: Map walls =============================================================================
|
||||
{
|
||||
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 half_wall_thickness = wall_thickness * .5f;
|
||||
|
||||
FP_Entity_CreateWallAtPos(game,
|
||||
DQN_STRING8("Left Wall"),
|
||||
Dqn_Rect_InterpolatedPoint(map_hit_box, Dqn_V2_InitNx2(0.f, 0.5f)) - Dqn_V2_InitNx2(half_wall_thickness, 0.f),
|
||||
Dqn_V2_InitNx2(wall_thickness, map_hit_box.size.h));
|
||||
|
||||
FP_Entity_CreateWallAtPos(game,
|
||||
DQN_STRING8("Right Wall"),
|
||||
Dqn_Rect_InterpolatedPoint(map_hit_box, Dqn_V2_InitNx2(1.f, 0.5f)) + Dqn_V2_InitNx2(half_wall_thickness, 0.f),
|
||||
Dqn_V2_InitNx2(wall_thickness, map_hit_box.size.h));
|
||||
|
||||
FP_Entity_CreateWallAtPos(game,
|
||||
DQN_STRING8("Top Wall"),
|
||||
Dqn_Rect_InterpolatedPoint(map_hit_box, Dqn_V2_InitNx2(0.5f, 0.f)) - Dqn_V2_InitNx2(0.f, half_wall_thickness),
|
||||
Dqn_V2_InitNx2(map_hit_box.size.w, wall_thickness));
|
||||
|
||||
FP_Entity_CreateWallAtPos(game,
|
||||
DQN_STRING8("Bottom Wall"),
|
||||
Dqn_Rect_InterpolatedPoint(map_hit_box, Dqn_V2_InitNx2(0.5f, 1.f)) + Dqn_V2_InitNx2(0.f, half_wall_thickness),
|
||||
Dqn_V2_InitNx2(map_hit_box.size.w, wall_thickness));
|
||||
}
|
||||
|
||||
// NOTE: Hero ==================================================================================
|
||||
{
|
||||
FP_GameEntityHandle terry = FP_Entity_CreateTerry(game, Dqn_V2_InitNx2(1434, 11), "Terry");
|
||||
game->clicked_entity = terry;
|
||||
|
@ -87,16 +87,12 @@ static FP_GameEntityHandle FP_Entity_CreateSmoochie(FP_Game *game, Dqn_V2 pos, D
|
||||
return result;
|
||||
}
|
||||
|
||||
static FP_GameEntityHandle FP_Entity_CreateWallAtTile(FP_Game *game, Dqn_String8 name, Dqn_V2I tile_pos, Dqn_V2I size_in_tiles)
|
||||
static FP_GameEntityHandle FP_Entity_CreateWallAtPos(FP_Game *game, Dqn_String8 name, Dqn_V2 pos, Dqn_V2 size)
|
||||
{
|
||||
Dqn_V2 size = Dqn_V2_InitV2I(size_in_tiles * DQN_CAST(int32_t) game->tile_size);
|
||||
Dqn_V2 world_pos = FP_Game_TilePosToWorldPos(game, tile_pos);
|
||||
world_pos += size * .5f;
|
||||
|
||||
FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, name.data);
|
||||
FP_GameEntityHandle result = entity->handle;
|
||||
entity->local_pos = world_pos;
|
||||
entity->local_hit_box_size = Dqn_V2_InitV2I(size_in_tiles * DQN_CAST(int32_t)game->tile_size);
|
||||
entity->local_pos = pos;
|
||||
entity->local_hit_box_size = size;
|
||||
FP_Entity_AddDebugEditorFlags(game, entity->handle);
|
||||
entity->flags |= FP_GameEntityFlag_NonTraversable;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user