Snake moves slightly out of the map on certain coordinates

Viewed 22

In line 84-87, i set an if statement that the game should restart if snake position is out of the gridsize/map but somehow the snake is able to move slightly out of the canvas on some coordinates.

This is the code for being out of map:

  if (pos.x < 0 || pos.x > T || pos.y < 0 || pos.y > T) {
    init();
  }

}

JS Fiddle: https://jsfiddle.net/anon9420/5y86vdhw/49/

0 Answers
Related