aboutsummaryrefslogtreecommitdiff
path: root/server/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'server/protocol')
-rw-r--r--server/protocol/src/lib.rs7
-rw-r--r--server/protocol/src/movement.rs21
2 files changed, 20 insertions, 8 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index f2a6dd27..14c410b3 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -88,11 +88,12 @@ pub enum PacketS {
character: i32,
},
Leave,
- Position {
+ Movement {
#[bincode(with_serde)]
- pos: Vec2,
- rot: f32,
+ direction: Vec2,
boosting: bool,
+ #[bincode(with_serde)]
+ pos: Option<Vec2>,
},
Interact {
#[bincode(with_serde)]
diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs
index 9abff295..ab4eb818 100644
--- a/server/protocol/src/movement.rs
+++ b/server/protocol/src/movement.rs
@@ -72,21 +72,32 @@ impl MovementBase {
self.velocity += direction * dt * speed;
self.position += self.velocity * dt;
self.velocity = self.velocity * (-dt * PLAYER_FRICTION).exp();
- collide_player(self, map);
+ collide_player_tiles(self, map);
- PacketS::Position {
- pos: self.position,
+ PacketS::Movement {
+ pos: Some(self.position),
boosting: self.boosting,
- rot: self.rotation,
+ direction,
}
}
+ pub fn collide(&mut self, other: &mut Self, dt: f32) {
+ let diff = self.position - other.position;
+ let d = diff.length();
+ if d < 0.01 || d > PLAYER_SIZE * 2. {
+ return;
+ }
+ let norm = diff.normalize();
+ let f = 100. / (1. + d);
+ self.velocity += norm * f * dt
+ }
+
pub fn get_interact_target(&self) -> IVec2 {
(self.position + Vec2::new(self.rotation.sin(), self.rotation.cos())).as_ivec2()
}
}
-pub fn collide_player(p: &mut MovementBase, map: &HashSet<IVec2>) {
+fn collide_player_tiles(p: &mut MovementBase, map: &HashSet<IVec2>) {
for xo in -1..=1 {
for yo in -1..=1 {
let tile = IVec2::new(xo, yo) + p.position.as_ivec2();