I am right now creating a snake game in ruby 2d and need a way for the computer to detect when the snake touches the apple.
I have found nothing on this topic as the ruby2d community is fairly small.
I am right now creating a snake game in ruby 2d and need a way for the computer to detect when the snake touches the apple.
I have found nothing on this topic as the ruby2d community is fairly small.
Copyright © 2021 Jogjafile Inc.
You are gonna want to write a function that returns true whenever snake has the same xy-coordinates as the apple.
Let's suppose your apple
ahas member variablesxandy. The snakes headsalso has its current x and y coordinates saved in its member variablesxandy.So in your gameloop always call
hit(a, s)and do what you need to do based on the boolean outcome of the function.