Skip to content

Commit e52ca58

Browse files
committed
Soundtrack + fixed lives bug
1 parent 828d4e2 commit e52ca58

9 files changed

+37
-7
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
Binary file not shown.
116 KB
Binary file not shown.

audios/Sonic Jump Sound Effect.mp3

19.3 KB
Binary file not shown.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<script as="script" src="src/prep.js"></script>
1111
<script rel="preload" as="script" src="src/game.js"></script>
1212
<script as="script" src="src/score.js"></script>
13+
<script rel="preload" as="script" src="src/soundtrack.js"></script>
1314
<script rel="preload" as="script" src="src/obstacle.js"></script>
1415
<title>Sonic Runner</title>
1516
</head>

src/game.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ function game() {
33
function jump() {
44
if (sonic.classList != "jump") {
55
sonic.classList.add("jump");
6+
Jump.currentTime = 0.4;
7+
Jump.play();
68

7-
setTimeout(function () {
9+
Jump.addEventListener("ended", function() {
810
sonic.classList.remove("jump");
9-
}, 400);
10-
}
11+
});
12+
}
1113
}
1214
['keydown', 'click'].forEach(function(e) {
1315
document.addEventListener(e, function () {
@@ -51,12 +53,21 @@ function game() {
5153
function lostLife() {
5254
setTimeout(() => {
5355
lives -= 1;
56+
if (lives <= 0) {
57+
lives = 0;
58+
}
5459
canLoseLife = true;
55-
livesDisplay.innerHTML = `Lives: ${lives}`;
60+
livesDisplay.innerHTML = 'Lives: ' + lives;
5661
}, 500);
5762
}
5863

5964
function gameOver() {
65+
GreenHill.loop = false;
66+
GreenHill.currentTime = 257;
67+
68+
GameOver.loop = true;
69+
GameOver.play();
70+
6071
isPaused = true;
6172
alert("Game Over");
6273
location.reload()

src/prep.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ window.addEventListener("DOMContentLoaded", function (event) {
2222
images.push(img);
2323
}
2424
/* 🎶🎶🎶🎶Music🎶🎶🎶🎶 */
25-
var audio = new Audio('sounds/Extras Menu - Sonic Mega Collection [OST].mp3');
26-
audio.loop = true;
27-
audio.play();
25+
Menu.loop = true;
26+
Menu.play();
2827
});
2928

3029
(function() {
@@ -70,6 +69,11 @@ function wait() {
7069
document.addEventListener("keydown", wait, { once: true });
7170

7271
function start() {
72+
Menu.loop = false;
73+
Menu.currentTime = 172;
74+
GreenHill.loop = true;
75+
GreenHill.play();
76+
7377
document.removeEventListener("keydown", wait, { once: true });
7478
const button = document.getElementById("play");
7579
const play = document.getElementById("play-txt");

src/soundtrack.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* Musics */
2+
var Menu = new Audio('audios/Extras Menu - Sonic Mega Collection [OST].mp3');
3+
Menu.volume = 0.4;
4+
5+
var GameOver = new Audio('audios/Sonic Advance 1 2 and 3-Game Over.mp3');
6+
GameOver.volume = 0.4;
7+
8+
var GreenHill = new Audio('audios/Green Hill (Modern) - Sonic Generations [OST].mp3');
9+
GreenHill.volume = 0.3;
10+
11+
var Jump = new Audio('audios/Sonic Jump Sound Effect.mp3');
12+
Jump.volume = 1;

0 commit comments

Comments
 (0)