Page 1 of 1

problem with my code

Posted: Sat Mar 07, 2020 10:01 am
by throwaway507326
Hey there! I'm fairly new to LOVE and lua. To get started I've been following a tutorial on how to create the game 'snake'. I tweaked the code here and there to change the properties of the game more in my liking. Following that tutorial I added a collision detection if the snake is still alive or has died. However after adding the collision detection the snake refuses to move which it did before. Since I'm new to LOVE and lua I coulnd't figure out what's wrong with my code.

What is wrong with my code so that the snake doesn't move? I would be grateful if you could look into the code and tell me what I have to edit in order for the code to work properly :)

Thanks in advance!

(the (German) tutorial I followed along: https://www.youtube.com/playlist?list=P ... YPtfBVTFT8)
the main.lua file containing the code should be attached to this thread

Re: problem with my code

Posted: Sat Mar 07, 2020 9:17 pm
by Xugro
You initialize the snake with one head and four tail elements. All of them in on the same spot. In the first update the head then collides with all four of its tails, triggering the death of the snake with its fourth tail element.

You can initialize the snake with 3 tail elements, initialize the snake in a row (like it was already moving) or start the collision detection in the second update round

Re: problem with my code

Posted: Sun Mar 08, 2020 2:34 pm
by throwaway507326
That makes sense. I think I'll be able to fix that then.

Thanks a lot for the help!