diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-26 16:53:07 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-26 16:53:07 +0200 |
commit | 2ca6ac7ab329036d0155de2de4b0a11f3a785414 (patch) | |
tree | 7472368efb282a4380b45931f3462e9930f48a36 /server/src/customer/movement.rs | |
parent | c4b0f8d698b574c711b1e205371adfd3e3339487 (diff) | |
download | hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.bz2 hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.zst |
boosting
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 { |