Now with resize

This commit is contained in:
2022-01-25 14:41:24 +01:00
parent d52638c282
commit 95be479636
4 changed files with 147 additions and 44 deletions

79
src/map.rs Normal file
View File

@@ -0,0 +1,79 @@
use rltk::{Rltk, RGB};
#[derive(PartialEq, Copy, Clone)]
pub enum TileType {
Wall,
Floor,
}
pub fn xy_idx(x: i32, y: i32) -> usize {
(y as usize * 80) + x as usize
}
pub fn new_map_rooms_and_corridors() -> Vec<TileType> {
let mut map = vec![TileType::Wall; 80 * 50];
map
}
/// Makes a map with solid boundaries and 400 randomly placed walls. No guarantees that it won't look awful
pub fn new_map_test() -> Vec<TileType> {
let mut map = vec![TileType::Floor; 80 * 50];
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;
}
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
}
pub fn draw_map(map: &[TileType], ctx: &mut Rltk) {
let mut y = 0;
let mut x = 0;
for tile in map.iter() {
match tile {
TileType::Floor => {
ctx.set(
x,
y,
RGB::from_f32(0.5, 0.5, 0.5),
RGB::from_f32(0., 0., 0.),
rltk::to_cp437('.'),
);
}
TileType::Wall => {
ctx.set(
x,
y,
RGB::from_f32(0.0, 1.0, 0.0),
RGB::from_f32(0., 0., 0.),
rltk::to_cp437('#'),
);
}
}
x += 1;
if x > 79 {
x = 0;
y += 1;
}
}
}