I will try to explain what I need as best as I can.
I am creating a snake game with a gui, and I need the fruit to randomly spawn. I can get it to spawn on any random coordinate within the game. But that's no good, since the snake only travels on coordinates that are multiples of 10. This is because when you click any arrow key, it continuously adds 10 to to the previous coordinate. Basically, I need to have the fruit not only randomly spawn withing the boundaries, but also within coordinates that are a multiple of 10 so that the snake can actually collide with it no matter where it is on the map.
Size of map:
- Width of map = 800
- height of map = 500
I tried using a for loop like this (for the x coordinate):
for(int x = 0; x <= 800; x += 10)
and this for the y coord:
for(int y = 0; y <= 500; y += 10)
But I couldn't get anything to work. Once again, I need to generate a random x coordinate between 0 and 800 (0, 10, 20, 30, etc.) and a random y coordinate between 0 and 500 (0, 10, 20, etc.). If you understand what I'm getting at, because I'm not sure how well I've explained, please help out.
Thanks!
Aucun commentaire:
Enregistrer un commentaire