From ef164fbbee3bd68b5e3641a761b94b7f0557e0e0 Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 8 Oct 2023 20:51:54 +1100 Subject: [PATCH] fp: Smoochie teleport --- feely_pona.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++----- feely_pona_game.h | 2 ++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index f86dfbe..5b50efb 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -1716,9 +1716,52 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input 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); - if (entity->type == FP_EntityType_Clinger && game->play.clock_ms >= entity->clinger_next_dash_timestamp) { - entity->clinger_next_dash_timestamp = game->play.clock_ms + 2000; - acceleration_meters_per_s = entity_to_waypoint_norm * entity->base_acceleration_per_s.meters * 45.f; + if (entity->type == FP_EntityType_Smoochie) { + if (waypoint_entity->type == FP_EntityType_Terry) { + if (dist_to_waypoint_sq < DQN_SQUARED(FP_Game_MetersToPixelsNx1(game->play, 2.f)) && + !entity->smoochie_has_teleported) { + + if (entity->smoochie_teleport_timestamp == 0) { + entity->smoochie_teleport_timestamp = game->play.clock_ms + DQN_CAST(Dqn_usize)(Dqn_PCG32_NextF32(&game->play.rng) * 5000); + } + + if (game->play.clock_ms < entity->smoochie_teleport_timestamp) { + Dqn_usize time_to_teleport_ms = entity->smoochie_teleport_timestamp - game->play.clock_ms; + if (time_to_teleport_ms < 2000) + entity->action.sprite_alpha = Dqn_PCG32_NextF32(&game->play.rng); + } else if (game->play.clock_ms >= entity->smoochie_teleport_timestamp) { + Dqn_Rect waypoint_rect = FP_Game_CalcEntityWorldHitBox(game, waypoint_entity->handle); + entity->smoochie_has_teleported = true; + entity->action.sprite_alpha = 1.f; + + Dqn_FArray teleport_pos = {}; + + if (waypoint_entity->direction != FP_GameDirection_Up) { + Dqn_FArray_Add(&teleport_pos, Dqn_Rect_InterpolatedPoint(waypoint_rect, Dqn_V2_InitNx2(0.5f, -1.2f))); + } + + if (waypoint_entity->direction != FP_GameDirection_Down) { + Dqn_FArray_Add(&teleport_pos, Dqn_Rect_InterpolatedPoint(waypoint_rect, Dqn_V2_InitNx2(0.5f, +1.2f))); + } + + if (waypoint_entity->direction != FP_GameDirection_Left) { + Dqn_FArray_Add(&teleport_pos, Dqn_Rect_InterpolatedPoint(waypoint_rect, Dqn_V2_InitNx2(-1.2f, +0.5f))); + } + + if (waypoint_entity->direction != FP_GameDirection_Right) { + Dqn_FArray_Add(&teleport_pos, Dqn_Rect_InterpolatedPoint(waypoint_rect, Dqn_V2_InitNx2(+1.2f, +0.5f))); + } + + uint32_t teleport_index = Dqn_PCG32_Range(&game->play.rng, 0, DQN_CAST(uint32_t)teleport_pos.size); + entity->local_pos = teleport_pos.data[teleport_index]; + } + } + } + } else if (entity->type == FP_EntityType_Clinger) { + if (game->play.clock_ms >= entity->clinger_next_dash_timestamp) { + entity->clinger_next_dash_timestamp = game->play.clock_ms + 2000; + acceleration_meters_per_s = entity_to_waypoint_norm * entity->base_acceleration_per_s.meters * 45.f; + } } break; } @@ -1998,9 +2041,12 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input Dqn_V2 entity_world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle); Dqn_Rect entity_hit_box = FP_Game_CalcEntityWorldHitBox(game, entity->handle); - Dqn_f32 step_y = (entity_hit_box.size.h / spawn_count) * 1.5f; - Dqn_V2 mob_world_pos = Dqn_V2_InitNx2(entity_world_pos.x, - entity_hit_box.pos.y + (Dqn_PCG32_NextF32(&game->play.rng) * step_y) + (step_y * spawn_index)); + Dqn_f32 step_y = (entity_hit_box.size.h / spawn_count) * 1.5f; + Dqn_f32 mob_y_offset = (Dqn_PCG32_NextF32(&game->play.rng) * step_y) + (step_y * spawn_index); + if (Dqn_PCG32_NextF32(&game->play.rng) >= .5f) + mob_y_offset *= -1; + + Dqn_V2 mob_world_pos = Dqn_V2_InitNx2(entity_world_pos.x, entity_world_pos.y + mob_y_offset); Dqn_f32 mob_choice = Dqn_PCG32_NextF32(&game->play.rng); if (mob_choice <= 0.33f) link->data = FP_Entity_CreateClinger(game, mob_world_pos, "Clinger"); diff --git a/feely_pona_game.h b/feely_pona_game.h index 3e8725d..6456fc7 100644 --- a/feely_pona_game.h +++ b/feely_pona_game.h @@ -221,6 +221,8 @@ struct FP_GameEntity Dqn_usize terry_mobile_data_plan; Dqn_usize terry_mobile_data_plan_cap; Dqn_usize clinger_next_dash_timestamp; + bool smoochie_has_teleported; + Dqn_usize smoochie_teleport_timestamp; Dqn_usize coins; FP_GameInventory inventory;