57 lines
1.9 KiB
Rust
57 lines
1.9 KiB
Rust
use avian2d::{math::Vector, prelude::*};
|
|
use bevy::{input::common_conditions::input_pressed, prelude::*};
|
|
use bevy_rand::prelude::{EntropyPlugin, WyRand};
|
|
use clap::Parser;
|
|
|
|
mod game;
|
|
use game::{
|
|
runtime::{move_camera, move_player, quit, zoom_camera},
|
|
seed::Seed,
|
|
setup::{setup_balls, setup_player, setup_pseudo_random, 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 {
|
|
#[arg(short, long, default_value = ":)")]
|
|
pub seed: Seed,
|
|
}
|
|
|
|
impl Plugin for AppSettings {
|
|
fn build(&self, app: &mut App) {
|
|
app.insert_resource(Gravity(Vector::ZERO))
|
|
.insert_resource(self.seed.clone())
|
|
.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),
|
|
EntropyPlugin::<WyRand>::with_seed(self.seed.clone().into()),
|
|
))
|
|
.add_systems(
|
|
Startup,
|
|
(
|
|
setup_pseudo_random,
|
|
setup_ui,
|
|
(setup_player, setup_balls, setup_walls).after(setup_pseudo_random),
|
|
),
|
|
)
|
|
.add_systems(
|
|
Update,
|
|
(
|
|
move_player,
|
|
quit.run_if(input_pressed(KeyCode::KeyQ)),
|
|
zoom_camera,
|
|
),
|
|
)
|
|
.add_systems(PostUpdate, move_camera);
|
|
}
|
|
}
|