Make RNG seedable
This commit is contained in:
parent
6732f5575c
commit
946e961633
5 changed files with 57 additions and 14 deletions
34
src/main.rs
34
src/main.rs
|
@ -9,18 +9,26 @@ use bevy::{
|
|||
input::common_conditions::input_pressed,
|
||||
prelude::*,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
use distributed_physics_test::Random;
|
||||
|
||||
const AREA_WIDTH: f32 = 750.;
|
||||
const PLAYER_SIZE: f32 = 30.;
|
||||
|
||||
fn main() {
|
||||
#[derive(Default)]
|
||||
struct AppSettings {
|
||||
seed: String,
|
||||
}
|
||||
|
||||
fn main() -> AppExit {
|
||||
run_app(AppSettings::default())
|
||||
}
|
||||
|
||||
fn run_app(settings: AppSettings) -> AppExit {
|
||||
App::new()
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
PhysicsPlugins::default()
|
||||
.with_length_unit(50.0)
|
||||
.set(PhysicsInterpolationPlugin::interpolate_all()),
|
||||
PhysicsPlugins::default().with_length_unit(50.0),
|
||||
))
|
||||
.add_systems(
|
||||
Startup,
|
||||
|
@ -31,11 +39,12 @@ fn main() {
|
|||
(move_player, quit.run_if(input_pressed(KeyCode::KeyQ))),
|
||||
)
|
||||
.insert_resource(Gravity(Vector::ZERO))
|
||||
.run();
|
||||
.insert_resource(Random::seed(&settings.seed))
|
||||
.run()
|
||||
}
|
||||
|
||||
fn setup_scene(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
commands.spawn((Name::new("Camera"), Camera2d, IsDefaultUiCamera));
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
|
@ -50,19 +59,16 @@ fn setup_balls(
|
|||
mut commands: Commands,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut rng: ResMut<Random>,
|
||||
) {
|
||||
let mut rng = rand::rng();
|
||||
for _ in 0..20 {
|
||||
let circle = Circle::new(rng.random_range(10.0..(PLAYER_SIZE - 5.)));
|
||||
let circle = Circle::new(rng.range(10.0..(PLAYER_SIZE - 5.)));
|
||||
let mut transform = Transform::from_xyz(
|
||||
0.,
|
||||
rng.random_range((PLAYER_SIZE + 5.)..(AREA_WIDTH / 2. - PLAYER_SIZE)),
|
||||
rng.range((PLAYER_SIZE + 5.)..(AREA_WIDTH / 2. - PLAYER_SIZE)),
|
||||
0.,
|
||||
);
|
||||
transform.rotate_around(
|
||||
Vec3::ZERO,
|
||||
Quat::from_rotation_z(rng.random_range(0.0..(PI * 2.))),
|
||||
);
|
||||
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_z(rng.range(0.0..(PI * 2.))));
|
||||
commands.spawn((
|
||||
Ball,
|
||||
Collider::from(circle),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue