sideways #1
+7
-5
@@ -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();
|
||||
@@ -225,9 +226,10 @@ impl AI for FoodGenerator {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user