|
|
@ -203,20 +203,21 @@ impl Renderable for Food { |
|
|
|
// no position, does not get rendered yet acts per turn
|
|
|
|
// no position, does not get rendered yet acts per turn
|
|
|
|
#[derive(Clone)] |
|
|
|
#[derive(Clone)] |
|
|
|
pub struct FoodGenerator { |
|
|
|
pub struct FoodGenerator { |
|
|
|
counter: u32, |
|
|
|
timer: u32, |
|
|
|
pos: Point, |
|
|
|
pos: Point, |
|
|
|
id: u32 |
|
|
|
id: u32, |
|
|
|
|
|
|
|
counter: u32 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl FoodGenerator { |
|
|
|
impl FoodGenerator { |
|
|
|
pub fn new() -> 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 { |
|
|
|
impl AI for FoodGenerator { |
|
|
|
fn step(&mut self, b: &Screen, w: &mut World) -> BoardCommand { |
|
|
|
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
|
|
|
|
// generate random coords, if valid, spawn
|
|
|
|
// if not, try again next step
|
|
|
|
// if not, try again next step
|
|
|
|
let (min, max) = b.get_dimensions(); |
|
|
|
let (min, max) = b.get_dimensions(); |
|
|
@ -225,9 +226,10 @@ impl AI for FoodGenerator { |
|
|
|
let r_x = rng.gen_range(min.0..max.0 + 1); |
|
|
|
let r_x = rng.gen_range(min.0..max.0 + 1); |
|
|
|
let r_y = rng.gen_range(min.1..max.1 + 1); |
|
|
|
let r_y = rng.gen_range(min.1..max.1 + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.counter += 1; |
|
|
|
return BoardCommand::SpawnFood(Point(r_x, r_y)); |
|
|
|
return BoardCommand::SpawnFood(Point(r_x, r_y)); |
|
|
|
} |
|
|
|
} |
|
|
|
self.counter += 1; |
|
|
|
self.timer += 1; |
|
|
|
BoardCommand::Noop |
|
|
|
BoardCommand::Noop |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|