change tiles

This commit is contained in:
klangner 2020-09-08 22:13:51 +02:00
parent 4cd00f62de
commit 7401b42790
2 changed files with 16 additions and 11 deletions

View File

@ -38,13 +38,13 @@ impl Tile for MapTiles {
let map = world.read_resource::<Map>();
let pos = Point::new(p.x as usize, p.y as usize);
if map.starting_point == Some(pos) {
Some(64)
Some(160)
} else if map.exit_point == Some(pos) {
Some(62)
Some(12)
} else if map.at(p.x as usize, p.y as usize) == TileType::Wall {
Some(35)
Some(320)
} else {
Some(46)
Some(19)
}
}
@ -104,7 +104,7 @@ impl SimpleState for PlayState {
init_map(&mut world);
let map_sprite_sheet_handle =
load_tiles_sprite_sheet(world, "texture/ascii.png", "texture/ascii.ron");
load_tiles_sprite_sheet(world, "texture/basic.png", "texture/basic.ron");
let (width, height) = {
let dim = world.read_resource::<ScreenDimensions>();

View File

@ -11,7 +11,7 @@ use std::fmt;
/// Position on the map
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
#[derive(Default, PartialEq, Copy, Clone, Debug, Eq, Hash)]
pub struct Point {
pub x: usize,
pub y: usize
@ -84,8 +84,12 @@ impl Map {
/// Get TileType at the given location
pub fn at(&self, x: usize, y: usize) -> TileType {
let idx = y * self.width + x;
self.tiles[idx]
if x >= self.width || y >= self.height {
TileType::Wall
} else {
let idx = (y as usize) * self.width + (x as usize);
self.tiles[idx]
}
}
/// Get available exists from the given tile
@ -109,14 +113,15 @@ impl Map {
// Check if given tile can be accessed
fn is_exit_valid(&self, x:usize, y:usize) -> bool {
if x < 1 || x > self.width-1 || y < 1 || y > self.height-1 { return false; }
self.at(x, y) == TileType::Floor
}
/// Modify tile at the given location
pub fn set_tile(&mut self, x: usize, y: usize, tile: TileType) {
let idx = y * self.width + x;
self.tiles[idx] = tile;
if x < self.width && y < self.height {
let idx = (y as usize) * self.width + (x as usize);
self.tiles[idx] = tile;
}
}
}