use crate::constants; use bevy::prelude::*; use rand::{ distributions::{Distribution, Standard}, Rng, }; #[derive(Debug, PartialEq, Clone, Copy)] pub enum Occupant { None, Green, Yellow, Red, Blue, Explosion, } impl Default for Occupant { fn default() -> Occupant { Occupant::None } } impl Occupant { pub fn to_index(&self) -> u32 { match self { Occupant::Green => constants::TILESHEET_GREEN, Occupant::Yellow => constants::TILESHEET_YELLOW, Occupant::Red => constants::TILESHEET_RED, Occupant::Blue => constants::TILESHEET_BLUE, Occupant::Explosion => constants::TILESHEET_EXPLOSION1, Occupant::None => constants::TILESHEET_NONE1, } } } 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::Blue, 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