Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Perrelli9338 committed Oct 4, 2024
1 parent a9c88b7 commit 7090d32
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
43 changes: 41 additions & 2 deletions src/resources/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Font>,
}
#[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<Image>,
#[asset(path = "textures/bomb.png")]
pub bomb: Handle<Image>,
#[asset(path = "textures/flag.png")]
pub flag: Handle<Image>,
#[asset(path = "textures/tile_uncovered.png")]
pub tile: Handle<Image>,
#[asset(path = "textures/tile_covered.png")]
pub covered_tile: Handle<Image>,
#[asset(path = "textures/wrong.png")]
pub wrong: Handle<Image>,
}

#[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<Font>,
}

#[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")]
Expand All @@ -27,4 +66,4 @@ pub struct TextureAssets {
pub covered_tile: Handle<Image>,
#[asset(path = "embedded://textures/wrong.png")]
pub wrong: Handle<Image>,
}
}
14 changes: 6 additions & 8 deletions src/resources/tile_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 7090d32

Please sign in to comment.