| 211 | self.snake.set_direction(direction); |
| 212 | } |
| 213 | pub fn draw<D>(&mut self, target: &mut D) -> () |
| 214 | where |
| 215 | D: DrawTarget<Color = T>, |
| 216 | { |
| 217 | self.snake.make_step(); |
| 218 | let hit = self.snake.contains(self.food.get_pixel().0); |
| 219 | if hit { |
| 220 | self.snake.grow(); |
| 221 | } |
| 222 | self.food_age += 1; |
| 223 | if self.food_age >= self.food_lifetime || hit { |
| 224 | self.food.replace(&self.snake); |
| 225 | self.food_age = 0; |
| 226 | } |
| 227 | |
| 228 | let mut scaled_display = ScaledDisplay::<D> { |
| 229 | real_display: target, |
| 230 | size_x: self.size_x / self.scale_x, |
| 231 | size_y: self.size_y / self.scale_y, |
| 232 | scale_x: self.scale_x, |
| 233 | scale_y: self.scale_y, |
| 234 | }; |
| 235 | |
| 236 | for part in self.snake.into_iter() { |
| 237 | _ = part.draw(&mut scaled_display); |
| 238 | } |
| 239 | _ = self.food.get_pixel().draw(&mut scaled_display); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /// A dummy DrawTarget implementation that can magnify each pixel so the user code does not need to adapt for scaling things |