use bevy::math::Vec3; use bevy::prelude::*; use gems::constants; use rand::{ distributions::{Distribution, Standard}, Rng, }; #[derive(Debug, PartialEq, Clone, Copy)] enum Occupant { None, Green, Yellow, Red, Diamond, Explosion, } impl Default for Occupant { fn default() -> Occupant { Occupant::None } } impl Occupant { pub fn to_index(&self) -> u32 { match self { Occupant::Green => 0, Occupant::Yellow => 1, Occupant::Red => 2, Occupant::Diamond => 3, Occupant::Explosion => 4, Occupant::None => 13, } } } impl Distribution for Standard { fn sample(&self, rng: &mut R) -> Occupant { match rng.gen_range(0..=3) { 0 => Occupant::Green, 1 => Occupant::Yellow, 2 => Occupant::Diamond, 3 => Occupant::Red, _ => Occupant::None, } } } #[derive(Debug, Clone, Default, Copy)] struct Cell { x: usize, y: usize, occupant: Occupant, selected: bool, hovered: bool, } impl Cell { pub fn new(x: usize, y: usize) -> Cell { Cell { x, y, occupant: Occupant::None, selected: false, hovered: false, } } } fn cell_insert_system(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { for (mut cell, mut sprite) in cell_query.iter_mut() { if cell.occupant == Occupant::None && cell.y == constants::ROWS - 1 { cell.occupant = rand::random(); sprite.index = cell.occupant.to_index(); } } } fn explosion_animation_system( time: Res