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 a has member variables x and y. The snakes head s also has its current x and y coordinates saved in its member variables x and y.
def hit(a, s)
return a.x == s.x && a.y == s.y
end
So in your gameloop always call hit(a, s) and do what you need to do based on the boolean outcome of the function.
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.