diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 07:09:22 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 07:09:22 +0100 |
commit | 445a51c344ecea346051cf59d03b95c98bb28e75 (patch) | |
tree | 33f0327659b9f8ea0422b2452c8ec48e532cef3c /src/client.rs | |
parent | 716bd0618308d6100556d1231b0b156f48c64778 (diff) |
feat: flash ability
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/client.rs b/src/client.rs index b4213a2..ce48b4f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -295,9 +295,7 @@ fn buffer_input( let Some(position) = player_position(&client_id, &players) else { return; }; - let Some(direction) = (world_position - position.0).try_normalize() else { - return; - }; + let direction = world_position - position.0; client.add_input(Inputs::Imperative(Imperative::AttackDirection( ability_slot, direction, @@ -340,6 +338,7 @@ fn buffer_input( fn choose_attack( champion: Res<MyChampion>, keyboard_input: Res<ButtonInput<KeyCode>>, + mouse_input: Res<ButtonInput<MouseButton>>, mut attack: ResMut<Attack>, mut client: ClientMut, ) { @@ -359,7 +358,9 @@ fn choose_attack( attack.0 = Some(AbilitySlot::G); } else if keyboard_input.just_pressed(KeyCode::Escape) { attack.0 = None; - } else if keyboard_input.just_pressed(KeyCode::ShiftLeft) { + } else if keyboard_input.just_pressed(KeyCode::CapsLock) { + attack.0 = None; + } else if mouse_input.just_pressed(MouseButton::Right) { attack.0 = None; } match attack.0 { @@ -459,20 +460,26 @@ fn gizmos_attack_indicator( let Some(world_position) = cursor_world_position(&windows, &cameras) else { return; }; - let Some(direction) = (world_position - position.0).try_normalize() else { - return; - }; + let direction = world_position - position.0; match ability { DirectionalAbility::Dash(Dash { max_distance, .. }) => { let DashCollisionResult { dash_end, .. } = dash_collision( PlayerId(client_id.0), position.0, - direction, + direction.normalize_or_zero(), max_distance, &player_positions, ); gizmos.arrow_2d(position.0, dash_end, Color::YELLOW); } + DirectionalAbility::Flash(Flash { max_distance, .. }) => { + gizmos.arrow_2d( + position.0, + position.0 + + direction.length().min(max_distance) * direction.normalize_or_zero(), + Color::YELLOW, + ); + } DirectionalAbility::Pull(Pull { max_distance, .. }) => { let Some(PullCollision { pull_end, @@ -481,12 +488,12 @@ fn gizmos_attack_indicator( }) = pull_collision( PlayerId(client_id.0), position.0, - direction, + direction.normalize_or_zero(), max_distance, &player_positions, ) else { - let pull_direction = -max_distance * direction; + let pull_direction = -max_distance * direction.normalize_or_zero(); let pull_start = position.0 - pull_direction; let pull_end = pull_start + (pull_direction.length() - 2. * PLAYER_RADIUS) @@ -499,7 +506,7 @@ fn gizmos_attack_indicator( DirectionalAbility::Spear(Spear { max_distance, .. }) => { gizmos.arrow_2d( position.0, - position.0 + max_distance * direction, + position.0 + max_distance * direction.normalize_or_zero(), Color::YELLOW, ); } |