diff --git a/src/lib/entity.rs b/src/lib/entity.rs index e768176..c8f7ac3 100644 --- a/src/lib/entity.rs +++ b/src/lib/entity.rs @@ -203,20 +203,21 @@ impl Renderable for Food { // no position, does not get rendered yet acts per turn #[derive(Clone)] pub struct FoodGenerator { - counter: u32, + timer: u32, pos: Point, - id: u32 + id: u32, + counter: u32 } impl FoodGenerator { pub fn new() -> FoodGenerator { - FoodGenerator { counter: 0, id: 0, pos: Point(0,0) } + FoodGenerator { timer: 0, id: 0, pos: Point(0,0), counter: 0 } } } impl AI for FoodGenerator { fn step(&mut self, b: &Screen, w: &mut World) -> BoardCommand { - if self.counter % 600 == 0 { + if self.timer % 600 == 0 && self.counter < 10 { // generate random coords, if valid, spawn // if not, try again next step let (min, max) = b.get_dimensions(); @@ -224,10 +225,11 @@ impl AI for FoodGenerator { let mut rng = rand::thread_rng(); let r_x = rng.gen_range(min.0..max.0 + 1); let r_y = rng.gen_range(min.1..max.1 + 1); - + + self.counter += 1; return BoardCommand::SpawnFood(Point(r_x, r_y)); } - self.counter += 1; + self.timer += 1; BoardCommand::Noop } } diff --git a/src/lib/screen.rs b/src/lib/screen.rs index 0ec94d6..ac6c73d 100644 --- a/src/lib/screen.rs +++ b/src/lib/screen.rs @@ -49,7 +49,7 @@ impl Screen { } pub fn get_dimensions(&self) -> (Point, Point) { - (Point(-self.max_x, -self.max_y), Point(self.max_x, self.max_y)) + (Point(0,0), Point(self.max_x, self.max_y)) } }