fp: Add dashing

This commit is contained in:
doyle 2023-09-21 17:11:07 +10:00
parent 8db9182fd9
commit a12a7d218b
2 changed files with 30 additions and 3 deletions

View File

@ -660,7 +660,8 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render
// NOTE: Move entity by keyboard =========================================================== // NOTE: Move entity by keyboard ===========================================================
Dqn_V2 acceleration = {}; 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) { if (entity->flags & FP_EntityFlag_MoveByKeyboard) {
acceleration = dir_vector * 10000000.f; acceleration = dir_vector * 10000000.f;
if (dir_vector.x) 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 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 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) if (action->state == FP_GameEntityState_Nil)
FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle); 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) { } else if (we_are_clicked_entity) {
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) { if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_J)) {
FP_Game_EntityActionSetState(action, FP_GameEntityState_AttackA); 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); FP_Game_EntityActionSetState(action, FP_GameEntityState_Idle);
} }
} }
@ -967,7 +993,7 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render
else else
attack_dir_vector.x = -1.f; 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 = DQN_CAST(Dqn_f32)DQN_SQUARED(input->delta_s);
Dqn_f32 t_squared = DQN_SQUARED(t); Dqn_f32 t_squared = DQN_SQUARED(t);

View File

@ -50,6 +50,7 @@ enum FP_GameEntityState
FP_GameEntityState_AttackB, FP_GameEntityState_AttackB,
FP_GameEntityState_AttackC, FP_GameEntityState_AttackC,
FP_GameEntityState_Run, FP_GameEntityState_Run,
FP_GameEntityState_Dash,
}; };
struct FP_GameWaypoint struct FP_GameWaypoint