map builder module
This commit is contained in:
parent
6302951694
commit
7e4953f096
5 changed files with 156 additions and 114 deletions
29
src/map_builders/common.rs
Normal file
29
src/map_builders/common.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use super::{Map, Rect, TileType};
|
||||
use std::cmp::{max, min};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue