diff options
Diffstat (limited to 'server/src/customer')
-rw-r--r-- | server/src/customer/mod.rs | 8 | ||||
-rw-r--r-- | server/src/customer/movement.rs | 39 | ||||
-rw-r--r-- | server/src/customer/pathfinding.rs | 3 |
3 files changed, 38 insertions, 12 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index e6f999e6..ba65a5e2 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -25,7 +25,7 @@ use crate::{ }; use anyhow::{anyhow, Result}; use fake::{faker, Fake}; -use glam::{IVec2, Vec2}; +use glam::IVec2; use log::debug; use movement::MovementBase; use pathfinding::{find_path, Path}; @@ -115,11 +115,7 @@ impl DemandState { self.customers.insert( id, Customer { - movement: MovementBase { - position: data.customer_spawn, - facing: Vec2::X, - vel: Vec2::ZERO, - }, + movement: MovementBase::new(data.customer_spawn), state: CustomerState::Entering { path, chair }, }, ); 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 { diff --git a/server/src/customer/pathfinding.rs b/server/src/customer/pathfinding.rs index 5056975e..73999e0c 100644 --- a/server/src/customer/pathfinding.rs +++ b/server/src/customer/pathfinding.rs @@ -41,10 +41,11 @@ impl Path { player.update( &walkable, (next - player.position).normalize_or_zero() * 0.5, + false, dt, ) } else { - player.update(&walkable, Vec2::ZERO, dt) + player.update(&walkable, Vec2::ZERO, false, dt) } } pub fn is_done(&self) -> bool { |