From 6b6206370b6a1b4dac8216b9432fa1fbae6e10b8 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Mon, 18 Dec 2023 17:04:48 +0100 Subject: [PATCH] Make enemies randomized --- src/level_generator.rs | 9 ++++++++- src/monster.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/level_generator.rs b/src/level_generator.rs index 7d6d9e2..97d37af 100644 --- a/src/level_generator.rs +++ b/src/level_generator.rs @@ -274,7 +274,14 @@ impl LevelGenerator { let t_x = left + room.offset_x + rng.gen_range(0..room.width); let t_y = top + room.offset_y + rng.gen_range(0..room.height); // TODO randomize enemies here - enemies.push(Box::new(Orc::new_with_position(2, Position::new(self.level, t_x, t_y)))); + match rng.gen_range(1..=100) { + 1..=50 => { + println!("Orc! {} {} {}", self.level, t_x, t_y); + enemies.push(Box::new(Orc::new_with_position(Position::new(self.level, t_x, t_y)))); } + _ => { + println!("Rat! {} {} {}", self.level, t_x, t_y); + enemies.push(Box::new(Rat::new_with_position(Position::new(self.level, t_x, t_y))));} + }; } if room.kind == RoomType::End || room.kind == RoomType::StairDown { diff --git a/src/monster.rs b/src/monster.rs index 6803199..dfa4b8e 100644 --- a/src/monster.rs +++ b/src/monster.rs @@ -48,15 +48,15 @@ impl Rat { life, position: Position::new(0, 0, 0), symbol: String::from("R"), - color: Color::Gray, + color: Color::Black, } } - pub fn new_with_position(life: usize, position: Position) -> Self { + pub fn new_with_position(position: Position) -> Self { Self { - life, + life: 2, position, symbol: String::from("R"), - color: Color::Gray, + color: Color::Black, } } #[cfg(test)] @@ -81,9 +81,9 @@ impl Orc { color: Color::DarkGray, } } - pub fn new_with_position(life: usize, position: Position) -> Self { + pub fn new_with_position(position: Position) -> Self { Self { - life, + life: 4, position, symbol: String::from("O"), color: Color::DarkGray,