diff options
Diffstat (limited to 'server/protocol/src/movement.rs')
-rw-r--r-- | server/protocol/src/movement.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs index dad9d300..ebcc627d 100644 --- a/server/protocol/src/movement.rs +++ b/server/protocol/src/movement.rs @@ -29,7 +29,8 @@ const BOOST_DURATION: f32 = 0.3; const BOOST_RESTORE: f32 = 0.5; pub struct MovementBase { - pub direction: Vec2, + pub input_direction: Vec2, + pub input_boost: bool, pub position: Vec2, pub facing: Vec2, pub rotation: f32, @@ -41,8 +42,9 @@ pub struct MovementBase { impl MovementBase { pub fn new(position: Vec2) -> Self { Self { + input_direction: Vec2::ZERO, + input_boost: false, position, - direction: Vec2::ZERO, facing: Vec2::X, velocity: Vec2::ZERO, boosting: false, @@ -50,8 +52,13 @@ impl MovementBase { rotation: 0., } } - pub fn update(&mut self, map: &HashSet<IVec2>, direction: Vec2, mut boost: bool, dt: f32) { - self.direction = direction.clamp_length_max(1.); + pub fn input(&mut self, direction: Vec2, boost: bool) { + self.input_boost = boost; + self.input_direction = direction; + } + pub fn update(&mut self, map: &HashSet<IVec2>, dt: f32) { + let mut boost = self.input_boost; + let direction = self.input_direction.clamp_length_max(1.); if direction.length() > 0.1 { self.facing = direction + (self.facing - direction) * (-dt * 10.).exp(); } @@ -74,8 +81,8 @@ impl MovementBase { pub fn movement_packet(&self, player: PlayerID) -> PacketS { PacketS::Movement { pos: Some(self.position), - boosting: self.boosting, - direction: self.direction, + boost: self.input_boost, + dir: self.input_direction, player, } } |