From 10b525e4c72e171de41890b247fab8744ef63cce Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Fri, 23 May 2025 23:49:11 -0400 Subject: [PATCH 1/2] Make only playable area seeded --- src/game/setup.rs | 13 +++++-------- src/lib.rs | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/game/setup.rs b/src/game/setup.rs index 4dc13ad..cd12f4d 100644 --- a/src/game/setup.rs +++ b/src/game/setup.rs @@ -24,13 +24,8 @@ const DIMENSION_SIZES: Range = 500.0..2000.0; #[derive(Resource)] pub struct PlayableArea(f32, f32); -/// The size of the player character -#[derive(Resource)] -pub struct PlayerSize(f32); - /// Initialize deterministic values -pub fn setup_pseudo_random(mut commands: Commands, mut rng: GlobalEntropy) { - commands.insert_resource(PlayerSize(rng.random_range(BALL_SIZES))); +pub fn setup_from_seed(mut commands: Commands, mut rng: GlobalEntropy) { commands.insert_resource(PlayableArea( rng.random_range(DIMENSION_SIZES), rng.random_range(DIMENSION_SIZES), @@ -46,9 +41,10 @@ pub fn setup_player( mut commands: Commands, mut materials: ResMut>, mut meshes: ResMut>, - radius: Res, ) { - let circle = Circle::new(radius.0); + let mut random = thread_rng(); + + let circle = Circle::new(random.random_range(BALL_SIZES)); commands.spawn(( Name::new("Player"), Player, @@ -66,6 +62,7 @@ pub fn setup_balls( region: Res, ) { let mut random = thread_rng(); + for i in 0..BALL_COUNT { let circle = Circle::new(random.random_range(BALL_SIZES)); commands.spawn(( diff --git a/src/lib.rs b/src/lib.rs index 1c1a86b..90a14b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ 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}, + setup::{setup_balls, setup_from_seed, setup_player, setup_ui, setup_walls}, }; /// The initial configuration passed to the game's setup functions. @@ -39,9 +39,9 @@ impl Plugin for AppSettings { .add_systems( Startup, ( - setup_pseudo_random, + setup_from_seed, setup_ui, - (setup_player, setup_balls, setup_walls).after(setup_pseudo_random), + (setup_player, setup_balls, setup_walls).after(setup_from_seed), ), ) .add_systems( From 0896ccf6913c77251d38054646f0a02af4f3db98 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Sat, 24 May 2025 00:43:44 -0400 Subject: [PATCH 2/2] Fix faster diagonal acceleration for the player Also always accelerate the player using the same force, so that bigger players aren't overpowered. --- src/game/objects.rs | 6 +++++- src/game/runtime.rs | 36 ++++++++++++++++++++++++++---------- src/game/setup.rs | 17 ++++++++++------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/game/objects.rs b/src/game/objects.rs index 2fbe122..da4f096 100644 --- a/src/game/objects.rs +++ b/src/game/objects.rs @@ -6,9 +6,13 @@ use bevy::prelude::*; #[require(Collider, Mesh2d, MeshMaterial2d, Restitution = Restitution::new(1.0), RigidBody, TransformInterpolation, Transform)] struct GameObject; +/// Radius of a ball +#[derive(Component, Default)] +pub struct Radius(pub f32); + /// A basic ball with which to interact #[derive(Component, Default)] -#[require(GameObject, RigidBody = RigidBody::Dynamic)] +#[require(GameObject, RigidBody = RigidBody::Dynamic, Radius)] pub struct Ball; /// The controllable ball diff --git a/src/game/runtime.rs b/src/game/runtime.rs index 81b1ddf..ab393ad 100644 --- a/src/game/runtime.rs +++ b/src/game/runtime.rs @@ -1,3 +1,5 @@ +use core::f32; + use avian2d::prelude::*; use bevy::{ input::mouse::{AccumulatedMouseScroll, MouseScrollUnit}, @@ -5,32 +7,46 @@ use bevy::{ prelude::*, }; -use super::objects::Player; +use super::objects::{Player, Radius}; /// Move the player character based on the keyboard input pub fn move_player( time: Res