fp: Add base walls

This commit is contained in:
doyle 2023-09-23 15:44:37 +10:00
parent 7d33baab4f
commit eceb4a3a21
3 changed files with 70 additions and 13 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit 30b2bb7f10bd8a53785d78a8bdbe919881ffbe2d
Subproject commit 2e846b010ab9c32e3792375aa5db23796201b3ee

View File

@ -505,20 +505,50 @@ void TELY_DLL_Init(void *user_data)
entity->flags |= FP_GameEntityFlag_NonTraversable;
}
game->tile_size = 37;
Dqn_V2I max_tile = platform->core.window_size / game->tile_size;
// NOTE: Wall
{
FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, "V. Wall");
entity->local_pos = Dqn_V2_InitNx2(100.f, 300.f);
entity->local_hit_box_size = Dqn_V2_InitNx2(100.f, 300.f);
entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
entity->flags |= FP_GameEntityFlag_MoveByMouse;
entity->flags |= FP_GameEntityFlag_NonTraversable;
Dqn_V2I vert_wall_tile_size = Dqn_V2I_InitNx2(1, 12);
Dqn_V2I right_wall_tile_pos = Dqn_V2I_InitNx2(max_tile.x - vert_wall_tile_size.x - 0, (max_tile.y / 2.f) - (vert_wall_tile_size.y * .5f));
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_GREEN_DARK_KHAKI_V4;
Dqn_V2I left_wall_top_tile = Dqn_V2I_InitNx2(max_tile.x - vert_wall_tile_size.x - 12, (max_tile.y / 2.f) - (vert_wall_tile_size.y * .5f));
Dqn_V2I left_wall_bottom_tile = Dqn_V2I_InitNx2(left_wall_top_tile.x, left_wall_top_tile.y + vert_wall_tile_size.y);
{
int32_t const base_width = right_wall_tile_pos.x - left_wall_top_tile.x;
Dqn_V2I const vert_wall_part_tile_size = Dqn_V2I_InitNx2(1, (vert_wall_tile_size.y / 2) - 2);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base left-top wall"), left_wall_top_tile, vert_wall_part_tile_size);
Dqn_V2I bottom_part_tile = Dqn_V2I_InitNx2(left_wall_top_tile.x, left_wall_top_tile.y + vert_wall_tile_size.y - vert_wall_part_tile_size.y);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base left-bottom wall"), bottom_part_tile, vert_wall_part_tile_size);
}
FP_GameEntityHandle right_wall = FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base right wall"), right_wall_tile_pos, vert_wall_tile_size);
Dqn_Rect right_wall_box = FP_Game_CalcEntityWorldHitBox(game, right_wall);
Dqn_V2I right_wall_bottom_tile = FP_Game_WorldPosToTilePos(game, right_wall_box.pos + Dqn_V2_InitNx2(0, right_wall_box.size.y));
Dqn_V2I right_wall_top_left_tile = FP_Game_WorldPosToTilePos(game, right_wall_box.pos);
{
Dqn_V2I hori_wall_tile_size = Dqn_V2I_InitNx2((right_wall_tile_pos.x - left_wall_top_tile.x - 1) / 2 - 1, 1);
{
Dqn_V2I bottom_left_wall_tile_pos = Dqn_V2I_InitNx2(left_wall_bottom_tile.x + 1, left_wall_bottom_tile.y - 1);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base bottom-left wall"), bottom_left_wall_tile_pos, hori_wall_tile_size);
Dqn_V2I bottom_right_wall_tile_pos = Dqn_V2I_InitNx2(right_wall_bottom_tile.x - hori_wall_tile_size.x, right_wall_bottom_tile.y - 1);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base bottom-right wall"), bottom_right_wall_tile_pos, hori_wall_tile_size);
}
{
Dqn_V2I top_left_wall_tile_pos = Dqn_V2I_InitNx2(left_wall_top_tile.x + 1, left_wall_top_tile.y);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base top-left wall"), top_left_wall_tile_pos, hori_wall_tile_size);
Dqn_V2I top_right_wall_tile_pos = Dqn_V2I_InitNx2(right_wall_top_left_tile.x - hori_wall_tile_size.x, right_wall_top_left_tile.y);
FP_Game_EntityAddWallAtTile(game, DQN_STRING8("Base top-right wall"), top_right_wall_tile_pos, hori_wall_tile_size);
}
}
}
uint16_t font_size = 18;
@ -527,7 +557,6 @@ void TELY_DLL_Init(void *user_data)
game->inter_italic_font = platform->func_load_font(assets, DQN_STRING8("Inter (Italic)"), DQN_STRING8("Data/Inter-Italic.otf"), font_size);
game->jetbrains_mono_font = platform->func_load_font(assets, DQN_STRING8("JetBrains Mono NL (Regular)"), DQN_STRING8("Data/JetBrainsMonoNL-Regular.ttf"), font_size);
game->test_audio = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa"));
game->tile_size = 37;
}
void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer, TELY_PlatformInput *input)

View File

@ -456,6 +456,12 @@ static Dqn_V2I FP_Game_WorldPosToTilePos(FP_Game *game, Dqn_V2 world_pos)
return result;
}
static Dqn_V2 FP_Game_TilePosToWorldPos(FP_Game *game, Dqn_V2I tile_pos)
{
Dqn_V2 result = Dqn_V2_InitNx2(tile_pos.x * game->tile_size, tile_pos.y * game->tile_size);
return result;
}
static Dqn_Slice<Dqn_V2I> FP_Game_AStarPathFind(FP_Game *game,
Dqn_Arena *arena,
TELY_Platform *platform,
@ -604,3 +610,25 @@ static Dqn_Slice<Dqn_V2I> FP_Game_AStarPathFind(FP_Game *game,
return result;
}
static FP_GameEntityHandle FP_Game_EntityAddWallAtTile(FP_Game *game, Dqn_String8 name, Dqn_V2I tile_pos, Dqn_V2I size_in_tiles)
{
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);
entity->local_pos = world_pos;
entity->local_hit_box_size = Dqn_V2_InitV2I(size_in_tiles * DQN_CAST(int32_t)game->tile_size);
entity->flags |= FP_GameEntityFlag_Clickable;
entity->flags |= FP_GameEntityFlag_MoveByKeyboard;
entity->flags |= FP_GameEntityFlag_MoveByMouse;
entity->flags |= FP_GameEntityFlag_NonTraversable;
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_GREEN_DARK_KHAKI_V4;
FP_GameEntityHandle result = entity->handle;
return result;
}