problem with my code

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
throwaway507326
Prole
Posts: 2
Joined: Sat Mar 07, 2020 9:36 am

problem with my code

Post 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
Attachments
main.lua
the snake program
(2.54 KiB) Downloaded 174 times
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: problem with my code

Post 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
throwaway507326
Prole
Posts: 2
Joined: Sat Mar 07, 2020 9:36 am

Re: problem with my code

Post by throwaway507326 »

That makes sense. I think I'll be able to fix that then.

Thanks a lot for the help!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], rabbitboots and 223 guests