Make enemies randomized
This commit is contained in:
parent
73315a7636
commit
6b6206370b
|
@ -274,7 +274,14 @@ impl LevelGenerator {
|
||||||
let t_x = left + room.offset_x + rng.gen_range(0..room.width);
|
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);
|
let t_y = top + room.offset_y + rng.gen_range(0..room.height);
|
||||||
// TODO randomize enemies here
|
// 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 {
|
if room.kind == RoomType::End || room.kind == RoomType::StairDown {
|
||||||
|
|
|
@ -48,15 +48,15 @@ impl Rat {
|
||||||
life,
|
life,
|
||||||
position: Position::new(0, 0, 0),
|
position: Position::new(0, 0, 0),
|
||||||
symbol: String::from("R"),
|
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 {
|
Self {
|
||||||
life,
|
life: 2,
|
||||||
position,
|
position,
|
||||||
symbol: String::from("R"),
|
symbol: String::from("R"),
|
||||||
color: Color::Gray,
|
color: Color::Black,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -81,9 +81,9 @@ impl Orc {
|
||||||
color: Color::DarkGray,
|
color: Color::DarkGray,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_with_position(life: usize, position: Position) -> Self {
|
pub fn new_with_position(position: Position) -> Self {
|
||||||
Self {
|
Self {
|
||||||
life,
|
life: 4,
|
||||||
position,
|
position,
|
||||||
symbol: String::from("O"),
|
symbol: String::from("O"),
|
||||||
color: Color::DarkGray,
|
color: Color::DarkGray,
|
||||||
|
|
Loading…
Reference in New Issue