From 02750384df3142bda62a7ce0feb08d115aa6af29 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 14 Mar 2024 14:24:43 +0100 Subject: feat: walking --- src/server.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index 3a7dd40..188aad1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,6 @@ use crate::protocol::*; use crate::server::network::*; +use crate::shared::imperative::*; use crate::shared::*; use bevy::prelude::*; use bevy::utils::HashMap; @@ -29,7 +30,8 @@ impl Plugin for ServerPlugin { transport: self.transport.clone(), }) .add_systems(Update, connections) - .add_systems(FixedUpdate, player_input); + .add_systems(FixedUpdate, player_input) + .add_systems(Update, imperative); } } @@ -63,16 +65,16 @@ fn connections( fn player_input( entity_map: Res, mut input_reader: EventReader>, - mut positions: Query<&mut PlayerPosition>, + mut imperatives: Query<&mut Imperative>, ) { for input in input_reader.read() { let client_id = input.context(); if let Some(input) = input.input() { if let Some(entity_id) = entity_map.0.get(client_id) { match input { - Inputs::Teleport(new_position) => { - if let Ok(mut position) = positions.get_mut(*entity_id) { - position.0 = *new_position; + Inputs::Imperative(new_imperative) => { + if let Ok(mut imperative) = imperatives.get_mut(*entity_id) { + *imperative = *new_imperative; } } _ => {} @@ -81,3 +83,25 @@ fn player_input( } } } + +const MOVEMENT_SPEED: f32 = 80.; + +fn imperative(mut players: Query<(&mut Imperative, &mut PlayerPosition)>, time: Res