use crate::constants; use bevy::prelude::*; use rand::{ distributions::{Distribution, Standard}, Rng, }; #[derive(Debug, PartialEq, Clone, Copy)] pub 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)] pub struct Cell { pub x: usize, pub y: usize, pub occupant: Occupant, pub selected: bool, pub hovered: bool, } impl Cell { pub fn new(x: usize, y: usize) -> Cell { Cell { x, y, occupant: Occupant::None, selected: false, hovered: false, } } } pub fn insert(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(); } } } pub fn explosion_animation( time: Res