aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-06-26 16:53:07 +0200
committermetamuffin <metamuffin@disroot.org>2024-06-26 16:53:07 +0200
commit2ca6ac7ab329036d0155de2de4b0a11f3a785414 (patch)
tree7472368efb282a4380b45931f3462e9930f48a36 /server/src
parentc4b0f8d698b574c711b1e205371adfd3e3339487 (diff)
downloadhurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar
hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.bz2
hurrycurry-2ca6ac7ab329036d0155de2de4b0a11f3a785414.tar.zst
boosting
Diffstat (limited to 'server/src')
-rw-r--r--server/src/customer/mod.rs8
-rw-r--r--server/src/customer/movement.rs39
-rw-r--r--server/src/customer/pathfinding.rs3
-rw-r--r--server/src/game.rs38
4 files changed, 57 insertions, 31 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 {
diff --git a/server/src/game.rs b/server/src/game.rs
index 595816e1..20f479c7 100644
--- a/server/src/game.rs
+++ b/server/src/game.rs
@@ -16,7 +16,7 @@
*/
use crate::{
- customer::{movement::PLAYER_SPEED_LIMIT, DemandState},
+ customer::DemandState,
data::Gamedata,
interaction::{interact, tick_tile, InteractEffect, TickEffect},
protocol::{ItemIndex, Message, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex},
@@ -244,29 +244,29 @@ impl Game {
.get_mut(&player)
.ok_or(anyhow!("player does not exist"))?;
- let dt = player.last_position_ts.elapsed().as_secs_f32();
- let dist = pos.distance(player.position);
- let speed = dist / dt;
- let interact_dist = player
- .interacting
- .map(|p| (p.as_vec2() + Vec2::splat(0.5)).distance(player.position))
- .unwrap_or_default();
- let movement_ok = speed < PLAYER_SPEED_LIMIT && dist < 1. && interact_dist < 2.;
- if movement_ok {
- player.position = pos;
- player.last_position_ts = Instant::now();
- }
+ // let dt = player.last_position_ts.elapsed().as_secs_f32();
+ // let dist = pos.distance(player.position);
+ // let speed = dist / dt;
+ // let interact_dist = player
+ // .interacting
+ // .map(|p| (p.as_vec2() + Vec2::splat(0.5)).distance(player.position))
+ // .unwrap_or_default();
+ // let movement_ok = speed < PLAYER_SPEED_LIMIT && dist < 1. && interact_dist < 2.;
+ // if movement_ok {
+ player.position = pos;
+ player.last_position_ts = Instant::now();
+ // }
self.packet_out.push_back(PacketC::Position {
player: pid,
pos: player.position,
rot,
});
- if !movement_ok {
- bail!(
- "{:?} moved to quickly. speed={speed:.02} dist={dist:.02}",
- player.name
- )
- }
+ // if !movement_ok {
+ // bail!(
+ // "{:?} moved to quickly. speed={speed:.02} dist={dist:.02}",
+ // player.name
+ // )
+ // }
}
PacketS::Collide { player, force } => {
self.packet_out