locate player in room
This commit is contained in:
33
src/map.rs
33
src/map.rs
@@ -12,35 +12,6 @@ pub fn xy_idx(x: i32, y: i32) -> usize {
|
||||
(y as usize * 80) + x as usize
|
||||
}
|
||||
|
||||
fn new_map_test() -> Vec<TileType> {
|
||||
let mut map = vec![TileType::Floor; 80 * 50];
|
||||
|
||||
// Make the boundaries walls
|
||||
for x in 0..80 {
|
||||
map[xy_idx(x, 0)] = TileType::Wall;
|
||||
map[xy_idx(x, 49)] = TileType::Wall;
|
||||
}
|
||||
for y in 0..50 {
|
||||
map[xy_idx(0, y)] = TileType::Wall;
|
||||
map[xy_idx(79, y)] = TileType::Wall;
|
||||
}
|
||||
|
||||
// Now we'll randomly splat a bunch of walls. It won't be pretty, but it's a decent illustration.
|
||||
// First, obtain the thread-local RNG:
|
||||
let mut rng = rltk::RandomNumberGenerator::new();
|
||||
|
||||
for _i in 0..400 {
|
||||
let x = rng.roll_dice(1, 79);
|
||||
let y = rng.roll_dice(1, 49);
|
||||
let idx = xy_idx(x, y);
|
||||
if idx != xy_idx(40, 25) {
|
||||
map[idx] = TileType::Wall;
|
||||
}
|
||||
}
|
||||
|
||||
map
|
||||
}
|
||||
|
||||
fn apply_room_to_map(room: &Rect, map: &mut Vec<TileType>) {
|
||||
for x in room.x1..room.x2 {
|
||||
for y in room.y1..room.y2 {
|
||||
@@ -61,7 +32,7 @@ fn apply_vertical_tunnel(map: &mut Vec<TileType>, x: i32, y1: i32, y2: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
|
||||
pub fn new_map_rooms_and_corridors() -> (Vec<Rect>,Vec<TileType>) {
|
||||
let mut map = vec![TileType::Wall; 80 * 50];
|
||||
|
||||
let mut rooms: Vec<Rect> = Vec::new();
|
||||
@@ -110,7 +81,7 @@ pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
|
||||
}
|
||||
}
|
||||
|
||||
map
|
||||
(rooms,map)
|
||||
}
|
||||
|
||||
pub fn draw_map(map: &[TileType], ctx: &mut Rltk) {
|
||||
|
||||
Reference in New Issue
Block a user