I've been creating the snake game in love and i wasn't able to draw the tail correctly due to not being able to give each tail block the correct x and y.
Basically there is this array of tail blocks that starts at 0 and gains one unit each time the snake eats food, this unit has x and y coordinates.
each update cycle, the snake moves, the tail moves(new x,y for each unit) and the tail gets longer if food is eaten.
I tried several times but my spaghetti code didn't cut it.
I know I should have used a timer variable and a proper grid but i wanted this one to be different.
TLDR: in main.lua exists an updateTail function, where unit.x and unit.y reside.
Thanks for taking the time to read this and a huge hug is waiting for any wonderful person who gives me advice regarding this subject.
[Solved]Snake Game: unable to draw tail correctly
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved]Snake Game: unable to draw tail correctly
- Attachments
-
- the_snakegame.love
- (1.25 KiB) Downloaded 135 times
Last edited by apolius on Sun Oct 27, 2019 7:16 pm, edited 1 time in total.
Re: Snake Game: unable to draw tail correctly
Reverse the order of the tail-update in line 31 from
to
and it will work.
In your version the position of an element will be set on the position of the previous element and all tail-elements will be on the same position after the update.
And if you know that you are writing spaghetti code: Try to write better code / refactor your code. This will help you tremendously
Code: Select all
for i = #tail, 1, -1 do
Code: Select all
for i = 1, #tail do
In your version the position of an element will be set on the position of the previous element and all tail-elements will be on the same position after the update.
And if you know that you are writing spaghetti code: Try to write better code / refactor your code. This will help you tremendously
Re: Snake Game: unable to draw tail correctly
Sometimes, you just need to stop, call your grandma, walk your dog, then come back to have a fresh look, pretty sure this was one of these moments, thanks for the help <3
Who is online
Users browsing this forum: Bing [Bot] and 4 guests