From e9e2a21f14f923bb5941f1e1d8efd0c7f772775a Mon Sep 17 00:00:00 2001 From: dan63047 Date: Thu, 9 Nov 2023 23:43:30 +0300 Subject: [PATCH] how to put this into engine??? --- src/engine/mod.rs | 1 + src/engine/randomizers.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/engine/randomizers.rs diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 61751ab..7bd8e90 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -5,6 +5,7 @@ mod rotation_systems; mod systems; mod components; mod resources; +pub mod randomizers; pub struct UBSGEngine; diff --git a/src/engine/randomizers.rs b/src/engine/randomizers.rs new file mode 100644 index 0000000..c248b07 --- /dev/null +++ b/src/engine/randomizers.rs @@ -0,0 +1,26 @@ +use rand::seq::SliceRandom; +use rand::thread_rng; + +use super::{rotation_systems::PiecesData, resources::Piece}; + +pub trait Randomizer{ + fn populate_next(&self, pieces_data: PiecesData) -> Vec; +} + +pub struct Bag {} + +impl Randomizer for Bag { + fn populate_next(&self, pieces_data: PiecesData) -> Vec { + let mut bag = vec![]; + let mut id: usize = 0; + for _ in pieces_data.pieces{ + let final_position = (3+pieces_data.spawn_offsets[id].0, 20+pieces_data.spawn_offsets[id].1); + let element = Piece { id: id, position: final_position, rotation: 0 }; + id += 1; + bag.insert(0, element); + } + let mut rng = thread_rng(); + bag.shuffle(&mut rng); + bag + } +} \ No newline at end of file