diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/protocol/src/lib.rs | 2 | ||||
-rw-r--r-- | server/protocol/src/movement.rs (renamed from server/src/customer/movement.rs) | 25 | ||||
-rw-r--r-- | server/src/customer/mod.rs | 6 | ||||
-rw-r--r-- | server/src/customer/pathfinding.rs | 4 |
4 files changed, 21 insertions, 16 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 895af376..f2a6dd27 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -28,6 +28,8 @@ use std::{ pub use glam; +pub mod movement; + pub const VERSION: (u32, u32) = (1, 0); pub const BINCODE_CONFIG: Configuration<LittleEndian, Varint, Limit<4096>> = diff --git a/server/src/customer/movement.rs b/server/protocol/src/movement.rs index 34ed5b16..486da816 100644 --- a/server/src/customer/movement.rs +++ b/server/protocol/src/movement.rs @@ -16,7 +16,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use hurrycurry_protocol::{glam::{IVec2, Vec2}, PacketS}; +use crate::{ + glam::{IVec2, Vec2}, + PacketS, +}; use std::collections::HashSet; const PLAYER_SIZE: f32 = 0.4; @@ -29,7 +32,8 @@ const BOOST_RESTORE: f32 = 0.5; pub struct MovementBase { pub position: Vec2, pub facing: Vec2, - pub vel: Vec2, + pub rotation: f32, + pub velocity: Vec2, pub boosting: bool, pub stamina: f32, } @@ -39,9 +43,10 @@ impl MovementBase { Self { position, facing: Vec2::X, - vel: Vec2::ZERO, + velocity: Vec2::ZERO, boosting: false, stamina: 0., + rotation: 0., } } pub fn update( @@ -55,7 +60,7 @@ impl MovementBase { if direction.length() > 0.1 { self.facing = direction + (self.facing - direction) * (-dt * 10.).exp(); } - let rot = self.facing.x.atan2(self.facing.y); + self.rotation = self.facing.x.atan2(self.facing.y); boost &= direction.length() > 0.1; self.boosting = boost && (self.boosting || self.stamina >= 1.) && self.stamina > 0.; self.stamina += if self.boosting { @@ -65,15 +70,15 @@ impl MovementBase { }; 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 * PLAYER_FRICTION).exp(); + self.velocity += direction * dt * speed; + self.position += self.velocity * dt; + self.velocity = self.velocity * (-dt * PLAYER_FRICTION).exp(); collide_player(self, map); PacketS::Position { pos: self.position, - boosting: false, - rot, + boosting: self.boosting, + rot: self.rotation, } } } @@ -98,7 +103,7 @@ pub fn collide_player(p: &mut MovementBase, map: &HashSet<IVec2>) { let grad = (Vec2::new(d_sample_x, d_sample_y) - d) / h; p.position += (PLAYER_SIZE - d) * grad; - p.vel -= grad * grad.dot(p.vel); + p.velocity -= grad * grad.dot(p.velocity); } } } diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index aeaa7ae1..bf385927 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -15,15 +15,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -pub mod movement; mod pathfinding; use crate::{data::Gamedata, game::Tile}; use anyhow::{anyhow, Result}; use fake::{faker, Fake}; -use hurrycurry_protocol::{glam::IVec2, DemandIndex, Message, PacketS, PlayerID}; +use hurrycurry_protocol::{ + glam::IVec2, movement::MovementBase, DemandIndex, Message, PacketS, PlayerID, +}; use log::info; -use movement::MovementBase; use pathfinding::{find_path, Path}; use rand::{random, thread_rng}; use std::{ diff --git a/server/src/customer/pathfinding.rs b/server/src/customer/pathfinding.rs index 2b9f98f4..d1e1e997 100644 --- a/server/src/customer/pathfinding.rs +++ b/server/src/customer/pathfinding.rs @@ -15,10 +15,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use super::movement::MovementBase; use hurrycurry_protocol::{ - glam::{IVec2, Vec2}, - PacketS, + glam::{IVec2, Vec2}, movement::MovementBase, PacketS }; use log::trace; use std::{ |