From e39d35d72f9b26ecb0bb82d145bd3d01376e5c21 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Sat, 30 Apr 2022 11:17:34 -0500 Subject: [PATCH] Move apple around --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 50ef1bd..96e09f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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();