Skip to content

Commit

Permalink
added reset functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cambrian34 committed Oct 20, 2023
1 parent 3a313b0 commit 791f309
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 10 additions & 4 deletions snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ function createRect(x,y,width, height,color){
window.addEventListener("keydown", (event)=>{
setTimeout(()=>{
if(event.keyCode == 37 && snake.rotateX != 1){
snake.rotateX = -1
snake.rotateX = -1;
snake.rotateY = 0;
} else if(event.keyCode == 38 && snake.rotateY != 1){
snake.rotateX = 0
snake.rotateX = 0;
snake.rotateY = -1;
}else if(event.keyCode == 39 && snake.rotateX != -1){
snake.rotateX = 1
snake.rotateX = 1;
snake.rotateY = 0;
}
else if(event.keyCode == 40 && snake.rotateY != -1){
snake.rotateX = 0
snake.rotateX = 0;
snake.rotateY = 1;
}
}, 1)
Expand All @@ -171,5 +171,11 @@ window.addEventListener("keydown", (event)=>{
}

}
//resets the game on spacebar
if (event.key == " " || event.key == "Spacebar"){
snake = new Snake(20,20,20);
apple = new Apple();
}


})

0 comments on commit 791f309

Please sign in to comment.