diff --git a/rust-pvz-genetics/src/genetics/gene/mod.rs b/rust-pvz-genetics/src/genetics/gene/mod.rs index 09914e4..0260c42 100644 --- a/rust-pvz-genetics/src/genetics/gene/mod.rs +++ b/rust-pvz-genetics/src/genetics/gene/mod.rs @@ -9,6 +9,19 @@ pub use gene_source::GeneSource; pub use gene_place::GenePlace; use godot::builtin::Vector2; +#[macro_export] +macro_rules! radial_child_position { + ($radius:literal) => { + |_|{ + use rand::{RngExt}; + use godot::builtin::Vector2; + let mut rng = rand::rng(); + + Vector2::from_angle(rng.random_range(0.0..=1.0)*3.1415*2.) * rng.random_range(($radius/2.)..=$radius) + } + }; +} + #[derive(PartialEq,Eq,Clone)] pub struct Gene { pub plant_source: GeneSource, @@ -58,10 +71,9 @@ impl Gene { } - - impl Display for Gene { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f,"({}) {}",self.plant_source,self.place) } } + diff --git a/rust-pvz-genetics/src/genetics/plants/sunflower.rs b/rust-pvz-genetics/src/genetics/plants/sunflower.rs index 39f1291..0327b37 100644 --- a/rust-pvz-genetics/src/genetics/plants/sunflower.rs +++ b/rust-pvz-genetics/src/genetics/plants/sunflower.rs @@ -33,6 +33,6 @@ fn get_place_head(place: GenePlace) -> Vector2 { match place { GenePlace::Mouth => Vector2::new(1.,4.), GenePlace::Eyes => Vector2::new(1.,-2.), - _ =>return Vector2::ZERO + _ => crate::radial_child_position!(10.)(place.clone()) } }