Compare commits
No commits in common. "789a41cb3f30409b6f7e1c093ec4efbea049e7dd" and "8ee142586b191cf29be5b64c230ad964db26b107" have entirely different histories.
789a41cb3f
...
8ee142586b
|
@ -310,11 +310,11 @@ impl LevelGenerator {
|
|||
for row in 0..ROOMS_VERTICAL {
|
||||
if let Some(connection) = self.rooms[col][row].connection_down {
|
||||
// println!("down");
|
||||
connection.render(&mut self.rng, &mut structure);
|
||||
connection.render(&mut structure);
|
||||
}
|
||||
if let Some(connection) = self.rooms[col][row].connection_right {
|
||||
// println!("right");
|
||||
connection.render(&mut self.rng,&mut structure);
|
||||
connection.render(&mut structure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,22 +331,20 @@ impl LevelGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_gen() {
|
||||
let mut rng = rand::thread_rng();
|
||||
for _ in 0..1000 {
|
||||
LevelGenerator::generate(0, true, false).render();
|
||||
}
|
||||
}
|
||||
// #[test]
|
||||
// fn test_level_gen() {
|
||||
// for _ in 0..1000 {
|
||||
// LevelGenerator::generate(0, true, false).render();
|
||||
// }
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn test_level_gen_respects_level() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let level = LevelGenerator::generate(0, true, false).render();
|
||||
assert_eq!(0, level.level);
|
||||
let level = LevelGenerator::generate(1, true, false).render();
|
||||
assert_eq!(1, level.level);
|
||||
}
|
||||
// #[test]
|
||||
// fn test_level_gen_respects_level() {
|
||||
// let level = LevelGenerator::generate(0, true, false).render();
|
||||
// assert_eq!(0, level.level);
|
||||
// let level = LevelGenerator::generate(1, true, false).render();
|
||||
// assert_eq!(1, level.level);
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
fn find_room_types(rooms: &Vec<Room>) -> (bool, bool, bool, bool) {
|
||||
|
|
|
@ -56,7 +56,7 @@ create_monster!(
|
|||
name:"spider".to_string(),
|
||||
life: 3,
|
||||
symbol: String::from("s"),
|
||||
color: Color::Yellow,
|
||||
color: Color::Blue,
|
||||
experience_gain: 7,
|
||||
ticks_between_steps: 7,
|
||||
damage_range: 2..=3,
|
||||
|
|
49
src/room.rs
49
src/room.rs
|
@ -1,4 +1,4 @@
|
|||
use std::{cmp::{max, min}, ops::RangeInclusive};
|
||||
use std::cmp::{max, min};
|
||||
|
||||
use crate::{
|
||||
constants::{LEVEL_HEIGHT, LEVEL_WIDTH, ROOM_HEIGHT, ROOM_WIDTH},
|
||||
|
@ -26,14 +26,7 @@ pub struct Connection {
|
|||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn render(&self, rng: &mut ThreadRng, tgt: &mut [[StructureElement; LEVEL_HEIGHT]; LEVEL_WIDTH]) {
|
||||
fn calc_range(a: usize, b:usize) -> RangeInclusive<usize>{
|
||||
if a > b {
|
||||
b..=a
|
||||
} else {
|
||||
a..=b
|
||||
}
|
||||
}
|
||||
pub fn render(&self, tgt: &mut [[StructureElement; LEVEL_HEIGHT]; LEVEL_WIDTH]) {
|
||||
// the tuples are (col, row)
|
||||
let abs_d_col =
|
||||
max(self.start_pos.0, self.end_pos.0) - min(self.start_pos.0, self.end_pos.0);
|
||||
|
@ -42,11 +35,22 @@ impl Connection {
|
|||
max(self.start_pos.1, self.end_pos.1) - min(self.start_pos.1, self.end_pos.1);
|
||||
|
||||
if abs_d_col == 0 {
|
||||
for row in calc_range(self.end_pos.1, self.start_pos.1 ) {
|
||||
let range = if self.end_pos.1 > self.start_pos.1 {
|
||||
self.start_pos.1..=self.end_pos.1
|
||||
} else {
|
||||
self.end_pos.1..=self.start_pos.1
|
||||
};
|
||||
|
||||
for row in range {
|
||||
tgt[self.end_pos.0][row] = StructureElement::Floor;
|
||||
}
|
||||
} else if abs_d_row == 0 {
|
||||
for col in calc_range(self.end_pos.0, self.start_pos.0) {
|
||||
let range = if self.end_pos.0 > self.start_pos.0 {
|
||||
self.start_pos.0..=self.end_pos.0
|
||||
} else {
|
||||
self.end_pos.0..=self.start_pos.0
|
||||
};
|
||||
for col in range {
|
||||
tgt[col][self.end_pos.1] = StructureElement::Floor;
|
||||
}
|
||||
} else {
|
||||
|
@ -54,16 +58,18 @@ impl Connection {
|
|||
if d_row > 0 {
|
||||
// more up/down
|
||||
let d_row = self.end_pos.1 - self.start_pos.1;
|
||||
let vert_offset = if d_row > 3 {
|
||||
rng.gen_range(1..=d_row-1)
|
||||
} else {d_row/2};
|
||||
for r in self.start_pos.1..=(self.start_pos.1 + vert_offset) {
|
||||
for r in self.start_pos.1..=(self.start_pos.1 + d_row / 2) {
|
||||
tgt[self.start_pos.0][r] = StructureElement::Floor;
|
||||
}
|
||||
for c in calc_range(self.end_pos.0, self.start_pos.0) {
|
||||
tgt[c][self.start_pos.1 + vert_offset] = StructureElement::Floor;
|
||||
let range = if self.end_pos.0 > self.start_pos.0 {
|
||||
self.start_pos.0..=self.end_pos.0
|
||||
} else {
|
||||
self.end_pos.0..=self.start_pos.0
|
||||
};
|
||||
for c in range {
|
||||
tgt[c][self.start_pos.1 + d_row / 2] = StructureElement::Floor;
|
||||
}
|
||||
for r in (self.start_pos.1 + vert_offset)..=self.end_pos.1 {
|
||||
for r in (self.start_pos.1 + d_row / 2)..=self.end_pos.1 {
|
||||
tgt[self.end_pos.0][r] = StructureElement::Floor;
|
||||
}
|
||||
} else {
|
||||
|
@ -72,7 +78,12 @@ impl Connection {
|
|||
for tgt_col in tgt.iter_mut().skip(self.start_pos.0).take(d_col / 2 + 1) {
|
||||
tgt_col[self.start_pos.1] = StructureElement::Floor;
|
||||
}
|
||||
for r in calc_range(self.end_pos.1, self.start_pos.1) {
|
||||
let range = if self.end_pos.1 > self.start_pos.1 {
|
||||
self.start_pos.1..=self.end_pos.1
|
||||
} else {
|
||||
self.end_pos.1..=self.start_pos.1
|
||||
};
|
||||
for r in range {
|
||||
tgt[self.start_pos.0 + d_col / 2][r] = StructureElement::Floor;
|
||||
}
|
||||
for tgt_col in tgt
|
||||
|
|
Loading…
Reference in New Issue