how to put this into engine???

This commit is contained in:
dan63047 2023-11-09 23:43:30 +03:00
parent 03b1847f57
commit e9e2a21f14
2 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,7 @@ mod rotation_systems;
mod systems; mod systems;
mod components; mod components;
mod resources; mod resources;
pub mod randomizers;
pub struct UBSGEngine; pub struct UBSGEngine;

26
src/engine/randomizers.rs Normal file
View File

@ -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<Piece>;
}
pub struct Bag {}
impl Randomizer for Bag {
fn populate_next(&self, pieces_data: PiecesData) -> Vec<Piece> {
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
}
}