76 lines
2.3 KiB
Rust
76 lines
2.3 KiB
Rust
use std::net::SocketAddr;
|
|
|
|
use avian2d::{math::Vector, prelude::*};
|
|
use bevy::{input::common_conditions::input_pressed, prelude::*};
|
|
use clap::{Args, Parser};
|
|
|
|
mod game;
|
|
use game::{
|
|
runtime::{move_camera, move_player, quit, zoom_camera},
|
|
seed::Seed,
|
|
setup::{setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls},
|
|
};
|
|
|
|
/// The initial configuration passed to the game's setup functions.
|
|
/// Also functions as a Bevy plugin to pass the configuration into the app.
|
|
#[derive(Parser)]
|
|
#[command(version, about)]
|
|
pub struct AppSettings {
|
|
#[command(flatten)]
|
|
source: Source,
|
|
|
|
#[arg(short, long, default_value = "25565")]
|
|
port: u16,
|
|
}
|
|
|
|
#[derive(Args)]
|
|
#[group(required = false, multiple = false)]
|
|
struct Source {
|
|
#[arg(short, long)]
|
|
seed: Option<Seed>,
|
|
#[arg(short, long)]
|
|
connect: Option<SocketAddr>,
|
|
}
|
|
|
|
impl Plugin for AppSettings {
|
|
fn build(&self, app: &mut App) {
|
|
app.insert_resource(Gravity(Vector::ZERO))
|
|
.add_plugins((
|
|
DefaultPlugins.set(WindowPlugin {
|
|
primary_window: Window {
|
|
title: "Distributed physics test".into(),
|
|
fit_canvas_to_parent: true,
|
|
..default()
|
|
}
|
|
.into(),
|
|
..default()
|
|
}),
|
|
PhysicsPlugins::default().with_length_unit(50.0),
|
|
))
|
|
.add_systems(
|
|
Startup,
|
|
(
|
|
setup_from_seed,
|
|
setup_ui,
|
|
(setup_player, setup_balls, setup_walls).after(setup_from_seed),
|
|
),
|
|
)
|
|
.add_systems(
|
|
Update,
|
|
(
|
|
move_player,
|
|
quit.run_if(input_pressed(KeyCode::KeyQ)),
|
|
zoom_camera,
|
|
),
|
|
)
|
|
.add_systems(PostUpdate, move_camera);
|
|
if let Some(ref seed) = self.source.seed {
|
|
app.insert_resource(seed.clone());
|
|
} else if let Some(ref peer) = self.source.connect {
|
|
println!("{peer}");
|
|
todo!("Handle connecting to peer and retrieving seed");
|
|
} else {
|
|
app.insert_resource(Seed::random());
|
|
}
|
|
}
|
|
}
|