start generating

This commit is contained in:
Joachim Lusiardi 2023-11-12 15:48:03 +01:00
parent 3830f26e92
commit ddf206343c
2 changed files with 18 additions and 14 deletions

View File

@ -15,26 +15,28 @@ pub struct Level {
}
impl Level {
const ROOM_HEIGHT: usize = 6;
const ROOM_WIDTH: usize = 7;
fn draw_room(row: usize, col: usize, s: &mut [[LevelElement; LEVEL_HEIGHT]; LEVEL_WIDTH]) {
for r in 0..Level::ROOM_HEIGHT {
for c in 0..Level::ROOM_WIDTH {
if c == Level::ROOM_WIDTH - 1 || r == Level::ROOM_HEIGHT - 1 {
s[col * Level::ROOM_WIDTH + c][row * Level::ROOM_HEIGHT + r] = LevelElement::Wall;
}
}
}
}
pub fn new() -> Level {
let mut s = [[LevelElement::Floor; LEVEL_HEIGHT]; LEVEL_WIDTH];
Level::draw_room(0, 0, &mut s);
Level::draw_room(1, 1, &mut s);
for i in 0..LEVEL_WIDTH {
s[i][0] = LevelElement::Wall;
s[i][LEVEL_HEIGHT-1] = LevelElement::Wall;
}
for i in 0..LEVEL_HEIGHT {
s[0][i] = LevelElement::Wall;
s[LEVEL_WIDTH-1][i] = LevelElement::Wall;
}
s[10][10] = LevelElement::Wall;
s[11][10] = LevelElement::Wall;
s[10][11] = LevelElement::Wall;
s[11][11] = LevelElement::Wall;
s[1][20] = LevelElement::Wall;
s[20][1] = LevelElement::Wall;
s[20][LEVEL_HEIGHT-2] = LevelElement::Wall;
s[LEVEL_WIDTH-2][20] = LevelElement::Wall;
s[4][4] = LevelElement::StairDown;
s[45][20] = LevelElement::StairUp;
Level {
structure: s
}

View File

@ -62,11 +62,13 @@ fn main() -> Result<()> {
height: 25,
};
frame.render_widget(
Paragraph::new(format!("{}\nHealth: {}/{}\n{}",
Paragraph::new(format!("{}\nHealth: {}/{}\n{}/{}/{}",
g.player.get_name(),
g.player.get_life(),
g.player.get_max_life(),
g.player.get_position().get_x()))
g.player.get_position().get_level(),
g.player.get_position().get_x(),
g.player.get_position().get_y()))
.white()
.on_blue(),
stats_area,