Add basic map
This commit is contained in:
31
src/map_builders/common.rs
Normal file
31
src/map_builders/common.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::cmp::{max, min};
|
||||
|
||||
use crate::rect::Rect;
|
||||
use crate::{Map, TileType};
|
||||
|
||||
pub fn apply_room_to_map(map: &mut Map, room: &Rect) {
|
||||
for y in room.y1 + 1..=room.y2 {
|
||||
for x in room.x1 + 1..=room.x2 {
|
||||
let idx = map.xy_idx(x, y);
|
||||
map.tiles[idx] = TileType::Floor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_horizontal_tunnel(map: &mut Map, x1: i32, x2: i32, y: i32) {
|
||||
for x in min(x1, x2)..=max(x1, x2) {
|
||||
let idx = map.xy_idx(x, y);
|
||||
if idx > 0 && idx < map.width as usize * map.height as usize {
|
||||
map.tiles[idx as usize] = TileType::Floor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_vertical_tunnel(map: &mut Map, y1: i32, y2: i32, x: i32) {
|
||||
for y in min(y1, y2)..=max(y1, y2) {
|
||||
let idx = map.xy_idx(x, y);
|
||||
if idx > 0 && idx < map.width as usize * map.height as usize {
|
||||
map.tiles[idx as usize] = TileType::Floor;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user