RylofScripts

snake js reset

Sep 18th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.getElementById("resetButton").addEventListener("click", resetGame);
  2.  
  3. // Add this reset function
  4. function resetGame() {
  5.   snake = [];
  6.   snake[0] = { x: 10 * box, y: 10 * box };
  7.   food = {
  8.     x: Math.floor(Math.random() * 20) * box,
  9.     y: Math.floor(Math.random() * 20) * box
  10.   };
  11.   d = null;
  12.   score = 0;
  13.   clearInterval(game);
  14.   game = setInterval(draw, 100);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment