Skip to content

Commit

Permalink
sounds added
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Jan 9, 2019
1 parent 3d3a427 commit 8bb6110
Show file tree
Hide file tree
Showing 432 changed files with 61,121 additions and 204 deletions.
23 changes: 20 additions & 3 deletions classic_snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ const box = 20;
const w = 1000;
const h = 500;

// sounds
let dead = new Audio();
let eat = new Audio();

dead.src = '/sounds/dead.mp3';
eat.src = '/sounds/eat.mp3';

let snake = [];

// intialize snake
Expand Down Expand Up @@ -37,16 +44,19 @@ function findDirection(event) {

if (key == 37 && direction != "RIGHT") {
direction = "LEFT";
delay();
} else if (key == 38 && direction != "DOWN") {
direction = "UP";

delay();
} else if (key == 39 && direction != "LEFT") {
direction = "RIGHT";

delay();
} else if (key == 40 && direction != "UP") {
direction = "DOWN";
delay();
} else if (key == 80) {
togglePause();
delay();
}
}

Expand Down Expand Up @@ -101,6 +111,7 @@ function draw() {
// if the snake eats the food
if (snakeX == food.x && snakeY == food.y) {
score++;
eat.play();
food = {
x: Math.floor(Math.random() * (w / box)) * box,
y: Math.floor(Math.random() * (h / box)) * box
Expand All @@ -121,7 +132,7 @@ function draw() {
}

//adding new head for snake

delay();
let newHead = {
x: snakeX,
y: snakeY
Expand All @@ -130,6 +141,7 @@ function draw() {
// checking game over condition

if (snakeX < 0 || snakeX == w || snakeY < 0 || snakeY == h || collision(newHead, snake)) {
dead.play();
clearInterval(game);
alert(` Oops: Game Over \n Your Score: ${score}`);
name = prompt('Enter Your Name ');
Expand Down Expand Up @@ -166,4 +178,9 @@ let name;

function displayScore() {
document.getElementById('score').innerHTML = score;
}

function delay(){
for(let i = 0;i<200;i++)
for(let j = 0;j<1000;j++);
}
7,039 changes: 7,039 additions & 0 deletions node_modules/ajv/dist/ajv.bundle.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions node_modules/ajv/dist/ajv.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node_modules/ajv/dist/ajv.min.js.map

Large diffs are not rendered by default.

Binary file added node_modules/ajv/lib/.DS_Store
Binary file not shown.
Loading

0 comments on commit 8bb6110

Please sign in to comment.