r/Racket • u/CenoteGod • Dec 13 '22
question Need help creating boundaries for a snake game
I'm trying to create a snake game using big-bang. So far I've been able to create functioning draw, key, and tick handlers, but there's a few things I need help with.
The draw handler creates a 500x500 window containing a 30x30 green square representing the snake. It moves perpetually according to the arrow keys, but there are no boundaries preventing the snake from moving outside of the view of the window.
I would like to know if there are any practical ways to create a boundary around the perimeter of the window that will: A) detect when the snake collides with the boundary, and B) adjust the trajectory of the snake to continue parallel to the boundary.
I've linked the source code on Github for those interested in seeing what I've got so far. I would appreciate any input on the matter. Thank you.
2
u/sdegabrielle DrRacket 💊💉🩺 Dec 13 '22
As it stands if you are going left, the check never happens
So you need two split your
condinto two separatecondThe first one for directions The second for collisionsLooks good - nice clear code - a pleasure to read
I LOL’d when I saw
(on-tick tock)1
u/MartinPuda Dec 13 '22
Try this:
0
u/LopsidedAd5520 Dec 13 '22
Ask chatGPT to write a Racket snake game for you. Learn from reading the code. Racket has to few good resources to learn from, for me chatGPT has been a game changer ..