From 87fb216256e6c3eb28db033a5c620bf1b4b04c81 Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 8 Oct 2023 13:22:08 +1100 Subject: [PATCH] fp: Add intro screen and remove nil states --- feely_pona.cpp | 2365 +++++++++++++++++----------------- feely_pona_entity.h | 24 - feely_pona_entity_create.cpp | 146 ++- feely_pona_game.h | 19 +- 4 files changed, 1272 insertions(+), 1282 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 8420243..d6d5f95 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -351,17 +351,18 @@ void TELY_DLL_Init(void *user_data) 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]; - FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, "Map"); - entity->type = FP_EntityType_Map; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; - entity->local_pos = {}; + FP_GameEntity *entity = FP_Game_MakeEntityPointerF(game, "Map"); + entity->type = FP_EntityType_Map; + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + entity->local_pos = {}; Dqn_f32 size_scale = FP_Entity_CalcSpriteScaleForDesiredHeight(game, entity->sprite_height, sprite_rect); Dqn_V2 sprite_rect_scaled = sprite_rect.size * size_scale; entity->local_hit_box_size = sprite_rect_scaled; FP_Entity_AddDebugEditorFlags(game, entity->handle); - + FP_Game_EntityActionReset(game, entity->handle, FP_GAME_ENTITY_ACTION_INFINITE_TIMER, render_data.sprite); game->map = entity; } @@ -510,10 +511,12 @@ void TELY_DLL_Init(void *user_data) FP_Entity_CreateHeart(game, base_mid_p, "Heart"); uint16_t font_size = 18; + game->camera.world_pos = base_mid_p - Dqn_V2_InitV2I(platform->core.window_size * .5f); 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_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->inter_regular_font_large = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), DQN_CAST(uint16_t)(font_size * 5.f)); + game->inter_regular_font = platform->func_load_font(assets, DQN_STRING8("Inter (Regular)"), DQN_STRING8("Data/Inter-Regular.otf"), DQN_CAST(uint16_t)(font_size)); + // 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->talkco_font = platform->func_load_font(assets, DQN_STRING8("Talkco"), DQN_STRING8("Data/Talkco.otf"), font_size); game->talkco_font_large = platform->func_load_font(assets, DQN_STRING8("Talkco"), DQN_STRING8("Data/Talkco.otf"), DQN_CAST(uint16_t)(font_size * 1.5f)); game->audio[FP_GameAudio_TestAudio] = platform->func_load_audio(assets, DQN_STRING8("Test Audio"), DQN_STRING8("Data/Audio/Purrple Cat - Moonwinds.qoa")); @@ -537,8 +540,6 @@ FP_GetClosestPortalMonkeyResult FP_GetClosestPortalMonkey(FP_Game *game, FP_Game FP_GameEntity *portal_monkey = FP_Game_GetEntity(game, portal_monkey_handle); if (FP_Game_IsNilEntity(portal_monkey)) continue; - if (portal_monkey->action.state == FP_EntityPortalMonkeyState_DisablingPortal) - continue; Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, handle); Dqn_V2 portal_monkey_pos = FP_Game_CalcEntityWorldPos(game, portal_monkey_handle); Dqn_f32 dist_squared = Dqn_V2_LengthSq_V2x2(entity_pos, portal_monkey_pos); @@ -557,18 +558,10 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform FP_GameEntityAction *action = &entity->action; bool const we_are_clicked_entity = entity->handle == game->clicked_entity; bool const entity_has_velocity = entity->velocity.x || entity->velocity.y; - bool const entering_new_state = action->state != action->next_state; + bool const entering_new_state = entity->alive_time_s == 0.f || action->state != action->next_state; bool const action_has_finished = !entering_new_state && game->clock_ms >= action->end_at_clock_ms; action->state = action->next_state; - // NOTE: Left-shift lets us strafe in the same direction - if (!TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_LeftShift)) { - if (acceleration_meters_per_s->x) - entity->direction = acceleration_meters_per_s->x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left; - else if (acceleration_meters_per_s->y) - entity->direction = acceleration_meters_per_s->y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up; - } - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, entity->action.state, entity->direction); switch (entity->type) { case FP_EntityType_Terry: { @@ -585,10 +578,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform } switch (*state) { - case FP_EntityTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityTerryState_Idle); - } break; - case FP_EntityTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -596,7 +585,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform } if (we_are_clicked_entity) { - if (game->active_menu == FP_GameActiveMenu_Nil) { + if (game->in_game_menu == FP_GameInGameMenu_Nil) { bool picked_up_monkey_this_frame = false; if (FP_Game_IsNilEntityHandle(game, entity->carried_monkey)) { // NOTE: Check if we are nearby a monkey and picking it up @@ -663,7 +652,7 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform if (we_are_clicked_entity) { bool picked_up_monkey_this_frame = false; - if (game->active_menu == FP_GameActiveMenu_Nil) { + if (game->in_game_menu == FP_GameInGameMenu_Nil) { if (FP_Game_IsNilEntityHandle(game, entity->carried_monkey)) { // NOTE: Check if we are nearby a monkey and picking it up FP_GetClosestPortalMonkeyResult closest_monkey = FP_GetClosestPortalMonkey(game, entity->handle); @@ -742,31 +731,9 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform } break; - case FP_EntityType_PortalMonkey: { - FP_EntityPortalMonkeyState *state = DQN_CAST(FP_EntityPortalMonkeyState *) & action->state; - switch (*state) { - case FP_EntityPortalMonkeyState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntitySmoochieState_Idle); - } break; - - case FP_EntityPortalMonkeyState_Idle: { - } break; - - case FP_EntityPortalMonkeyState_BeingCarried: { - } break; - - case FP_EntityPortalMonkeyState_DisablingPortal: { - } break; - } - } break; - case FP_EntityType_Smoochie: { FP_EntitySmoochieState *state = DQN_CAST(FP_EntitySmoochieState *) & action->state; switch (*state) { - case FP_EntitySmoochieState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntitySmoochieState_Idle); - } break; - case FP_EntitySmoochieState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -888,10 +855,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_Clinger: { FP_EntityClingerState *state = DQN_CAST(FP_EntityClingerState *)&action->state; switch (*state) { - case FP_EntityClingerState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityClingerState_Idle); - } break; - case FP_EntityClingerState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -962,10 +925,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_MerchantTerry: { FP_EntityMerchantTerryState *state = DQN_CAST(FP_EntityMerchantTerryState *)&action->state; switch (*state) { - case FP_EntityMerchantTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMerchantTerryState_Idle); - } break; - case FP_EntityMerchantTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -979,10 +938,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_MerchantPhoneCompany: { FP_EntityMerchantPhoneCompanyState *state = DQN_CAST(FP_EntityMerchantPhoneCompanyState *)&action->state; switch (*state) { - case FP_EntityMerchantPhoneCompanyState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMerchantPhoneCompanyState_Idle); - } break; - case FP_EntityMerchantPhoneCompanyState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -995,10 +950,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_MerchantGym: { FP_EntityMerchantGymState *state = DQN_CAST(FP_EntityMerchantGymState *)&action->state; switch (*state) { - case FP_EntityMerchantGymState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMerchantGymState_Idle); - } break; - case FP_EntityMerchantGymState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1012,10 +963,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_MerchantGraveyard: { FP_EntityMerchantGraveyardState *state = DQN_CAST(FP_EntityMerchantGraveyardState *)&action->state; switch (*state) { - case FP_EntityMerchantGraveyardState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMerchantGraveyardState_Idle); - } break; - case FP_EntityMerchantGraveyardState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1029,10 +976,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_ClubTerry: { FP_EntityClubTerryState *state = DQN_CAST(FP_EntityClubTerryState *)&action->state; switch (*state) { - case FP_EntityClubTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityClubTerryState_Idle); - } break; - case FP_EntityClubTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1063,10 +1006,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_Map: { FP_EntityMapState *state = DQN_CAST(FP_EntityMapState *) & action->state; switch (*state) { - case FP_EntityMapState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMapState_Idle); - } break; - case FP_EntityMapState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1080,10 +1019,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_Heart: { FP_EntityHeartState *state = DQN_CAST(FP_EntityHeartState *) & action->state; switch (*state) { - case FP_EntityHeartState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityHeartState_Idle); - } break; - case FP_EntityHeartState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1096,10 +1031,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_AirportTerry: { FP_EntityAirportTerryState *state = DQN_CAST(FP_EntityAirportTerryState *)&action->state; switch (*state) { - case FP_EntityAirportTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityAirportTerryState_Idle); - } break; - case FP_EntityAirportTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1145,10 +1076,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_AirportTerryPlane: { FP_EntityAirportTerryPlaneState *state = DQN_CAST(FP_EntityAirportTerryPlaneState *)&action->state; switch (*state) { - case FP_EntityAirportTerryPlaneState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityAirportTerryPlaneState_Idle); - } break; - case FP_EntityAirportTerryPlaneState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1174,10 +1101,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_Catfish: { FP_EntityCatfishState *state = DQN_CAST(FP_EntityCatfishState *) & action->state; switch (*state) { - case FP_EntityCatfishState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityCatfishState_Idle); - } break; - case FP_EntityCatfishState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1247,10 +1170,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_ChurchTerry: { FP_EntityChurchTerryState *state = DQN_CAST(FP_EntityChurchTerryState *)&action->state; switch (*state) { - case FP_EntityChurchTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityChurchTerryState_Idle); - } break; - case FP_EntityChurchTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1282,10 +1201,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_KennelTerry: { FP_EntityKennelTerryState *state = DQN_CAST(FP_EntityKennelTerryState *)&action->state; switch (*state) { - case FP_EntityKennelTerryState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityKennelTerryState_Idle); - } break; - case FP_EntityKennelTerryState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1303,10 +1218,6 @@ void FP_EntityActionStateMachine(FP_Game *game, TELY_Audio *audio, TELY_Platform case FP_EntityType_MobSpawner: { FP_EntityMobSpawnerState *state = DQN_CAST(FP_EntityMobSpawnerState *)&action->state; switch (*state) { - case FP_EntityMobSpawnerState_Nil: { - FP_Game_EntityTransitionState(game, entity, FP_EntityMobSpawnerState_Idle); - } break; - case FP_EntityMobSpawnerState_Idle: { if (entering_new_state) { uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; @@ -1437,556 +1348,565 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input { Dqn_Profiler_ZoneScopeWithIndex("FP_Update", FP_ProfileZone_FPUpdate); - if (TELY_Platform_InputKeyIsReleased(input->mouse_left)) - game->clicked_entity = game->prev_active_entity; - game->update_counter++; - game->clock_ms = DQN_CAST(uint64_t)(platform->input.timer_s * 1000.f); - Dqn_V2 dir_vector = {}; - - // NOTE: Keyboard movement input - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_W)) - dir_vector.y = -1.f; - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_A)) - dir_vector.x = -1.f; - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_S)) - dir_vector.y = +1.f; - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_D)) - dir_vector.x = +1.f; - - // NOTE: Gamepad movement input - // NOTE: button_codes 0 should be the first gamepad connected, we can - // get this working with other gamepads later - uint32_t gamepad = 0; - if (input->button_codes[gamepad]) { - dir_vector.x += input->left_stick[gamepad].x; - dir_vector.y += input->left_stick[gamepad].y; - } - - // TODO(doyle): Some bug, diagonal is still faster - if (dir_vector.x && dir_vector.y) { - dir_vector.x *= 0.7071067811865475244f; - dir_vector.y *= 0.7071067811865475244f; - } - - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Escape)) - game->clicked_entity = {}; - - if (game->clicked_entity.id) { - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Delete)) - FP_Game_DeleteEntity(game, game->clicked_entity); - - // NOTE: Building selector - Dqn_usize last_building_index = DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS) - 1; - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Q)) { - if (game->build_mode_building_index <= 0) { - game->build_mode_building_index = last_building_index; - } else { - game->build_mode_building_index -= 1; - } - } - - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_E)) { - if (game->build_mode_building_index >= last_building_index) { - game->build_mode_building_index = 0; - } else { - game->build_mode_building_index += 1; - } - } - - } else { - Dqn_f32 pan_speed = 5.f; - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space)) - pan_speed *= 2.5f; - game->camera.world_pos += dir_vector * pan_speed; - - } - - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F1)) - game->debug_ui = !game->debug_ui; - + game->clock_ms = DQN_CAST(uint64_t)(platform->input.timer_s * 1000.f); Dqn_ProfilerZone update_zone = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: Entity loop"), FP_ProfileZone_FPUpdate_EntityLoop); + if (game->state == FP_GameState_Play) { + Dqn_V2 dir_vector = {}; + if (TELY_Platform_InputKeyIsReleased(input->mouse_left)) + game->clicked_entity = game->prev_active_entity; - // NOTE: Handle input ========================================================================== - for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) { - FP_GameEntity *entity = it.entity; - entity->alive_time_s += PHYSICS_STEP; + // NOTE: Keyboard movement input + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_W)) + dir_vector.y = -1.f; + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_A)) + dir_vector.x = -1.f; + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_S)) + dir_vector.y = +1.f; + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_D)) + dir_vector.x = +1.f; - if (entity->flags & FP_GameEntityFlag_OccupiedInBuilding) - continue; - - // NOTE: Move entity by keyboard and gamepad =============================================== - Dqn_V2 acceleration_meters_per_s = entity->constant_acceleration_per_s; - if (game->clicked_entity == entity->handle) { - if (entity->flags & (FP_GameEntityFlag_MoveByKeyboard | FP_GameEntityFlag_MoveByGamepad)) { - bool move_entity = true; - switch (entity->type) { - case FP_EntityType_Terry: { - auto *state = DQN_CAST(FP_EntityTerryState *)&entity->action.state; - move_entity = *state == FP_EntityTerryState_Run || *state == FP_EntityTerryState_Idle; - } break; - - case FP_EntityType_Smoochie: { - auto *state = DQN_CAST(FP_EntitySmoochieState *)&entity->action.state; - move_entity = *state == FP_EntitySmoochieState_Run || *state == FP_EntitySmoochieState_Idle; - } break; - - case FP_EntityType_Clinger: { - auto *state = DQN_CAST(FP_EntityClingerState *)&entity->action.state; - move_entity = *state == FP_EntityClingerState_Run || *state == FP_EntityClingerState_Idle; - } break; - - case FP_EntityType_Nil: break; - case FP_EntityType_ClubTerry: break; - case FP_EntityType_Count: break; - case FP_EntityType_Map: break; - case FP_EntityType_MerchantTerry: break; - case FP_EntityType_MerchantGraveyard: break; - case FP_EntityType_MerchantPhoneCompany: break; - case FP_EntityType_Heart: break; - case FP_EntityType_MerchantGym: break; - case FP_EntityType_AirportTerry: break; - case FP_EntityType_Catfish: break; - case FP_EntityType_ChurchTerry: break; - case FP_EntityType_KennelTerry: break; - case FP_EntityType_PhoneMessageProjectile: break; - case FP_EntityType_AirportTerryPlane: break; - } - - if (move_entity) { - acceleration_meters_per_s = dir_vector * entity->base_acceleration_per_s.meters; - if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space)) - acceleration_meters_per_s *= 2.5f; - } - } - } else { - if (entity->velocity.x) - entity->direction = entity->velocity.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left; - else if (entity->velocity.y) - entity->direction = entity->velocity.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up; + // NOTE: Gamepad movement input + // NOTE: button_codes 0 should be the first gamepad connected, we can + // get this working with other gamepads later + uint32_t gamepad = 0; + if (input->button_codes[gamepad]) { + dir_vector.x += input->left_stick[gamepad].x; + dir_vector.y += input->left_stick[gamepad].y; } - // NOTE: Determine AI movement ============================================================= - Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, entity->handle); - if (acceleration_meters_per_s.x == 0 && acceleration_meters_per_s.y == 0) { - if (entity->flags & FP_GameEntityFlag_Aggros && entity->faction != FP_GameEntityFaction_Nil) { - FP_GameFindClosestEntityResult closest_defender = {}; - closest_defender.dist_squared = DQN_F32_MAX; - closest_defender.pos = Dqn_V2_InitNx1(DQN_F32_MAX); + // TODO(doyle): Some bug, diagonal is still faster + if (dir_vector.x && dir_vector.y) { + dir_vector.x *= 0.7071067811865475244f; + dir_vector.y *= 0.7071067811865475244f; + } - FP_GameEntityFaction enemy_faction = - entity->faction == FP_GameEntityFaction_Friendly - ? FP_GameEntityFaction_Foe - : FP_GameEntityFaction_Friendly; + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Escape)) + game->clicked_entity = {}; - for (FP_GameEntityIterator defender_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &defender_it, game->root_entity); ) { - FP_GameEntity *it_entity = defender_it.entity; - Dqn_V2 pos = FP_Game_CalcEntityWorldPos(game, it_entity->handle); - Dqn_f32 dist = Dqn_V2_LengthSq_V2x2(pos, entity_pos); + if (game->clicked_entity.id) { + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Delete)) + FP_Game_DeleteEntity(game, game->clicked_entity); - if (it_entity->faction != enemy_faction) - continue; + // NOTE: Building selector + Dqn_usize last_building_index = DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS) - 1; + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Q)) { + if (game->build_mode_building_index <= 0) { + game->build_mode_building_index = last_building_index; + } else { + game->build_mode_building_index -= 1; + } + } - if (dist < closest_defender.dist_squared) { - closest_defender.pos = pos; - closest_defender.dist_squared = dist; - closest_defender.entity = it_entity->handle; + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_E)) { + if (game->build_mode_building_index >= last_building_index) { + game->build_mode_building_index = 0; + } else { + game->build_mode_building_index += 1; + } + } + + } else { + Dqn_f32 pan_speed = 5.f; + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space)) + pan_speed *= 2.5f; + game->camera.world_pos += dir_vector * pan_speed; + + } + + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F1)) + game->debug_ui = !game->debug_ui; + + // NOTE: Handle input ========================================================================== + for (FP_GameEntityIterator it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &it, game->root_entity); ) { + FP_GameEntity *entity = it.entity; + entity->alive_time_s += PHYSICS_STEP; + + if (entity->flags & FP_GameEntityFlag_OccupiedInBuilding) + continue; + + // NOTE: Move entity by keyboard and gamepad =============================================== + Dqn_V2 acceleration_meters_per_s = entity->constant_acceleration_per_s; + if (game->clicked_entity == entity->handle) { + if (entity->flags & (FP_GameEntityFlag_MoveByKeyboard | FP_GameEntityFlag_MoveByGamepad)) { + bool move_entity = true; + switch (entity->type) { + case FP_EntityType_Terry: { + auto *state = DQN_CAST(FP_EntityTerryState *)&entity->action.state; + move_entity = *state == FP_EntityTerryState_Run || *state == FP_EntityTerryState_Idle; + } break; + + case FP_EntityType_Smoochie: { + auto *state = DQN_CAST(FP_EntitySmoochieState *)&entity->action.state; + move_entity = *state == FP_EntitySmoochieState_Run || *state == FP_EntitySmoochieState_Idle; + } break; + + case FP_EntityType_Clinger: { + auto *state = DQN_CAST(FP_EntityClingerState *)&entity->action.state; + move_entity = *state == FP_EntityClingerState_Run || *state == FP_EntityClingerState_Idle; + } break; + + case FP_EntityType_Nil: break; + case FP_EntityType_ClubTerry: break; + case FP_EntityType_Count: break; + case FP_EntityType_Map: break; + case FP_EntityType_MerchantTerry: break; + case FP_EntityType_MerchantGraveyard: break; + case FP_EntityType_MerchantPhoneCompany: break; + case FP_EntityType_Heart: break; + case FP_EntityType_MerchantGym: break; + case FP_EntityType_AirportTerry: break; + case FP_EntityType_Catfish: break; + case FP_EntityType_ChurchTerry: break; + case FP_EntityType_KennelTerry: break; + case FP_EntityType_PhoneMessageProjectile: break; + case FP_EntityType_AirportTerryPlane: break; + } + + if (move_entity) { + acceleration_meters_per_s = dir_vector * entity->base_acceleration_per_s.meters; + if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space)) + acceleration_meters_per_s *= 2.5f; + } + } + } else { + if (entity->velocity.x) + entity->direction = entity->velocity.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left; + else if (entity->velocity.y) + entity->direction = entity->velocity.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up; + } + + // NOTE: Determine AI movement ============================================================= + Dqn_V2 entity_pos = FP_Game_CalcEntityWorldPos(game, entity->handle); + if (acceleration_meters_per_s.x == 0 && acceleration_meters_per_s.y == 0) { + if (entity->flags & FP_GameEntityFlag_Aggros && entity->faction != FP_GameEntityFaction_Nil) { + FP_GameFindClosestEntityResult closest_defender = {}; + closest_defender.dist_squared = DQN_F32_MAX; + closest_defender.pos = Dqn_V2_InitNx1(DQN_F32_MAX); + + FP_GameEntityFaction enemy_faction = + entity->faction == FP_GameEntityFaction_Friendly + ? FP_GameEntityFaction_Foe + : FP_GameEntityFaction_Friendly; + + for (FP_GameEntityIterator defender_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &defender_it, game->root_entity); ) { + FP_GameEntity *it_entity = defender_it.entity; + Dqn_V2 pos = FP_Game_CalcEntityWorldPos(game, it_entity->handle); + Dqn_f32 dist = Dqn_V2_LengthSq_V2x2(pos, entity_pos); + + if (it_entity->faction != enemy_faction) + continue; + + if (dist < closest_defender.dist_squared) { + closest_defender.pos = pos; + closest_defender.dist_squared = dist; + closest_defender.entity = it_entity->handle; + } + } + + Dqn_f32 aggro_dist_threshold = FP_Game_MetersToPixelsNx1(game, 4.f); + if (closest_defender.dist_squared < DQN_SQUARED(aggro_dist_threshold)) { + bool has_waypoint_to_defender = false; + for (FP_SentinelListLink *link = nullptr; + !has_waypoint_to_defender && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { + has_waypoint_to_defender = link->data.entity == closest_defender.entity; + } + + if (!has_waypoint_to_defender) { + FP_GameEntity *defender = FP_Game_GetEntity(game, closest_defender.entity); + FP_GameDirection aggro_direction = FP_GameDirection_Count; + DQN_FOR_UINDEX(dir_index, FP_GameDirection_Count) { + FP_GameEntityHandle slot_entity_handle = defender->aggro_slot[dir_index]; + FP_GameEntity *slot_entity = FP_Game_GetEntity(game, slot_entity_handle); + if (FP_Game_IsNilEntity(slot_entity)) { + aggro_direction = DQN_CAST(FP_GameDirection)dir_index; + break; + } + } + + FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, + FP_SentinelList_Front(&entity->waypoints), + game->chunk_pool); + FP_GameWaypoint *waypoint = &link->data; + waypoint->entity = defender->handle; + if (aggro_direction != FP_GameDirection_Count) { + waypoint->type = FP_GameWaypointType_Side; + waypoint->type_direction = aggro_direction; + defender->aggro_slot[aggro_direction] = entity->handle; + } + } + } else { + if (closest_defender.dist_squared > DQN_SQUARED(aggro_dist_threshold * 2.f)) { + for (FP_SentinelListLink *link = nullptr; FP_SentinelList_Iterate(&entity->waypoints, &link); ) { + FP_GameEntity *maybe_terry = FP_Game_GetEntity(game, link->data.entity); + if (maybe_terry->type == FP_EntityType_Terry) { + link = FP_SentinelList_Erase(&entity->waypoints, link, game->chunk_pool); + } + } + } } } - Dqn_f32 aggro_dist_threshold = FP_Game_MetersToPixelsNx1(game, 4.f); - if (closest_defender.dist_squared < DQN_SQUARED(aggro_dist_threshold)) { - bool has_waypoint_to_defender = false; - for (FP_SentinelListLink *link = nullptr; - !has_waypoint_to_defender && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { - has_waypoint_to_defender = link->data.entity == closest_defender.entity; + if (entity->flags & FP_GameEntityFlag_RespondsToBuildings) { + FP_GameFindClosestEntityResult closest_building = {}; + closest_building.dist_squared = DQN_F32_MAX; + closest_building.pos = Dqn_V2_InitNx1(DQN_F32_MAX); + + for (FP_GameEntityIterator building_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &building_it, game->root_entity); ) { + FP_GameEntity *it_entity = building_it.entity; + if (it_entity->type != FP_EntityType_ClubTerry && + it_entity->type != FP_EntityType_AirportTerry && + it_entity->type != FP_EntityType_ChurchTerry) + continue; + + // NOTE: Already converted, we cannot attend church again + if (entity->converted_faction && it_entity->type == FP_EntityType_ChurchTerry) { + continue; + } + + bool already_visited_building = false; + for (FP_SentinelListLink *link_it = {}; + !already_visited_building && FP_SentinelList_Iterate(&entity->buildings_visited, &link_it); + ) { + FP_GameEntityHandle visit_item = link_it->data; + already_visited_building = visit_item == it_entity->handle; + } + + if (already_visited_building) + continue; + + Dqn_V2 pos = FP_Game_CalcEntityWorldPos(game, it_entity->handle); + Dqn_f32 dist = Dqn_V2_LengthSq_V2x2(pos, entity_pos); + if (dist < closest_building.dist_squared) { + closest_building.pos = pos; + closest_building.dist_squared = dist; + closest_building.entity = it_entity->handle; + } } - if (!has_waypoint_to_defender) { - FP_GameEntity *defender = FP_Game_GetEntity(game, closest_defender.entity); - FP_GameDirection aggro_direction = FP_GameDirection_Count; - DQN_FOR_UINDEX(dir_index, FP_GameDirection_Count) { - FP_GameEntityHandle slot_entity_handle = defender->aggro_slot[dir_index]; - FP_GameEntity *slot_entity = FP_Game_GetEntity(game, slot_entity_handle); - if (FP_Game_IsNilEntity(slot_entity)) { - aggro_direction = DQN_CAST(FP_GameDirection)dir_index; + if (!FP_Game_IsNilEntityHandle(game, closest_building.entity) && + closest_building.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 5.f))) { + + bool has_waypoint_to_building = false; + for (FP_SentinelListLink *link = nullptr; + !has_waypoint_to_building && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { + has_waypoint_to_building = link->data.entity == closest_building.entity; + } + + if (!has_waypoint_to_building) { + Dqn_Rect hit_box = FP_Game_CalcEntityWorldHitBox(game, closest_building.entity); + Dqn_V2 top_left = Dqn_Rect_TopLeft(hit_box); + Dqn_V2 top_right = Dqn_Rect_TopRight(hit_box); + + FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, FP_SentinelList_Front(&entity->waypoints), game->chunk_pool); + FP_GameWaypoint *waypoint = &link->data; + waypoint->entity = closest_building.entity; + waypoint->type = FP_GameWaypointType_Side; + + + uint32_t *direction_hit_count = nullptr; + FP_GameDirection least_encountered_direction = FP_GameDirection_Down; + + DQN_FOR_UINDEX(dir_index, FP_GameDirection_Count) { + FP_GameEntity *waypoint_entity = FP_Game_GetEntity(game, waypoint->entity); + uint32_t *hit_count = waypoint_entity->count_of_entities_targetting_sides + dir_index; + if (!direction_hit_count || *hit_count < *direction_hit_count) { + direction_hit_count = hit_count; + least_encountered_direction = DQN_CAST(FP_GameDirection)dir_index; + } else if (hit_count == direction_hit_count) { + if (Dqn_PCG32_NextF32(&game->rng) >= 0.5f) { + direction_hit_count = hit_count; + least_encountered_direction = DQN_CAST(FP_GameDirection)dir_index; + } + } + } + + waypoint->type_direction = least_encountered_direction; + (*direction_hit_count)++; + } + } + } + + if (entity->flags & FP_GameEntityFlag_PointOfInterestHeart) { + FP_GameFindClosestEntityResult closest_heart = FP_Game_FindClosestEntityWithType(game, entity->handle, FP_EntityType_Heart); + if (closest_heart.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 4.f))) { + + bool has_waypoint_to = false; + for (FP_SentinelListLink *link = nullptr; + !has_waypoint_to && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { + has_waypoint_to = link->data.entity == closest_heart.entity; + } + + if (!has_waypoint_to) { + Dqn_Rect club_hit_box = FP_Game_CalcEntityWorldHitBox(game, closest_heart.entity); + Dqn_V2 club_top_left = Dqn_Rect_TopLeft(club_hit_box); + Dqn_V2 club_top_right = Dqn_Rect_TopRight(club_hit_box); + + FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, FP_SentinelList_Front(&entity->waypoints), game->chunk_pool); + FP_GameWaypoint *waypoint = &link->data; + waypoint->entity = closest_heart.entity; + waypoint->type = FP_GameWaypointType_ClosestSide; + } + } + } + + while (entity->waypoints.size) { + FP_SentinelListLink *waypoint_link = entity->waypoints.sentinel->next; + FP_GameWaypoint const *waypoint = &waypoint_link->data; + FP_GameEntity *waypoint_entity = FP_Game_GetEntity(game, waypoint_link->data.entity); + if (FP_Game_IsNilEntity(waypoint_entity)) { + FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); + continue; + } + + // NOTE: We found a waypoint that is valid to move towards + Dqn_V2 target_pos = FP_Game_CalcWaypointWorldPos(game, entity->handle, waypoint); + Dqn_V2 entity_to_waypoint = target_pos - entity_pos; + + // NOTE: Check if we've arrived at the waypoint + Dqn_f32 dist_to_waypoint_sq = Dqn_V2_LengthSq(entity_to_waypoint); + + Dqn_f32 arrival_threshold = {}; + switch (waypoint->arrive) { + case FP_GameWaypointArrive_Default: { + arrival_threshold = FP_Game_MetersToPixelsNx1(game, 0.5f); + } break; + + case FP_GameWaypointArrive_WhenWithinEntitySize: { + arrival_threshold = DQN_MAX(waypoint_entity->local_hit_box_size.w, waypoint_entity->local_hit_box_size.h) * waypoint_link->data.value; + } break; + } + + // NOTE: We haven't arrived yet, calculate an acceleration vector to the waypoint + if (dist_to_waypoint_sq > DQN_SQUARED(arrival_threshold)) { + Dqn_V2 entity_to_waypoint_norm = Dqn_V2_Normalise(entity_to_waypoint); + acceleration_meters_per_s = entity_to_waypoint_norm * (entity->base_acceleration_per_s.meters * 0.25f); + break; + } + + // NOTE: We have arrived at the waypoint + bool aggro = false; + if (entity->flags & FP_GameEntityFlag_Aggros) { + aggro |= entity->faction == FP_GameEntityFaction_Friendly && waypoint_entity->faction & FP_GameEntityFaction_Foe; + aggro |= entity->faction == FP_GameEntityFaction_Foe && waypoint_entity->faction & FP_GameEntityFaction_Friendly; + } + + bool building_response = (entity->flags & FP_GameEntityFlag_RespondsToBuildings) && + waypoint_entity->type == FP_EntityType_ClubTerry || + waypoint_entity->type == FP_EntityType_AirportTerry || + waypoint_entity->type == FP_EntityType_ChurchTerry; + bool heart_response = (entity->flags & FP_GameEntityFlag_PointOfInterestHeart) && waypoint_entity->type == FP_EntityType_Heart; + + if (((waypoint->flags & FP_GameWaypointFlag_NonInterruptible) == 0) && (aggro || building_response || heart_response)) { + bool can_attack = !entity->is_dying; // TODO(doyle): State transition needs to check if it's valid to move to making this not necessary + if (building_response) { + FP_GameEntity *building = waypoint_entity; + if (FP_Game_IsNilEntityHandle(game, building->building_patron)) { + building->building_patron = entity->handle; + + Dqn_Rect hit_box = FP_Game_CalcEntityWorldHitBox(game, building->handle); + Dqn_V2 exit_pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(0.5f, 1.1f)); + if (building->type == FP_EntityType_ClubTerry) { + FP_Game_EntityTransitionState(game, building, FP_EntityClubTerryState_PartyTime); + entity->local_pos = exit_pos; // TODO(doyle): Only works when parent world pos is 0,0 + } else if (building->type == FP_EntityType_AirportTerry) { + FP_Game_EntityTransitionState(game, building, FP_EntityAirportTerryState_FlyPassenger); + entity->local_pos = exit_pos; // TODO(doyle): Only works when parent world pos is 0,0 + } else { + DQN_ASSERT(building->type == FP_EntityType_ChurchTerry); + FP_Game_EntityTransitionState(game, building, FP_EntityChurchTerryState_ConvertPatron); + } + + entity->flags |= FP_GameEntityFlag_OccupiedInBuilding; + can_attack = false; + FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); + FP_SentinelList_Add(&entity->buildings_visited, game->chunk_pool, building->handle); + } + } + + if (can_attack) { + Dqn_V2 attack_dir_vectors[FP_GameDirection_Count] = {}; + attack_dir_vectors[FP_GameDirection_Up] = Dqn_V2_InitNx2(+0, -1); + attack_dir_vectors[FP_GameDirection_Down] = Dqn_V2_InitNx2(+0, +1); + attack_dir_vectors[FP_GameDirection_Left] = Dqn_V2_InitNx2(-1, +0); + attack_dir_vectors[FP_GameDirection_Right] = Dqn_V2_InitNx2(+1, +0); + + Dqn_V2 defender_entity_pos = FP_Game_CalcEntityWorldPos(game, waypoint_entity->handle); + Dqn_V2 entity_to_defender = defender_entity_pos - entity_pos; + Dqn_V2 entity_to_defender_norm = Dqn_V2_Normalise(entity_to_defender); + + FP_GameDirection best_attack_dir = FP_GameDirection_Up; + Dqn_f32 best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector = -1.1f; + DQN_FOR_UINDEX (dir_index, FP_GameDirection_Count) { + Dqn_V2 attack_dir = attack_dir_vectors[dir_index]; + Dqn_f32 scalar_projection = Dqn_V2_Dot(attack_dir, entity_to_defender_norm); + if (scalar_projection > best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector) { + best_attack_dir = DQN_CAST(FP_GameDirection)dir_index; + best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector = scalar_projection; + } + } + + switch (entity->type) { + case FP_EntityType_Terry: /*FALLTHRU*/ + case FP_EntityType_Smoochie: /*FALLTHRU*/ + case FP_EntityType_Catfish: /*FALLTHRU*/ + case FP_EntityType_Clinger: { + // TODO(doyle): We should check if it's valid to enter this new state + // from the entity's current state + if (entity->type == FP_EntityType_Terry) { + FP_Game_EntityTransitionState(game, entity, FP_EntityTerryState_Attack); + } else if (entity->type == FP_EntityType_Smoochie) { + FP_Game_EntityTransitionState(game, entity, FP_EntitySmoochieState_Attack); + } else if (entity->type == FP_EntityType_Catfish) { + FP_Game_EntityTransitionState(game, entity, FP_EntityCatfishState_Attack); + } else { + DQN_ASSERT(entity->type == FP_EntityType_Clinger); + FP_Game_EntityTransitionState(game, entity, FP_EntityClingerState_Attack); + } + entity->direction = best_attack_dir; + } break; + + case FP_EntityType_Nil: break; + case FP_EntityType_ClubTerry: break; + case FP_EntityType_Map: break; + case FP_EntityType_Heart: break; + case FP_EntityType_MerchantTerry: break; + case FP_EntityType_MerchantGraveyard: break; + case FP_EntityType_MerchantGym: break; + case FP_EntityType_MerchantPhoneCompany: break; + case FP_EntityType_AirportTerry: break; + case FP_EntityType_ChurchTerry: break; + case FP_EntityType_KennelTerry: break; + case FP_EntityType_PhoneMessageProjectile: break; + case FP_EntityType_Count: DQN_INVALID_CODE_PATH; break; + } + } + + // NOTE: Aggro makes the entity attack, we will exit here preserving the waypoint in the entity. + break; + } else { + FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); + } + } + } + + // NOTE: Move entity by mouse ============================================================== + if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) { + entity->velocity = {}; + acceleration_meters_per_s = {}; + entity->local_pos += input->mouse_p_delta; + } + + if (game->clicked_entity == entity->handle) { + if (game->in_game_menu == FP_GameInGameMenu_Nil || game->in_game_menu == FP_GameInGameMenu_Build) { + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_H)) + game->in_game_menu = DQN_CAST(FP_GameInGameMenu)(DQN_CAST(uint32_t)game->in_game_menu ^ FP_GameInGameMenu_Build); + } + + if (entity->flags & FP_GameEntityFlag_CameraTracking) + game->camera.world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) - Dqn_V2_InitV2I(platform->core.window_size) * .5f; + + FP_GamePlaceableBuilding placeable_building = PLACEABLE_BUILDINGS[game->build_mode_building_index]; + game->build_mode_can_place_building = false; + + uint8_t *inventory_count = nullptr; + if (placeable_building.type == FP_EntityType_ChurchTerry) + inventory_count = &entity->inventory.churchs; + else if (placeable_building.type == FP_EntityType_KennelTerry) + inventory_count = &entity->inventory.kennels; + else if (placeable_building.type == FP_EntityType_ClubTerry) + inventory_count = &entity->inventory.clubs; + else if (placeable_building.type == FP_EntityType_AirportTerry) + inventory_count = &entity->inventory.airports; + + bool have_building_inventory = inventory_count && (*inventory_count) > 0; + if (have_building_inventory && game->in_game_menu == FP_GameInGameMenu_Build) { + Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, placeable_building, entity->handle); + Dqn_V2 placement_pos = Dqn_Rect_Center(dest_rect); + + for (FP_GameEntityIterator zone_it = {}; + FP_Game_DFSPreOrderWalkEntityTree(game, &zone_it, game->root_entity); + ) { + + FP_GameEntity *zone = zone_it.entity; + bool is_building = zone->type == FP_EntityType_KennelTerry || + zone->type == FP_EntityType_AirportTerry || + zone->type == FP_EntityType_ChurchTerry || + zone->type == FP_EntityType_ClubTerry; + + Dqn_Rect zone_hit_box = FP_Game_CalcEntityWorldHitBox(game, zone->handle); + if (is_building) { + if (Dqn_Rect_Intersects(zone_hit_box, dest_rect)) { + game->build_mode_can_place_building = false; break; } } - FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, - FP_SentinelList_Front(&entity->waypoints), - game->chunk_pool); - FP_GameWaypoint *waypoint = &link->data; - waypoint->entity = defender->handle; - if (aggro_direction != FP_GameDirection_Count) { - waypoint->type = FP_GameWaypointType_Side; - waypoint->type_direction = aggro_direction; - defender->aggro_slot[aggro_direction] = entity->handle; - } + if ((zone->flags & FP_GameEntityFlag_BuildZone) == 0) + continue; + + 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); } - } else { - if (closest_defender.dist_squared > DQN_SQUARED(aggro_dist_threshold * 2.f)) { - for (FP_SentinelListLink *link = nullptr; FP_SentinelList_Iterate(&entity->waypoints, &link); ) { - FP_GameEntity *maybe_terry = FP_Game_GetEntity(game, link->data.entity); - if (maybe_terry->type == FP_EntityType_Terry) { - link = FP_SentinelList_Erase(&entity->waypoints, link, game->chunk_pool); - } + + if (game->build_mode_can_place_building && + TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) { + if (placeable_building.type == FP_EntityType_ClubTerry) { + FP_Entity_CreateClubTerry(game, placement_pos, "Club Terry"); + } else if (placeable_building.type == FP_EntityType_ChurchTerry) { + FP_Entity_CreateChurchTerry(game, placement_pos, "Church Terry"); + } else if (placeable_building.type == FP_EntityType_AirportTerry) { + FP_Entity_CreateAirportTerry(game, placement_pos, "Airport Terry"); + } else { + DQN_ASSERT(placeable_building.type == FP_EntityType_KennelTerry); + FP_Entity_CreateKennelTerry(game, placement_pos, "Kennel Terry"); } + + (*inventory_count)--; } } } - if (entity->flags & FP_GameEntityFlag_RespondsToBuildings) { - FP_GameFindClosestEntityResult closest_building = {}; - closest_building.dist_squared = DQN_F32_MAX; - closest_building.pos = Dqn_V2_InitNx1(DQN_F32_MAX); - - for (FP_GameEntityIterator building_it = {}; FP_Game_DFSPostOrderWalkEntityTree(game, &building_it, game->root_entity); ) { - FP_GameEntity *it_entity = building_it.entity; - if (it_entity->type != FP_EntityType_ClubTerry && - it_entity->type != FP_EntityType_AirportTerry && - it_entity->type != FP_EntityType_ChurchTerry) - continue; - - // NOTE: Already converted, we cannot attend church again - if (entity->converted_faction && it_entity->type == FP_EntityType_ChurchTerry) { - continue; - } - - bool already_visited_building = false; - for (FP_SentinelListLink *link_it = {}; - !already_visited_building && FP_SentinelList_Iterate(&entity->buildings_visited, &link_it); - ) { - FP_GameEntityHandle visit_item = link_it->data; - already_visited_building = visit_item == it_entity->handle; - } - - if (already_visited_building) - continue; - - Dqn_V2 pos = FP_Game_CalcEntityWorldPos(game, it_entity->handle); - Dqn_f32 dist = Dqn_V2_LengthSq_V2x2(pos, entity_pos); - if (dist < closest_building.dist_squared) { - closest_building.pos = pos; - closest_building.dist_squared = dist; - closest_building.entity = it_entity->handle; - } - } - - if (!FP_Game_IsNilEntityHandle(game, closest_building.entity) && - closest_building.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 5.f))) { - - bool has_waypoint_to_building = false; - for (FP_SentinelListLink *link = nullptr; - !has_waypoint_to_building && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { - has_waypoint_to_building = link->data.entity == closest_building.entity; - } - - if (!has_waypoint_to_building) { - Dqn_Rect hit_box = FP_Game_CalcEntityWorldHitBox(game, closest_building.entity); - Dqn_V2 top_left = Dqn_Rect_TopLeft(hit_box); - Dqn_V2 top_right = Dqn_Rect_TopRight(hit_box); - - FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, FP_SentinelList_Front(&entity->waypoints), game->chunk_pool); - FP_GameWaypoint *waypoint = &link->data; - waypoint->entity = closest_building.entity; - waypoint->type = FP_GameWaypointType_Side; - - - uint32_t *direction_hit_count = nullptr; - FP_GameDirection least_encountered_direction = FP_GameDirection_Down; - - DQN_FOR_UINDEX(dir_index, FP_GameDirection_Count) { - FP_GameEntity *waypoint_entity = FP_Game_GetEntity(game, waypoint->entity); - uint32_t *hit_count = waypoint_entity->count_of_entities_targetting_sides + dir_index; - if (!direction_hit_count || *hit_count < *direction_hit_count) { - direction_hit_count = hit_count; - least_encountered_direction = DQN_CAST(FP_GameDirection)dir_index; - } else if (hit_count == direction_hit_count) { - if (Dqn_PCG32_NextF32(&game->rng) >= 0.5f) { - direction_hit_count = hit_count; - least_encountered_direction = DQN_CAST(FP_GameDirection)dir_index; - } - } - } - - waypoint->type_direction = least_encountered_direction; - (*direction_hit_count)++; - } + if (!FP_Game_IsNilEntityHandle(game, entity->carried_monkey) && entity->type != FP_EntityType_MobSpawner) { + FP_GameFindClosestEntityResult closest_portal = FP_Game_FindClosestEntityWithType(game, entity->carried_monkey, game->mob_spawners.data, game->mob_spawners.size); + if (closest_portal.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 1.f))) { + FP_GameEntity *portal = FP_Game_GetEntity(game, closest_portal.entity); + portal->carried_monkey = entity->carried_monkey; + entity->carried_monkey = {}; } + acceleration_meters_per_s *= 2.f; // TODO(doyle): Penalise the player + } else { + acceleration_meters_per_s *= 1.f; // TODO(doyle): Penalise the player } - if (entity->flags & FP_GameEntityFlag_PointOfInterestHeart) { - FP_GameFindClosestEntityResult closest_heart = FP_Game_FindClosestEntityWithType(game, entity->handle, FP_EntityType_Heart); - if (closest_heart.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 4.f))) { - - bool has_waypoint_to = false; - for (FP_SentinelListLink *link = nullptr; - !has_waypoint_to && FP_SentinelList_Iterate(&entity->waypoints, &link); ) { - has_waypoint_to = link->data.entity == closest_heart.entity; - } - - if (!has_waypoint_to) { - Dqn_Rect club_hit_box = FP_Game_CalcEntityWorldHitBox(game, closest_heart.entity); - Dqn_V2 club_top_left = Dqn_Rect_TopLeft(club_hit_box); - Dqn_V2 club_top_right = Dqn_Rect_TopRight(club_hit_box); - - FP_SentinelListLink *link = FP_SentinelList_MakeBefore(&entity->waypoints, FP_SentinelList_Front(&entity->waypoints), game->chunk_pool); - FP_GameWaypoint *waypoint = &link->data; - waypoint->entity = closest_heart.entity; - waypoint->type = FP_GameWaypointType_ClosestSide; - } - } + // NOTE: Left-shift lets us strafe in the same direction + if (!TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_LeftShift)) { + if (acceleration_meters_per_s.x) + entity->direction = acceleration_meters_per_s.x > 0.f ? FP_GameDirection_Right : FP_GameDirection_Left; + else if (acceleration_meters_per_s.y) + entity->direction = acceleration_meters_per_s.y > 0.f ? FP_GameDirection_Down : FP_GameDirection_Up; } - while (entity->waypoints.size) { - FP_SentinelListLink *waypoint_link = entity->waypoints.sentinel->next; - FP_GameWaypoint const *waypoint = &waypoint_link->data; - FP_GameEntity *waypoint_entity = FP_Game_GetEntity(game, waypoint_link->data.entity); - if (FP_Game_IsNilEntity(waypoint_entity)) { - FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); - continue; - } - // NOTE: We found a waypoint that is valid to move towards - Dqn_V2 target_pos = FP_Game_CalcWaypointWorldPos(game, entity->handle, waypoint); - Dqn_V2 entity_to_waypoint = target_pos - entity_pos; + // NOTE: Tick the state machine + // NOTE: This can delete the entity! Take caution + FP_GameEntityHandle entity_handle = entity->handle; + FP_EntityActionStateMachine(game, &platform->audio, input, entity, &acceleration_meters_per_s); - // NOTE: Check if we've arrived at the waypoint - Dqn_f32 dist_to_waypoint_sq = Dqn_V2_LengthSq(entity_to_waypoint); - - Dqn_f32 arrival_threshold = {}; - switch (waypoint->arrive) { - case FP_GameWaypointArrive_Default: { - arrival_threshold = FP_Game_MetersToPixelsNx1(game, 0.5f); - } break; - - case FP_GameWaypointArrive_WhenWithinEntitySize: { - arrival_threshold = DQN_MAX(waypoint_entity->local_hit_box_size.w, waypoint_entity->local_hit_box_size.h) * waypoint_link->data.value; - } break; - } - - // NOTE: We haven't arrived yet, calculate an acceleration vector to the waypoint - if (dist_to_waypoint_sq > DQN_SQUARED(arrival_threshold)) { - Dqn_V2 entity_to_waypoint_norm = Dqn_V2_Normalise(entity_to_waypoint); - acceleration_meters_per_s = entity_to_waypoint_norm * (entity->base_acceleration_per_s.meters * 0.25f); - break; - } - - // NOTE: We have arrived at the waypoint - bool aggro = false; - if (entity->flags & FP_GameEntityFlag_Aggros) { - aggro |= entity->faction == FP_GameEntityFaction_Friendly && waypoint_entity->faction & FP_GameEntityFaction_Foe; - aggro |= entity->faction == FP_GameEntityFaction_Foe && waypoint_entity->faction & FP_GameEntityFaction_Friendly; - } - - bool building_response = (entity->flags & FP_GameEntityFlag_RespondsToBuildings) && - waypoint_entity->type == FP_EntityType_ClubTerry || - waypoint_entity->type == FP_EntityType_AirportTerry || - waypoint_entity->type == FP_EntityType_ChurchTerry; - bool heart_response = (entity->flags & FP_GameEntityFlag_PointOfInterestHeart) && waypoint_entity->type == FP_EntityType_Heart; - - if (((waypoint->flags & FP_GameWaypointFlag_NonInterruptible) == 0) && (aggro || building_response || heart_response)) { - bool can_attack = !entity->is_dying; // TODO(doyle): State transition needs to check if it's valid to move to making this not necessary - if (building_response) { - FP_GameEntity *building = waypoint_entity; - if (FP_Game_IsNilEntityHandle(game, building->building_patron)) { - building->building_patron = entity->handle; - - Dqn_Rect hit_box = FP_Game_CalcEntityWorldHitBox(game, building->handle); - Dqn_V2 exit_pos = Dqn_Rect_InterpolatedPoint(hit_box, Dqn_V2_InitNx2(0.5f, 1.1f)); - if (building->type == FP_EntityType_ClubTerry) { - FP_Game_EntityTransitionState(game, building, FP_EntityClubTerryState_PartyTime); - entity->local_pos = exit_pos; // TODO(doyle): Only works when parent world pos is 0,0 - } else if (building->type == FP_EntityType_AirportTerry) { - FP_Game_EntityTransitionState(game, building, FP_EntityAirportTerryState_FlyPassenger); - entity->local_pos = exit_pos; // TODO(doyle): Only works when parent world pos is 0,0 - } else { - DQN_ASSERT(building->type == FP_EntityType_ChurchTerry); - FP_Game_EntityTransitionState(game, building, FP_EntityChurchTerryState_ConvertPatron); - } - - entity->flags |= FP_GameEntityFlag_OccupiedInBuilding; - can_attack = false; - FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); - FP_SentinelList_Add(&entity->buildings_visited, game->chunk_pool, building->handle); - } - } - - if (can_attack) { - Dqn_V2 attack_dir_vectors[FP_GameDirection_Count] = {}; - attack_dir_vectors[FP_GameDirection_Up] = Dqn_V2_InitNx2(+0, -1); - attack_dir_vectors[FP_GameDirection_Down] = Dqn_V2_InitNx2(+0, +1); - attack_dir_vectors[FP_GameDirection_Left] = Dqn_V2_InitNx2(-1, +0); - attack_dir_vectors[FP_GameDirection_Right] = Dqn_V2_InitNx2(+1, +0); - - Dqn_V2 defender_entity_pos = FP_Game_CalcEntityWorldPos(game, waypoint_entity->handle); - Dqn_V2 entity_to_defender = defender_entity_pos - entity_pos; - Dqn_V2 entity_to_defender_norm = Dqn_V2_Normalise(entity_to_defender); - - FP_GameDirection best_attack_dir = FP_GameDirection_Up; - Dqn_f32 best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector = -1.1f; - DQN_FOR_UINDEX (dir_index, FP_GameDirection_Count) { - Dqn_V2 attack_dir = attack_dir_vectors[dir_index]; - Dqn_f32 scalar_projection = Dqn_V2_Dot(attack_dir, entity_to_defender_norm); - if (scalar_projection > best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector) { - best_attack_dir = DQN_CAST(FP_GameDirection)dir_index; - best_attack_dir_scalar_projection_onto_entity_to_waypoint_vector = scalar_projection; - } - } - - switch (entity->type) { - case FP_EntityType_Terry: /*FALLTHRU*/ - case FP_EntityType_Smoochie: /*FALLTHRU*/ - case FP_EntityType_Catfish: /*FALLTHRU*/ - case FP_EntityType_Clinger: { - // TODO(doyle): We should check if it's valid to enter this new state - // from the entity's current state - if (entity->type == FP_EntityType_Terry) { - FP_Game_EntityTransitionState(game, entity, FP_EntityTerryState_Attack); - } else if (entity->type == FP_EntityType_Smoochie) { - FP_Game_EntityTransitionState(game, entity, FP_EntitySmoochieState_Attack); - } else if (entity->type == FP_EntityType_Catfish) { - FP_Game_EntityTransitionState(game, entity, FP_EntityCatfishState_Attack); - } else { - DQN_ASSERT(entity->type == FP_EntityType_Clinger); - FP_Game_EntityTransitionState(game, entity, FP_EntityClingerState_Attack); - } - entity->direction = best_attack_dir; - } break; - - case FP_EntityType_Nil: break; - case FP_EntityType_ClubTerry: break; - case FP_EntityType_Map: break; - case FP_EntityType_Heart: break; - case FP_EntityType_MerchantTerry: break; - case FP_EntityType_MerchantGraveyard: break; - case FP_EntityType_MerchantGym: break; - case FP_EntityType_MerchantPhoneCompany: break; - case FP_EntityType_AirportTerry: break; - case FP_EntityType_ChurchTerry: break; - case FP_EntityType_KennelTerry: break; - case FP_EntityType_PhoneMessageProjectile: break; - case FP_EntityType_Count: DQN_INVALID_CODE_PATH; break; - } - } - - // NOTE: Aggro makes the entity attack, we will exit here preserving the waypoint in the entity. - break; - } else { - FP_SentinelList_Erase(&entity->waypoints, waypoint_link, game->chunk_pool); - } - } + // NOTE: Core equations of motion ========================================================== + FP_Game_MoveEntity(game, entity_handle, acceleration_meters_per_s); } - // NOTE: Move entity by mouse ============================================================== - if (game->active_entity == entity->handle && entity->flags & FP_GameEntityFlag_MoveByMouse) { - entity->velocity = {}; - acceleration_meters_per_s = {}; - entity->local_pos += input->mouse_p_delta; + // NOTE: If all enemies for the current wave have been spawned and the cooldown has elapsed + // start the next wave. + if (game->enemies_spawned_this_wave >= game->enemies_per_wave && game->clock_ms >= game->wave_cooldown_timestamp_ms) { + game->enemies_per_wave = DQN_MAX(5 * DQN_CAST(uint32_t)game->mob_spawners.size, DQN_CAST(uint32_t)(game->enemies_per_wave * 1.5f)); + game->enemies_spawned_this_wave = 0; + game->current_wave++; } - - if (game->clicked_entity == entity->handle) { - if (game->active_menu == FP_GameActiveMenu_Nil || game->active_menu == FP_GameActiveMenu_Build) { - if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_H)) - game->active_menu = DQN_CAST(FP_GameActiveMenu)(DQN_CAST(uint32_t)game->active_menu ^ FP_GameActiveMenu_Build); - } - - if (entity->flags & FP_GameEntityFlag_CameraTracking) - game->camera.world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) - Dqn_V2_InitV2I(platform->core.window_size) * .5f; - - FP_GamePlaceableBuilding placeable_building = PLACEABLE_BUILDINGS[game->build_mode_building_index]; - game->build_mode_can_place_building = false; - - uint8_t *inventory_count = nullptr; - if (placeable_building.type == FP_EntityType_ChurchTerry) - inventory_count = &entity->inventory.churchs; - else if (placeable_building.type == FP_EntityType_KennelTerry) - inventory_count = &entity->inventory.kennels; - else if (placeable_building.type == FP_EntityType_ClubTerry) - inventory_count = &entity->inventory.clubs; - else if (placeable_building.type == FP_EntityType_AirportTerry) - inventory_count = &entity->inventory.airports; - - bool have_building_inventory = inventory_count && (*inventory_count) > 0; - if (have_building_inventory && game->active_menu == FP_GameActiveMenu_Build) { - Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, placeable_building, entity->handle); - Dqn_V2 placement_pos = Dqn_Rect_Center(dest_rect); - - for (FP_GameEntityIterator zone_it = {}; - FP_Game_DFSPreOrderWalkEntityTree(game, &zone_it, game->root_entity); - ) { - - FP_GameEntity *zone = zone_it.entity; - bool is_building = zone->type == FP_EntityType_KennelTerry || - zone->type == FP_EntityType_AirportTerry || - zone->type == FP_EntityType_ChurchTerry || - zone->type == FP_EntityType_ClubTerry; - - Dqn_Rect zone_hit_box = FP_Game_CalcEntityWorldHitBox(game, zone->handle); - if (is_building) { - if (Dqn_Rect_Intersects(zone_hit_box, dest_rect)) { - game->build_mode_can_place_building = false; - break; - } - } - - if ((zone->flags & FP_GameEntityFlag_BuildZone) == 0) - continue; - - 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_J)) { - if (placeable_building.type == FP_EntityType_ClubTerry) { - FP_Entity_CreateClubTerry(game, placement_pos, "Club Terry"); - } else if (placeable_building.type == FP_EntityType_ChurchTerry) { - FP_Entity_CreateChurchTerry(game, placement_pos, "Church Terry"); - } else if (placeable_building.type == FP_EntityType_AirportTerry) { - FP_Entity_CreateAirportTerry(game, placement_pos, "Airport Terry"); - } else { - DQN_ASSERT(placeable_building.type == FP_EntityType_KennelTerry); - FP_Entity_CreateKennelTerry(game, placement_pos, "Kennel Terry"); - } - - (*inventory_count)--; - } - } - } - - if (!FP_Game_IsNilEntityHandle(game, entity->carried_monkey) && entity->type != FP_EntityType_MobSpawner) { - FP_GameFindClosestEntityResult closest_portal = FP_Game_FindClosestEntityWithType(game, entity->carried_monkey, game->mob_spawners.data, game->mob_spawners.size); - if (closest_portal.dist_squared < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 1.f))) { - FP_GameEntity *portal = FP_Game_GetEntity(game, closest_portal.entity); - portal->carried_monkey = entity->carried_monkey; - entity->carried_monkey = {}; - } - acceleration_meters_per_s *= 2.f; // TODO(doyle): Penalise the player - } else { - acceleration_meters_per_s *= 1.f; // TODO(doyle): Penalise the player - } - - // NOTE: Tick the state machine - // NOTE: This can delete the entity! Take caution - FP_GameEntityHandle entity_handle = entity->handle; - FP_EntityActionStateMachine(game, &platform->audio, input, entity, &acceleration_meters_per_s); - - // NOTE: Core equations of motion ========================================================== - FP_Game_MoveEntity(game, entity_handle, acceleration_meters_per_s); - } - - // NOTE: If all enemies for the current wave have been spawned and the cooldown has elapsed - // start the next wave. - if (game->enemies_spawned_this_wave >= game->enemies_per_wave && game->clock_ms >= game->wave_cooldown_timestamp_ms) { - game->enemies_per_wave = DQN_MAX(5 * DQN_CAST(uint32_t)game->mob_spawners.size, DQN_CAST(uint32_t)(game->enemies_per_wave * 1.5f)); - game->enemies_spawned_this_wave = 0; - game->current_wave++; } // NOTE: Update entity ========================================================================= @@ -2167,9 +2087,20 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) { Dqn_Profiler_ZoneScopeWithIndex("FP_Render", FP_ProfileZone_FPRender); - TELY_PlatformInput *input = &platform->input; - Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform); - Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos; + TELY_PlatformInput *input = &platform->input; + TELY_RFui *rfui = &game->rfui; + TELY_Assets *assets = &platform->assets; + + TELY_Render_ClearColourV3(renderer, TELY_COLOUR_BLACK_MIDNIGHT_V4.rgb); + TELY_Render_PushFont(renderer, game->jetbrains_mono_font); + + TELY_RFui_FrameSetup(rfui, &platform->frame_arena); + TELY_RFui_PushFont(rfui, game->jetbrains_mono_font); + TELY_RFui_PushLabelColourV4(rfui, TELY_COLOUR_BLACK_MIDNIGHT_V4); + + Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform); + TELY_Render_PushTransform(renderer, model_view); + Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos; // NOTE: Draw tiles ============================================================================ Dqn_usize tile_count_x = DQN_CAST(Dqn_usize)(platform->core.window_size.w / game->tile_size); @@ -2357,7 +2288,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) } } - if (game->active_menu == FP_GameActiveMenu_Build) { + if (game->in_game_menu == FP_GameInGameMenu_Build) { if (entity->flags & FP_GameEntityFlag_BuildZone) TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_BLUE_CADET_V4, 0.5f)); } @@ -2441,648 +2372,600 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer) } } - // NOTE: Render the merchant menus ========================================= - FP_GameEntity *player = FP_Game_GetEntity(game, game->player); - Dqn_V2 player_pos = FP_Game_CalcEntityWorldPos(game, game->player); - { - FP_GameInventory *invent = &player->inventory; - struct FP_MerchantToMenuMapping { - FP_GameEntityHandle merchant; - Dqn_String8 menu_anim; - Dqn_String8 building; - Dqn_V2 building_offset01; - uint8_t *inventory_count; - uint32_t *building_base_price; - uint32_t *upgrade_base_price; - } merchants[] = { - {game->merchant_terry, g_anim_names.merchant_terry_menu, g_anim_names.club_terry_dark, Dqn_V2_InitNx2(0.015f, +0.04f), &invent->clubs, &invent->clubs_base_price, &invent->health_base_price}, - {game->merchant_graveyard, g_anim_names.merchant_graveyard_menu, g_anim_names.church_terry_dark, Dqn_V2_InitNx2(0.04f, -0.15f), &invent->churchs, &invent->churchs_base_price, &invent->stamina_base_price}, - {game->merchant_gym, g_anim_names.merchant_gym_menu, g_anim_names.kennel_terry, Dqn_V2_InitNx2(0, +0), &invent->kennels, &invent->kennels_base_price, &invent->attack_base_price}, - {game->merchant_phone_company, g_anim_names.merchant_phone_company_menu, g_anim_names.airport_terry, Dqn_V2_InitNx2(0, -0.1f), &invent->airports, &invent->airports_base_price, &invent->mobile_plan_base_price}, - }; + if (game->state == FP_GameState_IntroScreen) { + TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); + DQN_DEFER { TELY_Render_PopTransform(renderer); }; + TELY_Render_RectColourV4( + renderer, + Dqn_Rect_InitNx4(0, 0, DQN_CAST(Dqn_f32)platform->core.window_size.x, DQN_CAST(Dqn_f32)platform->core.window_size.y), + TELY_RenderShapeMode_Fill, + TELY_Colour_V4Alpha(TELY_COLOUR_BLACK_V4, 0.8f)); - bool activated_merchant = false; - for (FP_MerchantToMenuMapping mapping : merchants) { - FP_GameEntityHandle merchant_handle = mapping.merchant; - Dqn_V2 world_pos = FP_Game_CalcEntityWorldPos(game, merchant_handle); - Dqn_f32 dist_squared = Dqn_V2_LengthSq_V2x2(world_pos, player_pos); + Dqn_V2I inset = platform->core.window_size * .05f; + Dqn_f32 min_inset = DQN_CAST(Dqn_f32)DQN_MIN(inset.x, inset.y); - if (dist_squared > DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 4))) - continue; + Dqn_V2 draw_p = Dqn_V2_InitNx2(min_inset, min_inset); + TELY_Render_PushColourV4(renderer, TELY_COLOUR_WHITE_V4); - // NOTE: Render animated merchant menu ============================= - activated_merchant = true; - Dqn_Rect merchant_menu_rect = {}; - { - FP_GameRenderSprite *sprite = &game->player_merchant_menu; - if (!sprite->asset.anim || sprite->asset.anim->label != mapping.menu_anim) { - sprite->asset = TELY_Asset_MakeAnimatedSprite(&game->atlas_sprite_sheet, mapping.menu_anim, TELY_AssetFlip_No); - sprite->started_at_clock_ms = game->clock_ms; + TELY_Render_PushFont(renderer, game->inter_regular_font_large); + TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, "Feely Pona"); draw_p.y += TELY_Render_FontHeight(renderer, assets); + TELY_Render_PopFont(renderer); + + TELY_Render_PushFont(renderer, game->inter_regular_font); + TELY_Render_TextF(renderer, draw_p, Dqn_V2_Zero, "Press enter to start"); draw_p.y += TELY_Render_FontHeight(renderer, assets); + TELY_Render_PopFont(renderer); + TELY_Render_PopColourV4(renderer); + + if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_Return)) + game->state = FP_GameState_Play; + } else { + // NOTE: Render the merchant menus ========================================= + FP_GameEntity *player = FP_Game_GetEntity(game, game->player); + Dqn_V2 player_pos = FP_Game_CalcEntityWorldPos(game, game->player); + { + FP_GameInventory *invent = &player->inventory; + struct FP_MerchantToMenuMapping { + FP_GameEntityHandle merchant; + Dqn_String8 menu_anim; + Dqn_String8 building; + Dqn_V2 building_offset01; + uint8_t *inventory_count; + uint32_t *building_base_price; + uint32_t *upgrade_base_price; + } merchants[] = { + {game->merchant_terry, g_anim_names.merchant_terry_menu, g_anim_names.club_terry_dark, Dqn_V2_InitNx2(0.015f, +0.04f), &invent->clubs, &invent->clubs_base_price, &invent->health_base_price}, + {game->merchant_graveyard, g_anim_names.merchant_graveyard_menu, g_anim_names.church_terry_dark, Dqn_V2_InitNx2(0.04f, -0.15f), &invent->churchs, &invent->churchs_base_price, &invent->stamina_base_price}, + {game->merchant_gym, g_anim_names.merchant_gym_menu, g_anim_names.kennel_terry, Dqn_V2_InitNx2(0, +0), &invent->kennels, &invent->kennels_base_price, &invent->attack_base_price}, + {game->merchant_phone_company, g_anim_names.merchant_phone_company_menu, g_anim_names.airport_terry, Dqn_V2_InitNx2(0, -0.1f), &invent->airports, &invent->airports_base_price, &invent->mobile_plan_base_price}, + }; + + bool activated_merchant = false; + for (FP_MerchantToMenuMapping mapping : merchants) { + FP_GameEntityHandle merchant_handle = mapping.merchant; + Dqn_V2 world_pos = FP_Game_CalcEntityWorldPos(game, merchant_handle); + Dqn_f32 dist_squared = Dqn_V2_LengthSq_V2x2(world_pos, player_pos); + + if (dist_squared > DQN_SQUARED(FP_Game_MetersToPixelsNx1(game, 4))) + continue; + + // NOTE: Render animated merchant menu ============================= + activated_merchant = true; + Dqn_Rect merchant_menu_rect = {}; + { + FP_GameRenderSprite *sprite = &game->player_merchant_menu; + if (!sprite->asset.anim || sprite->asset.anim->label != mapping.menu_anim) { + sprite->asset = TELY_Asset_MakeAnimatedSprite(&game->atlas_sprite_sheet, mapping.menu_anim, TELY_AssetFlip_No); + sprite->started_at_clock_ms = game->clock_ms; + } + + uint64_t elapsed_ms = game->clock_ms - sprite->started_at_clock_ms; + uint16_t raw_anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite->asset.anim->ms_per_frame); + uint16_t anim_frame = raw_anim_frame % sprite->asset.anim->count; + + Dqn_usize sprite_index = sprite->asset.anim->index + anim_frame; + Dqn_Rect src_rect = sprite->asset.sheet->rects.data[sprite_index]; + + merchant_menu_rect.size = src_rect.size; + merchant_menu_rect.pos = world_pos - (merchant_menu_rect.size * .5f) - Dqn_V2_InitNx2(0.f, src_rect.size.y); + Dqn_f32 sin_t = DQN_SINF(DQN_CAST(Dqn_f32)input->timer_s * 3.f); + merchant_menu_rect.pos.y += sin_t * 4.f; + + TELY_Render_TextureColourV4(renderer, + sprite->asset.sheet->tex_handle, + src_rect, + merchant_menu_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_WHITE_V4); } - uint64_t elapsed_ms = game->clock_ms - sprite->started_at_clock_ms; - uint16_t raw_anim_frame = DQN_CAST(uint16_t)(elapsed_ms / sprite->asset.anim->ms_per_frame); - uint16_t anim_frame = raw_anim_frame % sprite->asset.anim->count; + TELY_Render_PushColourV4(renderer, TELY_COLOUR_WHITE_V4); + TELY_Render_PushFont(renderer, game->talkco_font_large); + DQN_DEFER { + TELY_Render_PopFont(renderer); + TELY_Render_PopColourV4(renderer); + }; - Dqn_usize sprite_index = sprite->asset.anim->index + anim_frame; - Dqn_Rect src_rect = sprite->asset.sheet->rects.data[sprite_index]; + // NOTE: Render the merchant button for buildings ================== + uint64_t const buy_duration_ms = 500; + { + bool const have_enough_coins = player->coins >= *mapping.building_base_price; + // NOTE: Buy trigger + animation =============================== + { + TELY_PlatformInputScanCode key = TELY_PlatformInputScanCode_J; + bool trigger_buy_anim = false; - merchant_menu_rect.size = src_rect.size; - merchant_menu_rect.pos = world_pos - (merchant_menu_rect.size * .5f) - Dqn_V2_InitNx2(0.f, src_rect.size.y); - Dqn_f32 sin_t = DQN_SINF(DQN_CAST(Dqn_f32)input->timer_s * 3.f); - merchant_menu_rect.pos.y += sin_t * 4.f; + if (have_enough_coins) { + if (TELY_Platform_InputScanCodeIsPressed(input, key)) { + game->player_trigger_purchase_building_timestamp = game->clock_ms + buy_duration_ms; + } else if (TELY_Platform_InputScanCodeIsDown(input, key)) { + trigger_buy_anim = true; + if (game->clock_ms > game->player_trigger_purchase_building_timestamp) + game->player_trigger_purchase_building_timestamp = game->clock_ms; + } else if (TELY_Platform_InputScanCodeIsReleased(input, key)) { + if (game->clock_ms > game->player_trigger_purchase_building_timestamp) { + if (mapping.inventory_count) { + player->coins -= *mapping.building_base_price; + *mapping.building_base_price *= 2; + // NOTE: Raise the prices of everything else + invent->airports_base_price *= 2; + invent->clubs_base_price *= 2; + invent->kennels_base_price *= 2; + invent->churchs_base_price *= 2; + + (*mapping.inventory_count)++; + } + } else { + game->player_trigger_purchase_building_timestamp = UINT64_MAX; + } + } + + if (trigger_buy_anim) { + uint64_t start_buy_time = game->player_trigger_purchase_building_timestamp - buy_duration_ms; + uint64_t elapsed_time = game->clock_ms - start_buy_time; + + Dqn_f32 buy_t = DQN_MIN(elapsed_time / DQN_CAST(Dqn_f32)buy_duration_ms, 1.f); + Dqn_Rect buy_lerp_rect = {}; + buy_lerp_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.297f, 0.215f)); + buy_lerp_rect.size.w = (merchant_menu_rect.size.w * 0.38f) * buy_t; + buy_lerp_rect.size.h = merchant_menu_rect.size.h * .611f; + + TELY_Render_RectColourV4(renderer, buy_lerp_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_BLUE_CADET_V4, 0.5f)); + } + } + + } + + // NOTE: Render the (A) button ================================= + Dqn_V4 tex_mod_colour = have_enough_coins ? TELY_COLOUR_WHITE_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, .5f); + { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.merchant_button_a); + Dqn_Rect button_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + Dqn_Rect dest_rect = {}; + dest_rect.size = button_rect.size * 1.5f; + dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.345f, 0.5f)); + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + button_rect, + dest_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + tex_mod_colour); + + TELY_Render_TextF(renderer, Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0.5f, -1)), Dqn_V2_InitNx2(0.5, 0.f), "$%u", *mapping.building_base_price); + } + + // NOTE: Render the merchant shop item building ================ + { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, mapping.building); + Dqn_Rect tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + Dqn_Rect dest_rect = {}; + dest_rect.size = tex_rect.size * 0.35f; + dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.42f, 0.25f) + mapping.building_offset01); + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + tex_rect, + dest_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + tex_mod_colour); + } + } + + // NOTE: Render the merchant button for buildings + { + bool const have_enough_coins = player->coins >= *mapping.upgrade_base_price; + // NOTE: Buy trigger + animation =============================== + { + TELY_PlatformInputScanCode key = TELY_PlatformInputScanCode_K; + bool trigger_buy_anim = false; + + if (have_enough_coins) { + if (TELY_Platform_InputScanCodeIsPressed(input, key)) { + game->player_trigger_purchase_upgrade_timestamp = game->clock_ms + buy_duration_ms; + } else if (TELY_Platform_InputScanCodeIsDown(input, key)) { + trigger_buy_anim = true; + if (game->clock_ms > game->player_trigger_purchase_upgrade_timestamp) + game->player_trigger_purchase_upgrade_timestamp = game->clock_ms; + } else if (TELY_Platform_InputScanCodeIsReleased(input, key)) { + if (game->clock_ms > game->player_trigger_purchase_upgrade_timestamp) { + player->coins -= *mapping.upgrade_base_price; + *mapping.upgrade_base_price *= 2; + + if (mapping.merchant == game->merchant_terry) { + // TODO(doyle): Attack damage? Or increase attack range? + } else if (mapping.merchant == game->merchant_graveyard) { + player->stamina_cap += DQN_CAST(uint16_t)(FP_TERRY_DASH_STAMINA_COST * .5f); + } else if (mapping.merchant == game->merchant_gym) { + player->hp_cap += FP_DEFAULT_DAMAGE; + player->hp = player->hp_cap; + } else if (mapping.merchant == game->merchant_phone_company) { + player->terry_mobile_data_plan_cap += DQN_KILOBYTES(1); + } + } else { + game->player_trigger_purchase_upgrade_timestamp = UINT64_MAX; + } + } + + if (trigger_buy_anim) { + uint64_t start_buy_time = game->player_trigger_purchase_upgrade_timestamp - buy_duration_ms; + uint64_t elapsed_time = game->clock_ms - start_buy_time; + + Dqn_f32 buy_t = DQN_MIN(elapsed_time / DQN_CAST(Dqn_f32)buy_duration_ms, 1.f); + Dqn_Rect buy_lerp_rect = {}; + buy_lerp_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.68f, 0.215f)); + buy_lerp_rect.size.w = (merchant_menu_rect.size.w * 0.211f) * buy_t; + buy_lerp_rect.size.h = merchant_menu_rect.size.h * .611f; + + TELY_Render_RectColourV4(renderer, buy_lerp_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, 0.5f)); + } + } + } + + // NOTE: Render the (B) button ================================= + Dqn_V4 tex_mod_colour = have_enough_coins ? TELY_COLOUR_WHITE_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, .5f); + { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.merchant_button_b); + Dqn_Rect button_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + Dqn_Rect dest_rect = {}; + dest_rect.size = button_rect.size * 1.5f; + dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.75f, 0.5f)); + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + button_rect, + dest_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + tex_mod_colour); + + TELY_Render_TextF(renderer, Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0.5f, -1)), Dqn_V2_InitNx2(0.5, 0.f), "$%u", *mapping.upgrade_base_price); + } + } + } + + if (activated_merchant) { + game->in_game_menu = FP_GameInGameMenu_Merchant; + } else { + if (game->in_game_menu == FP_GameInGameMenu_Merchant) { + game->in_game_menu = FP_GameInGameMenu_Nil; + } + } + } + + // NOTE: Render player avatar HUD ========================================== + Dqn_Rect player_avatar_rect = {}; + player_avatar_rect.pos = Dqn_V2_InitNx1(32.f); + Dqn_V2 next_pos = {}; + { + TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); + DQN_DEFER { TELY_Render_PopTransform(renderer); }; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, FP_EntityType_Terry, FP_EntityTerryState_Idle, FP_GameDirection_Down); + player_avatar_rect.size = render_data.render_size; + + TELY_Render_TextureColourV4(renderer, + render_data.sheet->tex_handle, + render_data.sheet_rect, + player_avatar_rect, + Dqn_V2_Zero, + 0.f, + TELY_COLOUR_WHITE_V4); + + TELY_Render_PushFont(renderer, game->talkco_font); + DQN_DEFER { TELY_Render_PopFont(renderer); }; + + next_pos = Dqn_Rect_InterpolatedPoint(player_avatar_rect, Dqn_V2_InitNx2(1.f, 0)); + Dqn_f32 font_height = TELY_Render_FontHeight(renderer, &platform->assets); + + // TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "Terry"); + // next_pos.y += font_height; + + // NOTE: Health bar ==================================================== + Dqn_f32 bar_height = font_height * .75f; + Dqn_Rect health_icon_rect = {}; + { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_health); + Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + { + health_icon_rect.size = icon_tex_rect.size * .4f; + health_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - health_icon_rect.size.x * .25f, next_pos.y - (health_icon_rect.size.y * .35f)); + } + + Dqn_f32 bar_x = next_pos.x + (health_icon_rect.size.x * .25f); + Dqn_f32 health_t = player->hp / DQN_CAST(Dqn_f32)player->hp_cap; + Dqn_Rect health_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->hp_cap, bar_height); + Dqn_Rect curr_health_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->hp_cap * health_t, bar_height); + + TELY_Render_RectColourV4(renderer, curr_health_rect, TELY_RenderShapeMode_Fill, TELY_COLOUR_RED_TOMATO_V4); + + TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( + renderer, + health_rect, + TELY_RenderShapeMode_Line, + TELY_COLOUR_BLACK_V4); + cmd->thickness = 4.f; + + // NOTE: Draw the heart icon shadow TELY_Render_TextureColourV4(renderer, - sprite->asset.sheet->tex_handle, - src_rect, - merchant_menu_rect, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + Dqn_Rect_InitV2x2(health_icon_rect.pos - (cmd->thickness * 2.f), health_icon_rect.size + (cmd->thickness * 4.f)), + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_BLACK_V4); + + // NOTE: Draw the heart icon + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + health_icon_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotation*/, TELY_COLOUR_WHITE_V4); } - TELY_Render_PushColourV4(renderer, TELY_COLOUR_WHITE_V4); - TELY_Render_PushFont(renderer, game->talkco_font_large); - DQN_DEFER { - TELY_Render_PopFont(renderer); - TELY_Render_PopColourV4(renderer); - }; - - // NOTE: Render the merchant button for buildings ================== - uint64_t const buy_duration_ms = 500; + // NOTE: Stamina bar =================================================== + next_pos.y += health_icon_rect.size.h * .8f; + Dqn_Rect stamina_icon_rect = {}; { - bool const have_enough_coins = player->coins >= *mapping.building_base_price; - // NOTE: Buy trigger + animation =============================== + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_stamina); + Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; { - TELY_PlatformInputScanCode key = TELY_PlatformInputScanCode_J; - bool trigger_buy_anim = false; - - if (have_enough_coins) { - if (TELY_Platform_InputScanCodeIsPressed(input, key)) { - game->player_trigger_purchase_building_timestamp = game->clock_ms + buy_duration_ms; - } else if (TELY_Platform_InputScanCodeIsDown(input, key)) { - trigger_buy_anim = true; - if (game->clock_ms > game->player_trigger_purchase_building_timestamp) - game->player_trigger_purchase_building_timestamp = game->clock_ms; - } else if (TELY_Platform_InputScanCodeIsReleased(input, key)) { - if (game->clock_ms > game->player_trigger_purchase_building_timestamp) { - if (mapping.inventory_count) { - player->coins -= *mapping.building_base_price; - *mapping.building_base_price *= 2; - - // NOTE: Raise the prices of everything else - invent->airports_base_price *= 2; - invent->clubs_base_price *= 2; - invent->kennels_base_price *= 2; - invent->churchs_base_price *= 2; - - (*mapping.inventory_count)++; - } - } else { - game->player_trigger_purchase_building_timestamp = UINT64_MAX; - } - } - - if (trigger_buy_anim) { - uint64_t start_buy_time = game->player_trigger_purchase_building_timestamp - buy_duration_ms; - uint64_t elapsed_time = game->clock_ms - start_buy_time; - - Dqn_f32 buy_t = DQN_MIN(elapsed_time / DQN_CAST(Dqn_f32)buy_duration_ms, 1.f); - Dqn_Rect buy_lerp_rect = {}; - buy_lerp_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.297f, 0.215f)); - buy_lerp_rect.size.w = (merchant_menu_rect.size.w * 0.38f) * buy_t; - buy_lerp_rect.size.h = merchant_menu_rect.size.h * .611f; - - TELY_Render_RectColourV4(renderer, buy_lerp_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_BLUE_CADET_V4, 0.5f)); - } - } - + stamina_icon_rect.size = icon_tex_rect.size * .35f; + stamina_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - stamina_icon_rect.size.x * .25f, next_pos.y - (stamina_icon_rect.size.y * .35f)); } - // NOTE: Render the (A) button ================================= - Dqn_V4 tex_mod_colour = have_enough_coins ? TELY_COLOUR_WHITE_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, .5f); - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.merchant_button_a); - Dqn_Rect button_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - Dqn_Rect dest_rect = {}; - dest_rect.size = button_rect.size * 1.5f; - dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.345f, 0.5f)); - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - button_rect, - dest_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - tex_mod_colour); + Dqn_f32 bar_x = next_pos.x + (stamina_icon_rect.size.x * .25f); + Dqn_f32 stamina_t = player->stamina / DQN_CAST(Dqn_f32)player->stamina_cap; + Dqn_Rect stamina_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->stamina_cap, bar_height); + Dqn_Rect curr_stamina_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->stamina_cap * stamina_t, bar_height); + TELY_Render_RectColourV4( + renderer, + curr_stamina_rect, + TELY_RenderShapeMode_Fill, + TELY_COLOUR_YELLOW_SANDY_V4); - TELY_Render_TextF(renderer, Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0.5f, -1)), Dqn_V2_InitNx2(0.5, 0.f), "$%u", *mapping.building_base_price); + TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( + renderer, + stamina_rect, + TELY_RenderShapeMode_Line, + TELY_COLOUR_BLACK_V4); + cmd->thickness = 4.f; + + // NOTE: Draw the icon shadow + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + Dqn_Rect_InitV2x2(stamina_icon_rect.pos - (cmd->thickness * 2.f), stamina_icon_rect.size + (cmd->thickness * 4.f)), + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_BLACK_V4); + + // NOTE: Draw the icon + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + stamina_icon_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_WHITE_V4); + } + + // NOTE: Mobile data bar =================================================== + next_pos.y += stamina_icon_rect.size.h * .8f; + Dqn_Rect phone_icon_rect = {}; + { + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_phone); + Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; + { + phone_icon_rect.size = icon_tex_rect.size * .35f; + phone_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - phone_icon_rect.size.x * .25f, next_pos.y - (phone_icon_rect.size.y * .35f)); } - // NOTE: Render the merchant shop item building ================ - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, mapping.building); - Dqn_Rect tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - Dqn_Rect dest_rect = {}; - dest_rect.size = tex_rect.size * 0.35f; - dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.42f, 0.25f) + mapping.building_offset01); - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - tex_rect, - dest_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - tex_mod_colour); - } + Dqn_f32 pixels_per_kb = 15.5f; + Dqn_f32 bar_width = DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap / DQN_KILOBYTES(1) * pixels_per_kb; + + Dqn_f32 bar_x = next_pos.x + (phone_icon_rect.size.x * .25f); + Dqn_f32 data_plan_t = player->terry_mobile_data_plan / DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap; + Dqn_Rect data_plan_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, bar_width, bar_height); + Dqn_Rect curr_data_plan_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, bar_width * data_plan_t, bar_height); + TELY_Render_RectColourV4( + renderer, + curr_data_plan_rect, + TELY_RenderShapeMode_Fill, + TELY_COLOUR_BLUE_CADET_V4); + + TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( + renderer, + data_plan_rect, + TELY_RenderShapeMode_Line, + TELY_COLOUR_BLACK_V4); + cmd->thickness = 4.f; + + // NOTE: Draw the icon shadow + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + Dqn_Rect_InitV2x2(phone_icon_rect.pos - (cmd->thickness * 2.f), phone_icon_rect.size + (cmd->thickness * 4.f)), + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_BLACK_V4); + + // NOTE: Draw the icon + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + phone_icon_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_WHITE_V4); } - // NOTE: Render the merchant button for buildings + next_pos.y += phone_icon_rect.size.h * .8f; + Dqn_Rect money_icon_rect = {}; { - bool const have_enough_coins = player->coins >= *mapping.upgrade_base_price; - // NOTE: Buy trigger + animation =============================== + TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_money); + Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; { - TELY_PlatformInputScanCode key = TELY_PlatformInputScanCode_K; - bool trigger_buy_anim = false; - - if (have_enough_coins) { - if (TELY_Platform_InputScanCodeIsPressed(input, key)) { - game->player_trigger_purchase_upgrade_timestamp = game->clock_ms + buy_duration_ms; - } else if (TELY_Platform_InputScanCodeIsDown(input, key)) { - trigger_buy_anim = true; - if (game->clock_ms > game->player_trigger_purchase_upgrade_timestamp) - game->player_trigger_purchase_upgrade_timestamp = game->clock_ms; - } else if (TELY_Platform_InputScanCodeIsReleased(input, key)) { - if (game->clock_ms > game->player_trigger_purchase_upgrade_timestamp) { - player->coins -= *mapping.upgrade_base_price; - *mapping.upgrade_base_price *= 2; - - if (mapping.merchant == game->merchant_terry) { - // TODO(doyle): Attack damage? Or increase attack range? - } else if (mapping.merchant == game->merchant_graveyard) { - player->stamina_cap += DQN_CAST(uint16_t)(FP_TERRY_DASH_STAMINA_COST * .5f); - } else if (mapping.merchant == game->merchant_gym) { - player->hp_cap += FP_DEFAULT_DAMAGE; - player->hp = player->hp_cap; - } else if (mapping.merchant == game->merchant_phone_company) { - player->terry_mobile_data_plan_cap += DQN_KILOBYTES(1); - } - } else { - game->player_trigger_purchase_upgrade_timestamp = UINT64_MAX; - } - } - - if (trigger_buy_anim) { - uint64_t start_buy_time = game->player_trigger_purchase_upgrade_timestamp - buy_duration_ms; - uint64_t elapsed_time = game->clock_ms - start_buy_time; - - Dqn_f32 buy_t = DQN_MIN(elapsed_time / DQN_CAST(Dqn_f32)buy_duration_ms, 1.f); - Dqn_Rect buy_lerp_rect = {}; - buy_lerp_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.68f, 0.215f)); - buy_lerp_rect.size.w = (merchant_menu_rect.size.w * 0.211f) * buy_t; - buy_lerp_rect.size.h = merchant_menu_rect.size.h * .611f; - - TELY_Render_RectColourV4(renderer, buy_lerp_rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, 0.5f)); - } - } + money_icon_rect.size = icon_tex_rect.size * .35f; + money_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - money_icon_rect.size.x * .25f, next_pos.y - (money_icon_rect.size.y * .15f)); } - // NOTE: Render the (B) button ================================= - Dqn_V4 tex_mod_colour = have_enough_coins ? TELY_COLOUR_WHITE_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_RED_TOMATO_V4, .5f); - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.merchant_button_b); - Dqn_Rect button_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - Dqn_Rect dest_rect = {}; - dest_rect.size = button_rect.size * 1.5f; - dest_rect.pos = Dqn_Rect_InterpolatedPoint(merchant_menu_rect, Dqn_V2_InitNx2(0.75f, 0.5f)); - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - button_rect, - dest_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - tex_mod_colour); + TELY_Render_TextF(renderer, + Dqn_V2_InitNx2(next_pos.x + money_icon_rect.size.x * .75f, money_icon_rect.pos.y), + Dqn_V2_InitNx2(0, -0.5), + "$%I64u", + player->coins); - TELY_Render_TextF(renderer, Dqn_Rect_InterpolatedPoint(dest_rect, Dqn_V2_InitNx2(0.5f, -1)), Dqn_V2_InitNx2(0.5, 0.f), "$%u", *mapping.upgrade_base_price); - } - } - } + // NOTE: Draw the icon shadow + Dqn_f32 thickness = 4.f; + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + Dqn_Rect_InitV2x2(money_icon_rect.pos - (thickness * 2.f), money_icon_rect.size + (thickness * 4.f)), + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_BLACK_V4); - if (activated_merchant) { - game->active_menu = FP_GameActiveMenu_Merchant; - } else { - if (game->active_menu == FP_GameActiveMenu_Merchant) { - game->active_menu = FP_GameActiveMenu_Nil; - } - } - } - - // NOTE: Render player avatar HUD ========================================== - Dqn_Rect player_avatar_rect = {}; - player_avatar_rect.pos = Dqn_V2_InitNx1(32.f); - Dqn_V2 next_pos = {}; - { - TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); - DQN_DEFER { TELY_Render_PopTransform(renderer); }; - - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, FP_EntityType_Terry, FP_EntityTerryState_Idle, FP_GameDirection_Down); - player_avatar_rect.size = render_data.render_size; - - TELY_Render_TextureColourV4(renderer, - render_data.sheet->tex_handle, - render_data.sheet_rect, - player_avatar_rect, - Dqn_V2_Zero, - 0.f, - TELY_COLOUR_WHITE_V4); - - TELY_Render_PushFont(renderer, game->talkco_font); - DQN_DEFER { TELY_Render_PopFont(renderer); }; - - next_pos = Dqn_Rect_InterpolatedPoint(player_avatar_rect, Dqn_V2_InitNx2(1.f, 0)); - Dqn_f32 font_height = TELY_Render_FontHeight(renderer, &platform->assets); - - // TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "Terry"); - // next_pos.y += font_height; - - // NOTE: Health bar ==================================================== - Dqn_f32 bar_height = font_height * .75f; - Dqn_Rect health_icon_rect = {}; - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_health); - Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - { - health_icon_rect.size = icon_tex_rect.size * .4f; - health_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - health_icon_rect.size.x * .25f, next_pos.y - (health_icon_rect.size.y * .35f)); + // NOTE: Draw the icon + TELY_Render_TextureColourV4(renderer, + game->atlas_sprite_sheet.tex_handle, + icon_tex_rect, + money_icon_rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + TELY_COLOUR_WHITE_V4); } - Dqn_f32 bar_x = next_pos.x + (health_icon_rect.size.x * .25f); - Dqn_f32 health_t = player->hp / DQN_CAST(Dqn_f32)player->hp_cap; - Dqn_Rect health_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->hp_cap, bar_height); - Dqn_Rect curr_health_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->hp_cap * health_t, bar_height); + next_pos.y += money_icon_rect.size.h; - TELY_Render_RectColourV4(renderer, curr_health_rect, TELY_RenderShapeMode_Fill, TELY_COLOUR_RED_TOMATO_V4); + #if 0 + next_pos.y += font_height; + TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[H] Build Menu"); - TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( - renderer, - health_rect, - TELY_RenderShapeMode_Line, - TELY_COLOUR_BLACK_V4); - cmd->thickness = 4.f; + next_pos.y += font_height; + TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[Shift+WASD] Strafe"); - // NOTE: Draw the heart icon shadow - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - Dqn_Rect_InitV2x2(health_icon_rect.pos - (cmd->thickness * 2.f), health_icon_rect.size + (cmd->thickness * 4.f)), - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_BLACK_V4); + next_pos.y += font_height; + TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[Ctrl+WASD] Dash"); - // NOTE: Draw the heart icon - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - health_icon_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_WHITE_V4); + next_pos.y += font_height; + TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[J|K] Melee/Range"); + #endif } - // NOTE: Stamina bar =================================================== - next_pos.y += health_icon_rect.size.h * .8f; - Dqn_Rect stamina_icon_rect = {}; - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_stamina); - Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - { - stamina_icon_rect.size = icon_tex_rect.size * .35f; - stamina_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - stamina_icon_rect.size.x * .25f, next_pos.y - (stamina_icon_rect.size.y * .35f)); - } - - Dqn_f32 bar_x = next_pos.x + (stamina_icon_rect.size.x * .25f); - Dqn_f32 stamina_t = player->stamina / DQN_CAST(Dqn_f32)player->stamina_cap; - Dqn_Rect stamina_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->stamina_cap, bar_height); - Dqn_Rect curr_stamina_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, DQN_CAST(Dqn_f32)player->stamina_cap * stamina_t, bar_height); - TELY_Render_RectColourV4( - renderer, - curr_stamina_rect, - TELY_RenderShapeMode_Fill, - TELY_COLOUR_YELLOW_SANDY_V4); - - TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( - renderer, - stamina_rect, - TELY_RenderShapeMode_Line, - TELY_COLOUR_BLACK_V4); - cmd->thickness = 4.f; - - // NOTE: Draw the icon shadow - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - Dqn_Rect_InitV2x2(stamina_icon_rect.pos - (cmd->thickness * 2.f), stamina_icon_rect.size + (cmd->thickness * 4.f)), - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_BLACK_V4); - - // NOTE: Draw the icon - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - stamina_icon_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_WHITE_V4); - } - - // NOTE: Mobile data bar =================================================== - next_pos.y += stamina_icon_rect.size.h * .8f; - Dqn_Rect phone_icon_rect = {}; - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_phone); - Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - { - phone_icon_rect.size = icon_tex_rect.size * .35f; - phone_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - phone_icon_rect.size.x * .25f, next_pos.y - (phone_icon_rect.size.y * .35f)); - } - - Dqn_f32 pixels_per_kb = 15.5f; - Dqn_f32 bar_width = DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap / DQN_KILOBYTES(1) * pixels_per_kb; - - Dqn_f32 bar_x = next_pos.x + (phone_icon_rect.size.x * .25f); - Dqn_f32 data_plan_t = player->terry_mobile_data_plan / DQN_CAST(Dqn_f32)player->terry_mobile_data_plan_cap; - Dqn_Rect data_plan_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, bar_width, bar_height); - Dqn_Rect curr_data_plan_rect = Dqn_Rect_InitNx4(bar_x, next_pos.y, bar_width * data_plan_t, bar_height); - TELY_Render_RectColourV4( - renderer, - curr_data_plan_rect, - TELY_RenderShapeMode_Fill, - TELY_COLOUR_BLUE_CADET_V4); - - TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4( - renderer, - data_plan_rect, - TELY_RenderShapeMode_Line, - TELY_COLOUR_BLACK_V4); - cmd->thickness = 4.f; - - // NOTE: Draw the icon shadow - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - Dqn_Rect_InitV2x2(phone_icon_rect.pos - (cmd->thickness * 2.f), phone_icon_rect.size + (cmd->thickness * 4.f)), - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_BLACK_V4); - - // NOTE: Draw the icon - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - phone_icon_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_WHITE_V4); - } - - next_pos.y += phone_icon_rect.size.h * .8f; - Dqn_Rect money_icon_rect = {}; - { - TELY_AssetSpriteAnimation *anim = TELY_Asset_GetSpriteAnimation(&game->atlas_sprite_sheet, g_anim_names.icon_money); - Dqn_Rect icon_tex_rect = game->atlas_sprite_sheet.rects.data[anim->index]; - { - money_icon_rect.size = icon_tex_rect.size * .35f; - money_icon_rect.pos = Dqn_V2_InitNx2(next_pos.x - money_icon_rect.size.x * .25f, next_pos.y - (money_icon_rect.size.y * .15f)); - } - - TELY_Render_TextF(renderer, - Dqn_V2_InitNx2(next_pos.x + money_icon_rect.size.x * .75f, money_icon_rect.pos.y), - Dqn_V2_InitNx2(0, -0.5), - "$%I64u", - player->coins); - - // NOTE: Draw the icon shadow - Dqn_f32 thickness = 4.f; - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - Dqn_Rect_InitV2x2(money_icon_rect.pos - (thickness * 2.f), money_icon_rect.size + (thickness * 4.f)), - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_BLACK_V4); - - // NOTE: Draw the icon - TELY_Render_TextureColourV4(renderer, - game->atlas_sprite_sheet.tex_handle, - icon_tex_rect, - money_icon_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - TELY_COLOUR_WHITE_V4); - } - - next_pos.y += money_icon_rect.size.h; - - #if 0 - next_pos.y += font_height; - TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[H] Build Menu"); - - next_pos.y += font_height; - TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[Shift+WASD] Strafe"); - - next_pos.y += font_height; - TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[Ctrl+WASD] Dash"); - - next_pos.y += font_height; - TELY_Render_TextF(renderer, next_pos, Dqn_V2_Zero, "[J|K] Melee/Range"); - #endif - } - - // NOTE: Render the wave =================================================== - { - TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); - DQN_DEFER { TELY_Render_PopTransform(renderer); }; - - TELY_Render_PushFont(renderer, game->talkco_font_large); - DQN_DEFER { TELY_Render_PopFont(renderer); }; - - uint64_t time_until_next_wave_ms = 0; - if (game->enemies_spawned_this_wave >= game->enemies_per_wave) { - if (game->wave_cooldown_timestamp_ms > game->clock_ms) { - time_until_next_wave_ms = game->wave_cooldown_timestamp_ms - game->clock_ms; - } - } - - Dqn_f32 mid_x = platform->core.window_size.x * .5f; - if (time_until_next_wave_ms) { - TELY_Render_TextF(renderer, - Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y), - Dqn_V2_InitNx1(0.5f), - "%.1fs remaining until Wave %u!", - (time_until_next_wave_ms / 1000.f), game->current_wave + 1); - } else { - TELY_Render_TextF(renderer, Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y), Dqn_V2_InitNx1(0.5f), "Wave %u", game->current_wave); - } - } - - if (!FP_Game_IsNilEntityHandle(game, game->clicked_entity)) { - // NOTE: Render building blueprint ========================================================= - if (game->active_menu == FP_GameActiveMenu_Build) { - FP_GameEntity *entity = FP_Game_GetEntity(game, game->clicked_entity); - FP_GamePlaceableBuilding placeable_building = PLACEABLE_BUILDINGS[game->build_mode_building_index]; - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, placeable_building.type, placeable_building.state, entity->direction); - Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, placeable_building, 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, - render_data.sheet->tex_handle, - render_data.sheet_rect, - dest_rect, - Dqn_V2_Zero /*rotate origin*/, - 0.f /*rotation*/, - colour); - } - - // NOTE: Render the building selector UI =================================================== + // NOTE: Render the wave =================================================== { TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); DQN_DEFER { TELY_Render_PopTransform(renderer); }; - game->build_mode_building_index = DQN_CLAMP(game->build_mode_building_index, 0, DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS) - 1); - Dqn_f32 building_ui_size = 64.f; - Dqn_f32 padding = 10.f; - Dqn_f32 start_x = player_avatar_rect.pos.x; - DQN_FOR_UINDEX (building_index, DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS)) { - FP_GamePlaceableBuilding building = PLACEABLE_BUILDINGS[building_index]; - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, building.type, building.state, FP_GameDirection_Down); - Dqn_Rect rect = Dqn_Rect_InitNx4(start_x + (building_index * building_ui_size) + (padding * building_index), - next_pos.y, - building_ui_size, - building_ui_size); + TELY_Render_PushFont(renderer, game->talkco_font_large); + DQN_DEFER { TELY_Render_PopFont(renderer); }; - Dqn_V4 texture_colour = TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, .5f); - Dqn_V4 outline_colour = TELY_COLOUR_WHITE_PALE_GOLDENROD_V4; - if (game->build_mode_building_index == building_index) { - outline_colour = TELY_COLOUR_RED_TOMATO_V4; - texture_colour.a = 1.f; + uint64_t time_until_next_wave_ms = 0; + if (game->enemies_spawned_this_wave >= game->enemies_per_wave) { + if (game->wave_cooldown_timestamp_ms > game->clock_ms) { + time_until_next_wave_ms = game->wave_cooldown_timestamp_ms - game->clock_ms; } + } - TELY_Render_RectColourV4(renderer, rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, 0.5f)); + Dqn_f32 mid_x = platform->core.window_size.x * .5f; + if (time_until_next_wave_ms) { + TELY_Render_TextF(renderer, + Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y), + Dqn_V2_InitNx1(0.5f), + "%.1fs remaining until Wave %u!", + (time_until_next_wave_ms / 1000.f), game->current_wave + 1); + } else { + TELY_Render_TextF(renderer, Dqn_V2_InitNx2(mid_x, player_avatar_rect.pos.y), Dqn_V2_InitNx1(0.5f), "Wave %u", game->current_wave); + } + } + + if (!FP_Game_IsNilEntityHandle(game, game->clicked_entity)) { + // NOTE: Render building blueprint ========================================================= + if (game->in_game_menu == FP_GameInGameMenu_Build) { + FP_GameEntity *entity = FP_Game_GetEntity(game, game->clicked_entity); + FP_GamePlaceableBuilding placeable_building = PLACEABLE_BUILDINGS[game->build_mode_building_index]; + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, placeable_building.type, placeable_building.state, entity->direction); + Dqn_Rect dest_rect = FP_Game_GetBuildingPlacementRectForEntity(game, placeable_building, 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, render_data.sheet->tex_handle, render_data.sheet_rect, - rect, + dest_rect, Dqn_V2_Zero /*rotate origin*/, 0.f /*rotation*/, - texture_colour); + colour); + } - uint32_t building_count = 0; - if (building.type == FP_EntityType_ClubTerry) - building_count = player->inventory.clubs; - else if (building.type == FP_EntityType_AirportTerry) - building_count = player->inventory.airports; - else if (building.type == FP_EntityType_KennelTerry) - building_count = player->inventory.kennels; - else if (building.type == FP_EntityType_ChurchTerry) - building_count = player->inventory.churchs; + // NOTE: Render the building selector UI =================================================== + { + TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); + DQN_DEFER { TELY_Render_PopTransform(renderer); }; + game->build_mode_building_index = DQN_CLAMP(game->build_mode_building_index, 0, DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS) - 1); - TELY_Render_PushFont(renderer, game->talkco_font); - DQN_DEFER { TELY_Render_PopFont(renderer); }; + Dqn_f32 building_ui_size = 64.f; + Dqn_f32 padding = 10.f; + Dqn_f32 start_x = player_avatar_rect.pos.x; + DQN_FOR_UINDEX (building_index, DQN_ARRAY_UCOUNT(PLACEABLE_BUILDINGS)) { + FP_GamePlaceableBuilding building = PLACEABLE_BUILDINGS[building_index]; + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, building.type, building.state, FP_GameDirection_Down); + Dqn_Rect rect = Dqn_Rect_InitNx4(start_x + (building_index * building_ui_size) + (padding * building_index), + next_pos.y, + building_ui_size, + building_ui_size); - Dqn_V2 label_p = Dqn_Rect_InterpolatedPoint(rect, Dqn_V2_InitNx2(0.5f, 1.25f)); - TELY_Render_TextF(renderer, label_p, Dqn_V2_InitNx2(0.5f, 0.5f), "x %u", building_count); + Dqn_V4 texture_colour = TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, .5f); + Dqn_V4 outline_colour = TELY_COLOUR_WHITE_PALE_GOLDENROD_V4; + if (game->build_mode_building_index == building_index) { + outline_colour = TELY_COLOUR_RED_TOMATO_V4; + texture_colour.a = 1.f; + } - TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4(renderer, rect, TELY_RenderShapeMode_Line, outline_colour); - cmd->thickness = 2.f; + TELY_Render_RectColourV4(renderer, rect, TELY_RenderShapeMode_Fill, TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, 0.5f)); + TELY_Render_TextureColourV4(renderer, + render_data.sheet->tex_handle, + render_data.sheet_rect, + rect, + Dqn_V2_Zero /*rotate origin*/, + 0.f /*rotation*/, + texture_colour); + + uint32_t building_count = 0; + if (building.type == FP_EntityType_ClubTerry) + building_count = player->inventory.clubs; + else if (building.type == FP_EntityType_AirportTerry) + building_count = player->inventory.airports; + else if (building.type == FP_EntityType_KennelTerry) + building_count = player->inventory.kennels; + else if (building.type == FP_EntityType_ChurchTerry) + building_count = player->inventory.churchs; + + TELY_Render_PushFont(renderer, game->talkco_font); + DQN_DEFER { TELY_Render_PopFont(renderer); }; + + Dqn_V2 label_p = Dqn_Rect_InterpolatedPoint(rect, Dqn_V2_InitNx2(0.5f, 1.25f)); + TELY_Render_TextF(renderer, label_p, Dqn_V2_InitNx2(0.5f, 0.5f), "x %u", building_count); + + TELY_RenderCommandRect *cmd = TELY_Render_RectColourV4(renderer, rect, TELY_RenderShapeMode_Line, outline_colour); + cmd->thickness = 2.f; + } } } + + // NOTE: Add scanlines into the game for A E S T H E T I C S + Dqn_V2 screen_size = Dqn_V2_InitNx2(platform->core.window_size.w, platform->core.window_size.h); + Dqn_f32 scanline_gap = 4.0f; + Dqn_f32 scanline_thickness = 3.0f; + FP_GameRenderCameraFollowScanlines(renderer, screen_size, game->camera.world_pos, scanline_gap, scanline_thickness); } - // NOTE: Add scanlines into the game for A E S T H E T I C S - Dqn_V2 screen_size = Dqn_V2_InitNx2(platform->core.window_size.w, platform->core.window_size.h); - Dqn_f32 scanline_gap = 4.0f; - Dqn_f32 scanline_thickness = 3.0f; - FP_GameRenderCameraFollowScanlines(renderer, screen_size, game->camera.world_pos, scanline_gap, scanline_thickness); -} - -extern "C" __declspec(dllexport) -void TELY_DLL_FrameUpdate(void *user_data) -{ - TELY_Platform *platform = DQN_CAST(TELY_Platform *) user_data; - TELY_PlatformInput *input = &platform->input; - TELY_Assets *assets = &platform->assets; - TELY_Renderer *renderer = &platform->renderer; - FP_Game *game = DQN_CAST(FP_Game *) platform->user_data; - TELY_RFui *rfui = &game->rfui; - - TELY_Render_ClearColourV3(renderer, TELY_COLOUR_BLACK_MIDNIGHT_V4.rgb); - TELY_Render_PushFont(renderer, game->jetbrains_mono_font); - - TELY_RFui_FrameSetup(rfui, &platform->frame_arena); - TELY_RFui_PushFont(rfui, game->jetbrains_mono_font); - TELY_RFui_PushLabelColourV4(rfui, TELY_COLOUR_BLACK_MIDNIGHT_V4); - - // ============================================================================================= - - game->prev_clicked_entity = game->clicked_entity; - game->prev_hot_entity = game->hot_entity; - game->prev_active_entity = game->active_entity; - game->hot_entity = {}; - game->active_entity = {}; - Dqn_FArray_Clear(&game->parent_entity_stack); - Dqn_FArray_Add(&game->parent_entity_stack, game->root_entity->handle); - - Dqn_M2x3 model_view = FP_Game_CameraModelViewM2x3(game->camera, platform); - TELY_Render_PushTransform(renderer, model_view); - Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos; - - // ============================================================================================= - - TELY_Audio *audio = &platform->audio; - - #if 0 - if (audio->playback_size == 0) { - TELY_Audio_Play(audio, game->audio[FP_GameAudio_TestAudio], 1.f /*volume*/); - } - #endif - - // ============================================================================================= - - if (TELY_Platform_InputKeyWasDown(input->mouse_left) && TELY_Platform_InputKeyIsDown(input->mouse_left)) { - if (game->prev_active_entity.id) - game->active_entity = game->prev_active_entity; - } else { - for (FP_GameEntityIterator it = {}; FP_Game_DFSPreOrderWalkEntityTree(game, &it, game->root_entity); ) { - FP_GameEntity *entity = it.entity; - if (entity->local_hit_box_size.x <= 0 || entity->local_hit_box_size.y <= 0) - continue; - - if ((entity->flags & FP_GameEntityFlag_Clickable) == 0) - continue; - - Dqn_Rect world_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle); - if (!Dqn_Rect_ContainsPoint(world_hit_box, world_mouse_p)) - continue; - - game->hot_entity = entity->handle; - if (TELY_Platform_InputKeyIsPressed(input->mouse_left)) { - game->active_entity = entity->handle; - game->clicked_entity = entity->handle; - } - } - } - - for (game->delta_s_accumulator += DQN_CAST(Dqn_f32)input->delta_s; - game->delta_s_accumulator > PHYSICS_STEP; - game->delta_s_accumulator -= PHYSICS_STEP) { - FP_Update(platform, game, input); - } - - FP_Render(game, platform, renderer); - // NOTE: UI ==================================================================================== TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); DQN_DEFER { TELY_Render_PopTransform(renderer); }; @@ -3164,6 +3047,74 @@ void TELY_DLL_FrameUpdate(void *user_data) } } } +} + +extern "C" __declspec(dllexport) +void TELY_DLL_FrameUpdate(void *user_data) +{ + TELY_Platform *platform = DQN_CAST(TELY_Platform *) user_data; + TELY_PlatformInput *input = &platform->input; + TELY_Assets *assets = &platform->assets; + TELY_Renderer *renderer = &platform->renderer; + FP_Game *game = DQN_CAST(FP_Game *) platform->user_data; + TELY_RFui *rfui = &game->rfui; + + // ============================================================================================= + + game->prev_clicked_entity = game->clicked_entity; + game->prev_hot_entity = game->hot_entity; + game->prev_active_entity = game->active_entity; + game->hot_entity = {}; + game->active_entity = {}; + Dqn_FArray_Clear(&game->parent_entity_stack); + Dqn_FArray_Add(&game->parent_entity_stack, game->root_entity->handle); + + // ============================================================================================= + + TELY_Audio *audio = &platform->audio; + + #if 0 + if (audio->playback_size == 0) { + TELY_Audio_Play(audio, game->audio[FP_GameAudio_TestAudio], 1.f /*volume*/); + } + #endif + + // ============================================================================================= + + if (game->state == FP_GameState_Play) { + if (TELY_Platform_InputKeyWasDown(input->mouse_left) && TELY_Platform_InputKeyIsDown(input->mouse_left)) { + if (game->prev_active_entity.id) + game->active_entity = game->prev_active_entity; + } else { + Dqn_V2 world_mouse_p = input->mouse_p + game->camera.world_pos; + for (FP_GameEntityIterator it = {}; FP_Game_DFSPreOrderWalkEntityTree(game, &it, game->root_entity); ) { + FP_GameEntity *entity = it.entity; + if (entity->local_hit_box_size.x <= 0 || entity->local_hit_box_size.y <= 0) + continue; + + if ((entity->flags & FP_GameEntityFlag_Clickable) == 0) + continue; + + Dqn_Rect world_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle); + if (!Dqn_Rect_ContainsPoint(world_hit_box, world_mouse_p)) + continue; + + game->hot_entity = entity->handle; + if (TELY_Platform_InputKeyIsPressed(input->mouse_left)) { + game->active_entity = entity->handle; + game->clicked_entity = entity->handle; + } + } + } + } + + for (game->delta_s_accumulator += DQN_CAST(Dqn_f32)input->delta_s; + game->delta_s_accumulator > PHYSICS_STEP; + game->delta_s_accumulator -= PHYSICS_STEP) { + FP_Update(platform, game, input); + } + + FP_Render(game, platform, renderer); TELY_RFui_Flush(rfui, renderer, input, assets); TELY_Audio_MixPlaybackSamples(audio, assets); diff --git a/feely_pona_entity.h b/feely_pona_entity.h index 4df4129..9b6d6ee 100644 --- a/feely_pona_entity.h +++ b/feely_pona_entity.h @@ -29,7 +29,6 @@ enum FP_EntityType enum FP_EntityTerryState { - FP_EntityTerryState_Nil, FP_EntityTerryState_Idle, FP_EntityTerryState_Attack, FP_EntityTerryState_RangeAttack, @@ -39,14 +38,12 @@ enum FP_EntityTerryState enum FP_EntityMobSpawnerState { - FP_EntityMobSpawnerState_Nil, FP_EntityMobSpawnerState_Idle, FP_EntityMobSpawnerState_Shutdown, }; enum FP_EntitySmoochieState { - FP_EntitySmoochieState_Nil, FP_EntitySmoochieState_Idle, FP_EntitySmoochieState_Attack, FP_EntitySmoochieState_HurtSide, @@ -56,7 +53,6 @@ enum FP_EntitySmoochieState enum FP_EntityCatfishState { - FP_EntityCatfishState_Nil, FP_EntityCatfishState_Idle, FP_EntityCatfishState_Attack, FP_EntityCatfishState_Death, @@ -65,7 +61,6 @@ enum FP_EntityCatfishState enum FP_EntityClingerState { - FP_EntityClingerState_Nil, FP_EntityClingerState_Idle, FP_EntityClingerState_Attack, FP_EntityClingerState_Death, @@ -74,82 +69,63 @@ enum FP_EntityClingerState enum FP_EntityMerchantTerryState { - FP_EntityMerchantTerryState_Nil, FP_EntityMerchantTerryState_Idle, }; enum FP_EntityMerchantGymState { - FP_EntityMerchantGymState_Nil, FP_EntityMerchantGymState_Idle, }; enum FP_EntityMerchantPhoneCompanyState { - FP_EntityMerchantPhoneCompanyState_Nil, FP_EntityMerchantPhoneCompanyState_Idle, }; enum FP_EntityMerchantGraveyardState { - FP_EntityMerchantGraveyardState_Nil, FP_EntityMerchantGraveyardState_Idle, }; enum FP_EntityClubTerryState { - FP_EntityClubTerryState_Nil, FP_EntityClubTerryState_Idle, FP_EntityClubTerryState_PartyTime, }; enum FP_EntityAirportTerryState { - FP_EntityAirportTerryState_Nil, FP_EntityAirportTerryState_Idle, FP_EntityAirportTerryState_FlyPassenger, }; enum FP_EntityAirportTerryPlaneState { - FP_EntityAirportTerryPlaneState_Nil, FP_EntityAirportTerryPlaneState_Idle, FP_EntityAirportTerryPlaneState_FlyPassenger, }; enum FP_EntityChurchTerryState { - FP_EntityChurchTerryState_Nil, FP_EntityChurchTerryState_Idle, FP_EntityChurchTerryState_ConvertPatron, }; enum FP_EntityKennelTerryState { - FP_EntityKennelTerryState_Nil, FP_EntityKennelTerryState_Idle, }; enum FP_EntityMapState { - FP_EntityMapState_Nil, FP_EntityMapState_Idle, }; enum FP_EntityHeartState { - FP_EntityHeartState_Nil, FP_EntityHeartState_Idle, }; -enum FP_EntityPortalMonkeyState -{ - FP_EntityPortalMonkeyState_Nil, - FP_EntityPortalMonkeyState_Idle, - FP_EntityPortalMonkeyState_BeingCarried, - FP_EntityPortalMonkeyState_DisablingPortal, -}; - struct FP_EntityRenderData { FP_Meters height; diff --git a/feely_pona_entity_create.cpp b/feely_pona_entity_create.cpp index 9a96264..69709b0 100644 --- a/feely_pona_entity_create.cpp +++ b/feely_pona_entity_create.cpp @@ -35,7 +35,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 1.8f; FP_EntityTerryState state = DQN_CAST(FP_EntityTerryState)raw_state; switch (state) { - case FP_EntityTerryState_Nil: break; case FP_EntityTerryState_Idle: result.anim_name = g_anim_names.terry_walk_idle; break; case FP_EntityTerryState_Attack: { @@ -84,7 +83,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 1.6f; FP_EntitySmoochieState state = DQN_CAST(FP_EntitySmoochieState)raw_state; switch (state) { - case FP_EntitySmoochieState_Nil: break; case FP_EntitySmoochieState_Idle: result.anim_name = g_anim_names.smoochie_walk_down; break; case FP_EntitySmoochieState_Attack: result.anim_name = g_anim_names.smoochie_attack_down; break; case FP_EntitySmoochieState_HurtSide: result.anim_name = g_anim_names.smoochie_hurt_side; result.flip = direction == FP_GameDirection_Right ? TELY_AssetFlip_X : TELY_AssetFlip_No; break; @@ -105,7 +103,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 3.66f; FP_EntityMerchantTerryState state = DQN_CAST(FP_EntityMerchantTerryState)raw_state; switch (state) { - case FP_EntityMerchantTerryState_Nil: break; case FP_EntityMerchantTerryState_Idle: result.anim_name = g_anim_names.merchant_terry; break; } } break; @@ -114,7 +111,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 3.66f; FP_EntityMerchantGraveyardState state = DQN_CAST(FP_EntityMerchantGraveyardState)raw_state; switch (state) { - case FP_EntityMerchantGraveyardState_Nil: break; case FP_EntityMerchantGraveyardState_Idle: result.anim_name = g_anim_names.merchant_graveyard; break; } } break; @@ -124,7 +120,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.anim_name = g_anim_names.merchant_gym; FP_EntityMerchantGymState state = DQN_CAST(FP_EntityMerchantGymState)raw_state; switch (state) { - case FP_EntityMerchantGymState_Nil: break; case FP_EntityMerchantGymState_Idle: result.anim_name = g_anim_names.merchant_gym; break; } } break; @@ -133,7 +128,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 3.66f; FP_EntityMerchantPhoneCompanyState state = DQN_CAST(FP_EntityMerchantPhoneCompanyState)raw_state; switch (state) { - case FP_EntityMerchantPhoneCompanyState_Nil: break; case FP_EntityMerchantPhoneCompanyState_Idle: result.anim_name = g_anim_names.merchant_phone_company; break; } } break; @@ -142,7 +136,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 4.f; FP_EntityClubTerryState state = DQN_CAST(FP_EntityClubTerryState)raw_state; switch (state) { - case FP_EntityClubTerryState_Nil: break; case FP_EntityClubTerryState_Idle: result.anim_name = g_anim_names.club_terry_dark; break; case FP_EntityClubTerryState_PartyTime: result.anim_name = g_anim_names.club_terry_alive; break; } @@ -152,7 +145,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 1.6f; FP_EntityClingerState state = DQN_CAST(FP_EntityClingerState)raw_state; switch (state) { - case FP_EntityClingerState_Nil: break; case FP_EntityClingerState_Idle: result.anim_name = g_anim_names.clinger_walk_down; break; case FP_EntityClingerState_Attack: { @@ -183,7 +175,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 4.f; FP_EntityHeartState state = DQN_CAST(FP_EntityHeartState)raw_state; switch (state) { - case FP_EntityHeartState_Nil: break; case FP_EntityHeartState_Idle: result.anim_name = g_anim_names.heart; break; } } break; @@ -192,7 +183,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 4.f; FP_EntityAirportTerryState state = DQN_CAST(FP_EntityAirportTerryState)raw_state; switch (state) { - case FP_EntityAirportTerryState_Nil: break; case FP_EntityAirportTerryState_Idle: result.anim_name = g_anim_names.airport_terry; break; case FP_EntityAirportTerryState_FlyPassenger: result.anim_name = g_anim_names.airport_terry; break; } @@ -202,7 +192,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 1.6f; FP_EntityCatfishState state = DQN_CAST(FP_EntityCatfishState)raw_state; switch (state) { - case FP_EntityCatfishState_Nil: case FP_EntityCatfishState_Idle: result.anim_name = g_anim_names.catfish_walk_down; break; case FP_EntityCatfishState_Attack: { switch (direction) { @@ -230,7 +219,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 4.f; FP_EntityChurchTerryState state = DQN_CAST(FP_EntityChurchTerryState)raw_state; switch (state) { - case FP_EntityChurchTerryState_Nil: break; case FP_EntityChurchTerryState_Idle: result.anim_name = g_anim_names.church_terry_dark; break; case FP_EntityChurchTerryState_ConvertPatron: result.anim_name = g_anim_names.church_terry_alive; break; } @@ -240,7 +228,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 3.f; FP_EntityKennelTerryState state = DQN_CAST(FP_EntityKennelTerryState)raw_state; switch (state) { - case FP_EntityKennelTerryState_Nil: break; case FP_EntityKennelTerryState_Idle: result.anim_name = g_anim_names.kennel_terry; break; } } break; @@ -259,7 +246,6 @@ FP_EntityRenderData FP_Entity_GetRenderData(FP_Game *game, FP_EntityType type, u result.height.meters = 3.f; FP_EntityMobSpawnerState state = DQN_CAST(FP_EntityMobSpawnerState)raw_state; switch (state) { - case FP_EntityMobSpawnerState_Nil: break; case FP_EntityMobSpawnerState_Idle: result.anim_name = g_anim_names.portal; break; case FP_EntityMobSpawnerState_Shutdown: { result.anim_name = g_anim_names.portal_break; @@ -326,7 +312,9 @@ static FP_GameEntityHandle FP_Entity_CreateClinger(FP_Game *game, Dqn_V2 pos, DQ entity->is_dying = false; entity->base_acceleration_per_s.meters = 8.f; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; entity->attack_cooldown_ms = 1000; entity->faction = FP_GameEntityFaction_Foe; @@ -334,6 +322,9 @@ static FP_GameEntityHandle FP_Entity_CreateClinger(FP_Game *game, Dqn_V2 pos, DQ FP_Entity_AddDebugEditorFlags(game, entity->handle); entity->flags |= FP_GameEntityFlag_NonTraversable; entity->flags |= FP_GameEntityFlag_Attackable; + + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); return result; } @@ -349,13 +340,19 @@ static FP_GameEntityHandle FP_Entity_CreateSmoochie(FP_Game *game, Dqn_V2 pos, D entity->base_acceleration_per_s.meters = 8.f; entity->is_dying = false; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; entity->attack_cooldown_ms = 1000; entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.7f, entity->sprite_height.meters * .6f); + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, entity->handle); entity->flags |= FP_GameEntityFlag_NonTraversable; entity->flags |= FP_GameEntityFlag_Attackable; entity->faction = FP_GameEntityFaction_Foe; + return result; } @@ -371,7 +368,12 @@ static FP_GameEntityHandle FP_Entity_CreateCatfish(FP_Game *game, Dqn_V2 pos, DQ entity->base_acceleration_per_s.meters = 8.f; entity->is_dying = false; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + entity->attack_cooldown_ms = 1000; entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.7f, entity->sprite_height.meters * .6f); FP_Entity_AddDebugEditorFlags(game, entity->handle); @@ -424,9 +426,13 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos, entity->type = FP_EntityType_MobSpawner; entity->local_pos = pos; entity->local_hit_box_size = Dqn_V2_InitNx1(32); - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; FP_Entity_AddDebugEditorFlags(game, result); + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + entity->spawn_cap = spawn_cap; entity->spawn_list = FP_SentinelList_Init(game->chunk_pool); return result; @@ -443,7 +449,12 @@ static FP_GameEntityHandle FP_Entity_CreateTerry(FP_Game *game, Dqn_V2 pos, DQN_ entity->type = FP_EntityType_Terry; entity->local_pos = pos; entity->base_acceleration_per_s.meters = 16.f; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + entity->attack_cooldown_ms = 500; entity->local_hit_box_size = FP_Game_MetersToPixelsNx2(game, 0.5f, entity->sprite_height.meters * .6f); entity->hp_cap = FP_DEFAULT_DAMAGE * 3; @@ -469,7 +480,12 @@ static FP_GameEntityHandle FP_Entity_CreateMerchantTerry(FP_Game *game, Dqn_V2 p entity->type = FP_EntityType_MerchantTerry; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -493,7 +509,12 @@ static FP_GameEntityHandle FP_Entity_CreateMerchantGraveyard(FP_Game *game, Dqn_ entity->type = FP_EntityType_MerchantGraveyard; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -517,7 +538,12 @@ static FP_GameEntityHandle FP_Entity_CreateMerchantGym(FP_Game *game, Dqn_V2 pos entity->type = FP_EntityType_MerchantGym; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -541,7 +567,12 @@ static FP_GameEntityHandle FP_Entity_CreateMerchantPhoneCompany(FP_Game *game, D entity->type = FP_EntityType_MerchantPhoneCompany; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -565,7 +596,12 @@ static FP_GameEntityHandle FP_Entity_CreateClubTerry(FP_Game *game, Dqn_V2 pos, entity->type = FP_EntityType_ClubTerry; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -589,7 +625,12 @@ static FP_GameEntityHandle FP_Entity_CreateHeart(FP_Game *game, Dqn_V2 pos, DQN_ entity->type = FP_EntityType_Heart; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -613,7 +654,12 @@ static FP_GameEntityHandle FP_Entity_CreateChurchTerry(FP_Game *game, Dqn_V2 pos entity->type = FP_EntityType_ChurchTerry; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -637,7 +683,12 @@ static FP_GameEntityHandle FP_Entity_CreateKennelTerry(FP_Game *game, Dqn_V2 pos entity->type = FP_EntityType_KennelTerry; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -661,7 +712,12 @@ static FP_GameEntityHandle FP_Entity_CreateAirportTerry(FP_Game *game, Dqn_V2 po entity->type = FP_EntityType_AirportTerry; entity->local_pos = pos; - entity->sprite_height = FP_Entity_GetRenderData(game, entity->type, 0 /*state*/, FP_GameDirection_Down).height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_NonTraversable; @@ -684,11 +740,15 @@ static FP_GameEntityHandle FP_Entity_CreatePhoneMessageProjectile(FP_Game *game, va_end(args); entity->type = FP_EntityType_PhoneMessageProjectile; - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); entity->constant_acceleration_per_s = velocity; entity->local_pos = pos; - entity->sprite_height = render_data.height; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); + FP_Entity_AddDebugEditorFlags(game, result); entity->flags |= FP_GameEntityFlag_TTL; @@ -699,10 +759,6 @@ static FP_GameEntityHandle FP_Entity_CreatePhoneMessageProjectile(FP_Game *game, entity->ttl_end_timestamp = game->clock_ms + 1000; entity->projectile_owner = owner; entity->faction = FP_GameEntityFaction_Friendly; - - uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; - FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); - return result; } @@ -714,19 +770,19 @@ static FP_GameEntityHandle FP_Entity_CreatePortalMonkey(FP_Game *game, Dqn_V2 po FP_GameEntityHandle result = entity->handle; va_end(args); - entity->type = FP_EntityType_PortalMonkey; - FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->type = FP_EntityType_PortalMonkey; + entity->local_pos = pos; + + FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); - entity->local_pos = pos; - entity->sprite_height = render_data.height; FP_Entity_AddDebugEditorFlags(game, result); entity->local_hit_box_offset = Dqn_V2_InitNx2(0, render_data.render_size.h * .1f); entity->local_hit_box_size = Dqn_V2_InitNx2(render_data.render_size.w, render_data.render_size.h - (render_data.render_size.h * .4f)); - uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; - FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); - return result; } @@ -740,18 +796,16 @@ static FP_GameEntityHandle FP_Entity_CreateAirportTerryPlane(FP_Game *game, Dqn_ entity->type = FP_EntityType_AirportTerryPlane; FP_EntityRenderData render_data = FP_Entity_GetRenderData(game, entity->type, 0, FP_GameDirection_Down); + entity->sprite_height = render_data.height; + uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; + FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); entity->local_pos = pos; - entity->sprite_height = render_data.height; entity->flags |= FP_GameEntityFlag_NoClip; FP_Entity_AddDebugEditorFlags(game, result); entity->local_hit_box_offset = Dqn_V2_InitNx2(0, render_data.render_size.h * .1f); entity->local_hit_box_size = Dqn_V2_InitNx2(render_data.render_size.w, render_data.render_size.h - (render_data.render_size.h * .4f)); entity->base_acceleration_per_s.meters = 32.f; - - uint64_t duration_ms = FP_GAME_ENTITY_ACTION_INFINITE_TIMER; - FP_Game_EntityActionReset(game, result, duration_ms, render_data.sprite); - return result; } diff --git a/feely_pona_game.h b/feely_pona_game.h index b296e29..bf81507 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -263,11 +263,17 @@ enum FP_GameAudio FP_GameAudio_Count, }; -enum FP_GameActiveMenu +enum FP_GameInGameMenu { - FP_GameActiveMenu_Nil, - FP_GameActiveMenu_Build, - FP_GameActiveMenu_Merchant, + FP_GameInGameMenu_Nil, + FP_GameInGameMenu_Build, + FP_GameInGameMenu_Merchant, +}; + +enum FP_GameState +{ + FP_GameState_IntroScreen, + FP_GameState_Play, }; struct FP_Game @@ -275,6 +281,7 @@ struct FP_Game Dqn_f32 delta_s_accumulator; uint16_t tile_size; TELY_ChunkPool *chunk_pool; + TELY_AssetFontHandle inter_regular_font_large; TELY_AssetFontHandle inter_regular_font; TELY_AssetFontHandle inter_italic_font; TELY_AssetFontHandle jetbrains_mono_font; @@ -319,7 +326,7 @@ struct FP_Game Dqn_PCG32 rng; bool debug_ui; - FP_GameActiveMenu active_menu; + FP_GameInGameMenu in_game_menu; bool build_mode_can_place_building; Dqn_usize build_mode_building_index; @@ -330,6 +337,8 @@ struct FP_Game uint32_t enemies_per_wave; uint32_t enemies_spawned_this_wave; uint64_t wave_cooldown_timestamp_ms; + + FP_GameState state; }; struct FP_GameAStarNode