From c5a76e6b9708a2a476e256ff0ea2f760ff9a67bc Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 1 Oct 2023 21:15:05 +1100 Subject: [PATCH] fp: Add walls to avoid going OOB --- feely_pona.cpp | 34 +++++++++++++++++++++++++++++++--- feely_pona_entity_create.cpp | 10 +++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index ee89007..e17becf 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -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; @@ -462,7 +490,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform if (entering_new_state) { TELY_AssetAnimatedSprite sprite = TELY_Asset_MakeAnimatedSprite(sheet, g_anim_names.terry_walk_right, TELY_AssetFlip_No); - uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame; + uint64_t duration_ms = sprite.anim->count * sprite.anim->ms_per_frame; FP_Game_EntityActionReset(game, entity->handle, duration_ms, sprite); Dqn_V2 dash_dir = {}; diff --git a/feely_pona_entity_create.cpp b/feely_pona_entity_create.cpp index 7430467..169bb20 100644 --- a/feely_pona_entity_create.cpp +++ b/feely_pona_entity_create.cpp @@ -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;