diff options
Diffstat (limited to 'server/src/customer/movement.rs')
| -rw-r--r-- | server/src/customer/movement.rs | 39 | 
1 files changed, 34 insertions, 5 deletions
| diff --git a/server/src/customer/movement.rs b/server/src/customer/movement.rs index 3fcf37aa..a189ddce 100644 --- a/server/src/customer/movement.rs +++ b/server/src/customer/movement.rs @@ -20,25 +20,54 @@ use glam::{IVec2, Vec2};  use std::collections::HashSet;  const PLAYER_SIZE: f32 = 0.4; -const PLAYER_SPEED: f32 = 65.; -pub const PLAYER_SPEED_LIMIT: f32 = f32::INFINITY; // 10.; +const PLAYER_FRICTION: f32 = 10.0; +const PLAYER_SPEED: f32 = 40.0; +const BOOST_FACTOR: f32 = 3.0; +const BOOST_DURATION: f32 = 0.3; +const BOOST_RESTORE: f32 = 0.5;  pub struct MovementBase {      pub position: Vec2,      pub facing: Vec2,      pub vel: Vec2, +    pub boosting: bool, +    pub stamina: f32,  }  impl MovementBase { -    pub fn update(&mut self, map: &HashSet<IVec2>, direction: Vec2, dt: f32) -> PacketS { +    pub fn new(position: Vec2) -> Self { +        Self { +            position, +            facing: Vec2::X, +            vel: Vec2::ZERO, +            boosting: false, +            stamina: 0., +        } +    } +    pub fn update( +        &mut self, +        map: &HashSet<IVec2>, +        direction: Vec2, +        mut boost: bool, +        dt: f32, +    ) -> PacketS {          let direction = direction.clamp_length_max(1.);          if direction.length() > 0.1 {              self.facing = direction + (self.facing - direction) * (-dt * 10.).exp();          }          let rot = self.facing.x.atan2(self.facing.y); -        self.vel += direction * dt * PLAYER_SPEED; +        boost &= direction.length() > 0.1; +        self.boosting = boost && (self.boosting || self.stamina >= 1.) && self.stamina > 0.; +        self.stamina += if self.boosting { +            -dt / BOOST_DURATION +        } else { +            dt / BOOST_RESTORE +        }; +        self.stamina = self.stamina.max(0.).min(1.); +        let speed = PLAYER_SPEED * if self.boosting { BOOST_FACTOR } else { 1. }; +        self.vel += direction * dt * speed;          self.position += self.vel * dt; -        self.vel = self.vel * (-dt * 15.).exp(); +        self.vel = self.vel * (-dt * PLAYER_FRICTION).exp();          collide_player(self, map);          PacketS::Position { | 
