From a12a7d218b00c4ed44819ac8f0dd05bbf42204c7 Mon Sep 17 00:00:00 2001 From: doyle Date: Thu, 21 Sep 2023 17:11:07 +1000 Subject: [PATCH] fp: Add dashing --- feely_pona.cpp | 32 +++++++++++++++++++++++++++++--- feely_pona.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/feely_pona.cpp b/feely_pona.cpp index 89f5f0b..8f7b4ff 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -660,7 +660,8 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render // NOTE: Move entity by keyboard =========================================================== Dqn_V2 acceleration = {}; - if (game->clicked_entity == entity->handle) { + if (game->clicked_entity == entity->handle && + (entity->action.state == FP_GameEntityState_Run || entity->action.state == FP_GameEntityState_Idle)) { if (entity->flags & FP_EntityFlag_MoveByKeyboard) { acceleration = dir_vector * 10000000.f; if (dir_vector.x) @@ -840,6 +841,7 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render { bool we_are_clicked_entity = entity->handle == game->clicked_entity; bool action_has_finished = action->timer_s != FP_GAME_ENTITY_ACTION_INFINITE_TIMER && action->timer_s >= action->end_at_s; + bool entity_has_velocity = entity->velocity.x || entity->velocity.y; if (action->state == FP_GameEntityState_Nil) FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); @@ -907,7 +909,31 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render } else if (we_are_clicked_entity) { if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) { FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA); - } else if (dir_vector.x == 0.f && dir_vector.y == 0.f) { + } else if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_LeftShift)) { + FP_Game_EntityActionSetState(action, FP_GameEntityState_Dash); + } + } + + if ((action_has_finished && !entity_has_velocity) || (we_are_clicked_entity && dir_vector.x == 0.f && dir_vector.y == 0.f)) { + FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); + } + } + + if (action->state == FP_GameEntityState_Dash) { + if (action->flags & FP_GameEntityActionFlag_StateTransition) { + TELY_AssetSpriteAnimation *anim = entity->sprite_anims.data + TELY_Asset_GetSpriteAnimation(entity->sprite_anims, DQN_STRING8("Floor slide")).index; + FP_Game_EntityActionReset(action, anim->count * anim->seconds_per_frame, anim); + + Dqn_V2 dash_dir = {entity->facing_left ? -1.f : 1.f, 0.f}; + Dqn_V2 dash_acceleration = dash_dir * 400'000'000.f; + Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s); + entity->velocity = (dash_acceleration * t) + entity->velocity * 2.0f; + + } else if (action_has_finished) { + if (entity_has_velocity) { + // TODO(doyle): Not sure if this branch triggers properly. + FP_Game_EntityActionSetState(action, FP_GameEntityState_Run); + } else { FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); } } @@ -967,7 +993,7 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render else attack_dir_vector.x = -1.f; - Dqn_V2 acceleration = attack_dir_vector * 500000.f; + Dqn_V2 acceleration = attack_dir_vector * 500'000.f; Dqn_f32 t = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s); Dqn_f32 t_squared = DQN_SQUARED(t); diff --git a/feely_pona.h b/feely_pona.h index 798f92f..376bcb0 100644 --- a/feely_pona.h +++ b/feely_pona.h @@ -50,6 +50,7 @@ enum FP_GameEntityState FP_GameEntityState_AttackB, FP_GameEntityState_AttackC, FP_GameEntityState_Run, + FP_GameEntityState_Dash, }; struct FP_GameWaypoint