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();
+ }
}
_ => {}
}
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;