Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const background = new Image();
const background1 = new Image();
const background2 = new Image();
const foodImg = new Image();
const dead = new Audio();
const eat = new Audio();
Expand All @@ -18,6 +20,8 @@ let d;
let highestScore = localStorage.getItem('highestScore') ? localStorage.getItem('highestScore') : 0 ;
foodImg.src = "images/food.png";
background.src = "images/ground.png";
background1.src = "images/groundblue.png";
background2.src = "images/groundcherry.png";
dead.src = "audio/dead.mp3";
eat.src = "audio/eat.mp3";
up.src = "audio/up.mp3";
Expand Down Expand Up @@ -60,7 +64,14 @@ function collision(head, array) {
return false;
}
function draw() {
ctx.drawImage(background, 0, 0);
ctx.drawImage(background, 0, 0);
if (score >= 10) {
ctx.drawImage(background1, 0, 0);
}
if (score >= 15) {
ctx.drawImage(background2, 0, 0);
}


for (let i = 0; i < snake.length; i++) {
ctx.fillStyle = i == 0 ? "green" : "white";
Expand Down Expand Up @@ -118,7 +129,7 @@ function draw() {
}

snake.unshift(newHead);
ctx.fillStyle = "black";
ctx.fillStyle = "white";
ctx.font = "40px Change one";
ctx.fillText(score, 2 * box, 1.6 * box);
ctx.fillText('Highest Score: '+ highestScore,6 * box,1.6 * box)
Expand Down Expand Up @@ -521,5 +532,4 @@ confetti.start()
window.addEventListener('resize', function(event){
confetti.resize();
});
}

}
Binary file added images/groundblue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/groundcherry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
<title>Snake Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<canvas id="confetti"></canvas>
<canvas id="gamescreen" width="608" height="608"></canvas>
<script src="game.js"></script>

<body>
<h1>Snake Game</h1>
<h2>Controls:</h2>
<p>Use the arrow keys to move your snake.<br>Best of Luck</p>
<canvas id="confetti"></canvas>
<canvas id="gamescreen" width="608" height="608"></canvas>
<script src="game.js"></script>
</body>
</html>
37 changes: 29 additions & 8 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
canvas {
display: block;
margin-left: auto;
margin-right: auto;
display: block;
margin-left: auto;
margin-right: auto;
}

#confetti{
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
}

body {
background-color: darkslategray;
color: antiquewhite;
text-align: center;
}

h1 {
font-size: 50px;
}

h2 {
font-size: 30px;
margin-top: -20px;
}

p {
font-size: 20px;
margin-top: -20px;
}