From 965ccb56c4c58066939d74bea22c2a9b59416d0d Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 21 Mar 2021 17:51:55 +0100 Subject: moved cell stuff to another file --- src/main.rs | 215 ++---------------------------------------------------------- 1 file changed, 6 insertions(+), 209 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f0a7eb6..566ded5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,181 +1,8 @@ use bevy::math::Vec3; use bevy::prelude::*; +use gems::cell::{self, Cell}; use gems::constants; -use rand::{ - distributions::{Distribution, Standard}, - thread_rng, 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