change tiles
This commit is contained in:
parent
4cd00f62de
commit
7401b42790
|
@ -38,13 +38,13 @@ impl Tile for MapTiles {
|
||||||
let map = world.read_resource::<Map>();
|
let map = world.read_resource::<Map>();
|
||||||
let pos = Point::new(p.x as usize, p.y as usize);
|
let pos = Point::new(p.x as usize, p.y as usize);
|
||||||
if map.starting_point == Some(pos) {
|
if map.starting_point == Some(pos) {
|
||||||
Some(64)
|
Some(160)
|
||||||
} else if map.exit_point == Some(pos) {
|
} 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 {
|
} else if map.at(p.x as usize, p.y as usize) == TileType::Wall {
|
||||||
Some(35)
|
Some(320)
|
||||||
} else {
|
} else {
|
||||||
Some(46)
|
Some(19)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ impl SimpleState for PlayState {
|
||||||
init_map(&mut world);
|
init_map(&mut world);
|
||||||
|
|
||||||
let map_sprite_sheet_handle =
|
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 (width, height) = {
|
||||||
let dim = world.read_resource::<ScreenDimensions>();
|
let dim = world.read_resource::<ScreenDimensions>();
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::fmt;
|
||||||
|
|
||||||
|
|
||||||
/// Position on the map
|
/// Position on the map
|
||||||
#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
#[derive(Default, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
pub x: usize,
|
pub x: usize,
|
||||||
pub y: usize
|
pub y: usize
|
||||||
|
@ -84,9 +84,13 @@ impl Map {
|
||||||
|
|
||||||
/// Get TileType at the given location
|
/// Get TileType at the given location
|
||||||
pub fn at(&self, x: usize, y: usize) -> TileType {
|
pub fn at(&self, x: usize, y: usize) -> TileType {
|
||||||
let idx = y * self.width + x;
|
if x >= self.width || y >= self.height {
|
||||||
|
TileType::Wall
|
||||||
|
} else {
|
||||||
|
let idx = (y as usize) * self.width + (x as usize);
|
||||||
self.tiles[idx]
|
self.tiles[idx]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get available exists from the given tile
|
/// Get available exists from the given tile
|
||||||
pub fn get_available_exits(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)> {
|
pub fn get_available_exits(&self, x: usize, y: usize) -> Vec<(usize, usize, f32)> {
|
||||||
|
@ -109,15 +113,16 @@ impl Map {
|
||||||
|
|
||||||
// Check if given tile can be accessed
|
// Check if given tile can be accessed
|
||||||
fn is_exit_valid(&self, x:usize, y:usize) -> bool {
|
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
|
self.at(x, y) == TileType::Floor
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modify tile at the given location
|
/// Modify tile at the given location
|
||||||
pub fn set_tile(&mut self, x: usize, y: usize, tile: TileType) {
|
pub fn set_tile(&mut self, x: usize, y: usize, tile: TileType) {
|
||||||
let idx = y * self.width + x;
|
if x < self.width && y < self.height {
|
||||||
|
let idx = (y as usize) * self.width + (x as usize);
|
||||||
self.tiles[idx] = tile;
|
self.tiles[idx] = tile;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Map {
|
impl fmt::Display for Map {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user