The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Snake game ( separate snake body ) Reply To: Snake game ( separate snake body )


Now I have two arrays: one is snakeBody(contains divs that will be body of the snake), second array contains arrays with coordinats of first element from snakeBody(snakeBody[0]) after he start moving in such form pastCoord = [[20,0], [40, 0], [60, 0]……] (here [coordX, coordY]). Every step is 20px.

I don’t know how to apply coords from pastCoord array to elements in snakeBody array.

I think about double for loop, but what to do in this loops I don’t know:

for (var i = this.snakeBody.length - 1; i >= 0; i--) {
         for (var j = gameObj.pastCoord.length - 1; j >= 0; j--) {