diff options
-rw-r--r-- | src/cell.rs | 16 | ||||
-rw-r--r-- | src/constants.rs | 25 | ||||
-rw-r--r-- | src/main.rs | 34 |
3 files changed, 53 insertions, 22 deletions
diff --git a/src/cell.rs b/src/cell.rs index 6b42fdf..1659289 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -11,7 +11,7 @@ pub enum Occupant { Green, Yellow, Red, - Diamond, + Blue, Explosion, } @@ -24,12 +24,12 @@ impl Default for Occupant { 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, + 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, } } } @@ -39,7 +39,7 @@ impl Distribution<Occupant> for Standard { match rng.gen_range(0..=3) { 0 => Occupant::Green, 1 => Occupant::Yellow, - 2 => Occupant::Diamond, + 2 => Occupant::Blue, 3 => Occupant::Red, _ => Occupant::None, } diff --git a/src/constants.rs b/src/constants.rs index 5952fa5..c33e30b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -6,3 +6,28 @@ pub const SHIFT_X: f32 = 50.0; pub const SHIFT_Y: f32 = 50.0; pub const COLUMNS: usize = 8; pub const ROWS: usize = 8; + +pub const TILESHEET_GREEN: u32 = 0; +pub const TILESHEET_YELLOW: u32 = 1; +pub const TILESHEET_BLUE: u32 = 2; +pub const TILESHEET_RED: u32 = 3; + +pub const TILESHEET_EXPLOSION1: u32 = 4; +pub const TILESHEET_EXPLOSION2: u32 = 5; +pub const TILESHEET_EXPLOSION3: u32 = 6; +pub const TILESHEET_EXPLOSION4: u32 = 7; + +pub const TILESHEET_COSMONAUT1: u32 = 8; +pub const TILESHEET_VISOR1: u32 = 9; +pub const TILESHEET_VISOR2: u32 = 10; +pub const TILESHEET_NONE1: u32 = 11; + +pub const TILESHEET_COSMONAUT2: u32 = 12; +pub const TILESHEET_VISOR3: u32 = 13; +pub const TILESHEET_VISOR4: u32 = 14; +pub const TILESHEET_NONE2: u32 = 15; + +pub const TILESHEET_STAR1: u32 = 16; +pub const TILESHEET_STAR2: u32 = 17; +pub const TILESHEET_STAR3: u32 = 18; +pub const TILESHEET_NONE3: u32 = 19; diff --git a/src/main.rs b/src/main.rs index 566ded5..97592eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn star_spawning_system(commands: &mut Commands, time: Res<Time>, mut q: Query<& timer.reset(); commands .spawn(SpriteSheetBundle { - sprite: TextureAtlasSprite::new(16), + sprite: TextureAtlasSprite::new(constants::TILESHEET_STAR1), transform: Transform { translation: Vec3 { x: thread_rng().gen_range(-300..300) as f32, @@ -59,7 +59,7 @@ pub fn setup( ..Default::default() }) .spawn(SpriteSheetBundle { - sprite: TextureAtlasSprite::new(8), + sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT1), texture_atlas: atlas_handle.clone(), transform: Transform { translation: Vec3 { @@ -74,7 +74,7 @@ pub fn setup( }) .spawn((Timer::from_seconds(1.0, false),)) .spawn(SpriteSheetBundle { - sprite: TextureAtlasSprite::new(12), + sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT2), texture_atlas: atlas_handle.clone(), transform: Transform { translation: Vec3 { @@ -93,7 +93,7 @@ pub fn setup( commands .spawn(SpriteSheetBundle { texture_atlas: atlas_handle.clone(), - sprite: TextureAtlasSprite::new(11), + sprite: TextureAtlasSprite::new(constants::TILESHEET_NONE1), transform: Transform { translation: Vec3 { x: ((i as f32) * 16.0 * 3.5) - 320.0, @@ -119,16 +119,22 @@ fn animation_system( timer.tick(time.delta_seconds()); if timer.finished() { let index = match sprite.index { - 9 => 10, - 10 => 13, - 13 => 14, - 11 => 12, - 16 => 17, - 17 => 18, - _ => 11, + constants::TILESHEET_EXPLOSION1 => constants::TILESHEET_EXPLOSION2, + constants::TILESHEET_EXPLOSION2 => constants::TILESHEET_EXPLOSION3, + constants::TILESHEET_EXPLOSION3 => constants::TILESHEET_EXPLOSION4, + + constants::TILESHEET_VISOR1 => constants::TILESHEET_VISOR2, + constants::TILESHEET_VISOR2 => constants::TILESHEET_VISOR3, + constants::TILESHEET_VISOR3 => constants::TILESHEET_VISOR4, + + constants::TILESHEET_STAR1 => constants::TILESHEET_STAR2, + constants::TILESHEET_STAR2 => constants::TILESHEET_STAR3, + + constants::TILESHEET_NONE1 => constants::TILESHEET_NONE2, + _ => constants::TILESHEET_NONE1, }; sprite.index = index; - if index == 12 { + if index == constants::TILESHEET_NONE2 { commands.despawn(entity); } } @@ -151,11 +157,11 @@ fn cosmonaut_detect_system( && transform.translation.x + 16.0 * 3.5 > cursor_position.x && transform.translation.y < cursor_position.y && transform.translation.y + 16.0 * 3.5 > cursor_position.y - && sprite.index == 8 + && sprite.index == constants::TILESHEET_COSMONAUT1 { commands .spawn(SpriteSheetBundle { - sprite: TextureAtlasSprite::new(9), + sprite: TextureAtlasSprite::new(constants::TILESHEET_VISOR1), transform: *transform, ..Default::default() }) |