aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-11 01:30:59 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-11 01:35:05 +0200
commit218da36b4f963a5dfcd619d543cb95c5c196d214 (patch)
tree244ecd10f4ca3d9798cedf7149394a1d4827b5d9 /server/bot/src
parentf753629acd906ff7acd42a18a266cc93a883330c (diff)
downloadhurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar
hurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar.bz2
hurrycurry-218da36b4f963a5dfcd619d543cb95c5c196d214.tar.zst
update movement in protocol and all clients
Diffstat (limited to 'server/bot/src')
-rw-r--r--server/bot/src/main.rs59
1 files changed, 56 insertions, 3 deletions
diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs
index 0b625703..61cef1f9 100644
--- a/server/bot/src/main.rs
+++ b/server/bot/src/main.rs
@@ -16,6 +16,59 @@
*/
-fn main() {
-
-} \ No newline at end of file
+use std::{thread::sleep, time::Duration};
+
+use anyhow::Result;
+use hurrycurry_client_lib::{network::sync::Network, Game};
+use hurrycurry_protocol::{glam::Vec2, PacketC, PacketS, PlayerID};
+
+fn main() -> Result<()> {
+ let mut network = Network::connect("ws://127.0.0.1")?;
+
+ let mut game = Game::default();
+
+ network.queue_out.push_back(PacketS::Join {
+ name: "bot".to_string(),
+ character: 1,
+ });
+
+ let mut bots = Vec::new();
+
+ loop {
+ let dt = 1. / 50.;
+
+ network.poll()?;
+
+ while let Some(packet) = network.queue_in.pop_front() {
+ match &packet {
+ PacketC::Joined { id } => bots.push(Bot::new(*id)),
+ _ => (),
+ }
+ game.apply_packet(packet);
+ }
+
+ for b in &bots {
+ network.queue_out.push_back(PacketS::Movement {
+ player: b.id,
+ dir: Vec2::ONE,
+ boost: true,
+ pos: None,
+ });
+ }
+
+ sleep(Duration::from_secs_f32(dt));
+ }
+}
+
+pub struct Bot {
+ id: PlayerID,
+}
+
+impl Bot {
+ pub fn new(id: PlayerID) -> Self {
+ Self { id }
+ }
+ pub fn tick(&self, game: &Game) {
+ if let Some(player) = game.players.get(&self.id) {}
+ }
+}