dimanche 21 mars 2021

How can one add the food in a snake game (pygame) more elegantly?

I saw quite a few ways to do it, but I don't understand why they calculate /10*10 in the end. This is how the food is handled, it doesn't work without the last part(/10.0)*10.0) but I don't understand what it is there for. Can someone please explain this?

foodx = round(random.randrange(0, window_width - snake_block)/10.0)*10.0
foody = round(random.randrange(0, window_width - snake_block)/10.0)*10.0



Aucun commentaire:

Enregistrer un commentaire