From: Tomas Wenström Date: Sat, 30 Jan 2021 16:41:51 +0000 (+0100) Subject: Bugfix X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=9768e2bbbcdfa38e84d593215c098ba96db754da;p=kaka%2Frust-sdl-test.git Bugfix --- diff --git a/src/core/game.rs b/src/core/game.rs index eabbdf9..3dacac1 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -70,9 +70,11 @@ impl AppState for GameState { self.world.level = self.lvlgen.generate(); } Event::KeyDown { keycode: Some(Keycode::KpMinus), .. } => { - self.lvlgen.iterations = 1.max(self.lvlgen.iterations - 1); - println!("{} iteration(s) of cellular automata", self.lvlgen.iterations); - self.world.level = self.lvlgen.generate(); + if self.lvlgen.iterations > 0 { + self.lvlgen.iterations -= 1; + println!("{} iteration(s) of cellular automata", self.lvlgen.iterations); + self.world.level = self.lvlgen.generate(); + } } _ => {} } diff --git a/src/core/level/lvlgen.rs b/src/core/level/lvlgen.rs index e39f232..a549166 100644 --- a/src/core/level/lvlgen.rs +++ b/src/core/level/lvlgen.rs @@ -264,13 +264,13 @@ impl Region { let mut outline = vec!(); let mut directions = vec!((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)); // 8 directions rotating right from starting direction right - let mut p = self.find_first_point_of_outline(&rect, &grid); + let start = self.find_first_point_of_outline(&rect, &grid); + let mut p = start; marked[p.x as usize][p.y as usize] = true; loop { outline.push((p + (ox as isize, oy as isize)) * scale as isize); self.find_next_point_of_outline(&grid, &mut p, &mut directions); - if marked[p.x as usize][p.y as usize] { - // we're back at the beginning + if p == start { break; } marked[p.x as usize][p.y as usize] = true;