diff options
Diffstat (limited to 'server/bot/src/main.rs')
-rw-r--r-- | server/bot/src/main.rs | 59 |
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) {} + } +} |