aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs
index 3fef179..b2db950 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -5,6 +5,7 @@ use crate::shared::health::*;
use crate::shared::imperative::*;
use crate::shared::projectile::*;
use crate::shared::*;
+use bevy::input::keyboard::*;
use bevy::input::mouse::MouseButton;
use bevy::prelude::*;
use bevy::sprite::{MaterialMesh2dBundle, Mesh2dHandle};
@@ -41,6 +42,9 @@ struct ClientId(pub u64);
#[derive(Resource)]
struct MyChampion(pub Champion);
+#[derive(Resource)]
+struct Attack(Option<AttackKey>);
+
struct ClientPlugin {
pub server_addr: Option<SocketAddr>,
pub client_id: u64,
@@ -52,12 +56,14 @@ impl Plugin for ClientPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(ClientId(self.client_id))
.insert_resource(MyChampion(self.champion))
+ .insert_resource(Attack(None))
.add_plugins(NetworkPlugin {
server_addr: self.server_addr.clone(),
client_id: self.client_id,
transport: self.transport.clone(),
})
.add_systems(Startup, setup)
+ .add_systems(PreUpdate, choose_attack)
.add_systems(Update, (move_players, move_projectiles))
.add_systems(
Update,
@@ -138,12 +144,16 @@ fn buffer_input(
mouse_input: Res<ButtonInput<MouseButton>>,
mut client: ClientMut,
windows: Query<&Window>,
+ attack: Res<Attack>,
) {
if mouse_input.just_pressed(MouseButton::Left) {
if let Some((target_player, _)) =
hovered_other_player(&cameras, &client_id, &attackables, &windows)
{
- client.add_input(Inputs::Imperative(Imperative::Attack(target_player)));
+ client.add_input(Inputs::Imperative(Imperative::Attack(
+ attack.0.unwrap_or(AttackKey::A),
+ target_player,
+ )));
} else {
if let Some(world_position) = cursor_world_position(&windows, &cameras) {
client.add_input(Inputs::Imperative(Imperative::WalkTo(world_position)));
@@ -152,6 +162,26 @@ fn buffer_input(
}
}
+fn choose_attack(keyboard_input: Res<ButtonInput<KeyCode>>, mut attack_key: ResMut<Attack>) {
+ if keyboard_input.pressed(KeyCode::KeyA) {
+ attack_key.0 = Some(AttackKey::A);
+ } else if keyboard_input.pressed(KeyCode::KeyQ) {
+ attack_key.0 = Some(AttackKey::Q);
+ } else if keyboard_input.pressed(KeyCode::KeyW) {
+ attack_key.0 = Some(AttackKey::W);
+ } else if keyboard_input.pressed(KeyCode::KeyE) {
+ attack_key.0 = Some(AttackKey::E);
+ } else if keyboard_input.pressed(KeyCode::KeyR) {
+ attack_key.0 = Some(AttackKey::R);
+ } else if keyboard_input.pressed(KeyCode::KeyD) {
+ attack_key.0 = Some(AttackKey::D);
+ } else if keyboard_input.pressed(KeyCode::KeyF) {
+ attack_key.0 = Some(AttackKey::F);
+ } else if keyboard_input.pressed(KeyCode::Escape) {
+ attack_key.0 = None;
+ }
+}
+
fn gizmos_hover_indicator(
cameras: Query<(&Camera, &GlobalTransform)>,
client_id: Res<ClientId>,