Move apple around

This commit is contained in:
Yash Karandikar 2022-04-30 11:17:34 -05:00
parent 45107b2b3c
commit e39d35d72f
Signed by: karx
GPG key ID: A794DA2529474BA5

View file

@ -73,6 +73,15 @@ fn main() {
}
};
if cat_box::physics::check_for_collision(&snake[0], &apple) {
let x = thread_rng().gen_range(0..=27) * 37;
let y = thread_rng().gen_range(0..=27) * 37;
let (currx, curry) = apple.position();
let (xdiff, ydiff) = (x - currx, curry - y);
apple.translate((xdiff, ydiff));
}
// So that the snake doesn't move at super speed
std::thread::sleep(Duration::from_millis(125));
apple.draw(ctx).unwrap();