From 7090d32aad37c1710cf92deef61cab47ac376df4 Mon Sep 17 00:00:00 2001 From: Perrelli9338 Date: Fri, 4 Oct 2024 18:59:39 +0200 Subject: [PATCH] Improvements --- src/resources/assets.rs | 43 +++++++++++++++++++++++++++++++++++++-- src/resources/tile_map.rs | 14 ++++++------- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/resources/assets.rs b/src/resources/assets.rs index f43e4f2..3d737e5 100644 --- a/src/resources/assets.rs +++ b/src/resources/assets.rs @@ -3,16 +3,55 @@ use bevy::{ prelude::{Font, Image, Resource}, }; use bevy_asset_loader::asset_collection::AssetCollection; - #[derive(AssetCollection, Resource)] pub struct AudioAssets {} +#[cfg(not(all( + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "wasm32") +)))] +#[derive(AssetCollection, Resource)] +pub struct FontAssets { + #[asset(path = "pixeled.ttf")] + pub font: Handle, +} +#[cfg(not(all( + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "wasm32") +)))] +#[derive(AssetCollection, Resource)] +pub struct TextureAssets { + #[asset(path = "textures/icon.png")] + pub icon: Handle, + #[asset(path = "textures/bomb.png")] + pub bomb: Handle, + #[asset(path = "textures/flag.png")] + pub flag: Handle, + #[asset(path = "textures/tile_uncovered.png")] + pub tile: Handle, + #[asset(path = "textures/tile_covered.png")] + pub covered_tile: Handle, + #[asset(path = "textures/wrong.png")] + pub wrong: Handle, +} +#[cfg(all( + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "wasm32") +))] #[derive(AssetCollection, Resource)] pub struct FontAssets { #[asset(path = "embedded://pixeled.ttf")] pub font: Handle, } +#[cfg(all( + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "wasm32") +))] #[derive(AssetCollection, Resource)] pub struct TextureAssets { #[asset(path = "embedded://textures/icon.png")] @@ -27,4 +66,4 @@ pub struct TextureAssets { pub covered_tile: Handle, #[asset(path = "embedded://textures/wrong.png")] pub wrong: Handle, -} \ No newline at end of file +} diff --git a/src/resources/tile_map.rs b/src/resources/tile_map.rs index 20d0ace..ac4b408 100644 --- a/src/resources/tile_map.rs +++ b/src/resources/tile_map.rs @@ -4,7 +4,6 @@ use rand::{thread_rng, Rng}; use std::ops::{Deref, DerefMut}; const RANGE: [(i8, i8); 8] = [ - // todo!() (-1, -1), (0, -1), (1, -1), @@ -45,18 +44,14 @@ impl TileMap { } pub fn is_bomb_at(&self, coordinates: Coordinates) -> bool { - if coordinates.x >= self.width || coordinates.y >= self.height { - return false; - } - - self.map[coordinates.y as usize][coordinates.x as usize].is_bomb() + !(coordinates.x >= self.width || coordinates.y >= self.height) && + self.map[coordinates.y as usize][coordinates.x as usize].is_bomb() } pub fn bomb_count_at(&self, coordinates: Coordinates) -> u8 { if self.is_bomb_at(coordinates) { return 0; } - let res = self .safe_square_at(coordinates) .filter(|c| self.is_bomb_at(*c)) @@ -73,7 +68,10 @@ impl TileMap { let column = rng.gen_range(0..self.width) as usize; if let Tile::Empty | Tile::BombNeighbour(0..=8) = self[row][column] { self[row][column] = Tile::Bomb; - self.bomb_coordinates.insert(Coordinates {y: row as u16, x: column as u16}); + self.bomb_coordinates.insert(Coordinates { + y: row as u16, + x: column as u16, + }); r_bombs -= 1; } }