0

Can SOmeone Explain THis Code

ctx.fillStyle="lime"; for(var i=0;i<trail.length;i++) { ctx.fillRect(trail[i].x*gs,trail[i].y*gs,gs-2,gs-2); if(trail[i].x==px && trail[i].y==py) { tail = 5; } } trail.push({x:px,y:py}); while(trail.length>tail) { trail.shift(); } if(ax==px && ay==py) { tail++; ax=Math.floor(Math.random()*tc); ay=Math.floor(Math.random()*tc); } ctx.fillStyle="red"; ctx.fillRect(ax*gs,ay*gs,gs-2,gs-2); } this is part of the code of snake i looked at it over and over and i still dont get it. When did they define tail as part of the snake. I dont understand it. Since they didnt define the variabel tail as part of the snake why does it make the snake grow? Since trail is the array wouldn't that make it grow bigger instead of the variable tail

11th Mar 2018, 10:49 PM
Someone Else
Someone Else - avatar
2 Answers
+ 4
send full code so we can try to xplain it
12th Mar 2018, 5:22 AM
2+2=4
2+2=4 - avatar
+ 1
I understand it now. I’m ok now
12th Mar 2018, 4:58 PM
Someone Else
Someone Else - avatar