Skip to content

Commit

Permalink
iiitl#2 Dynamic Speed Increment in Snake Game
Browse files Browse the repository at this point in the history
In this Snake game implementation, a dynamic speed increment feature has been introduced to enhance gameplay dynamics. When the snake consumes food, its speed increases by a fixed increment of 0.1 units, adding an element of challenge and excitement to the gameplay experience.
  • Loading branch information
NotVishesh authored Mar 15, 2024
1 parent 4dc72d0 commit 638d298
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function isCollide(snake) {
//if you into yourself

if (snake[0].x > 18 || snake[0].x < 0 || snake[0].y > 18 || snake[0].y < 0) {
speed = 5; // to reset the speed back to 5 when it collides
return true;
}
}
Expand All @@ -52,6 +53,8 @@ function gameEngine() {
if (snakeArr[0].y === food.y && snakeArr[0].x === food.x) {
// console.log("food")
foodSound.play();
speed +=0.1; // increase the speed by 0.1 every time it eates the food
// console.log(speed);

snakeArr.unshift({ x: snakeArr[0].x + inputDir.x, y: snakeArr[0].y + inputDir.y });
// console.log(snakeArr)
Expand Down

0 comments on commit 638d298

Please sign in to comment.