Skip to content

Commit

Permalink
Merge pull request #18 from Parallaxes/main
Browse files Browse the repository at this point in the history
Hotfix Completed && Audio Capability Added
  • Loading branch information
Parallaxes authored Dec 6, 2024
2 parents 06f3670 + d7f23b9 commit bce7258
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
Binary file added assets/audio/everlong.mp3
Binary file not shown.
4 changes: 4 additions & 0 deletions assets/js/platformer/BackgroundSnow.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Background from './Background.js';
import GameEnv from './GameEnv.js';

export class BackgroundSnow extends Background {
constructor(canvas, image, data) {
super(canvas, image, data);

// Start the background music in loop
GameEnv.loopSound('everlong');

this.parallaxSpeed = 0.3; // Speed for vertical parallax scrolling
}

Expand Down
3 changes: 3 additions & 0 deletions assets/js/platformer/GameControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ const GameControl = {
// Destroy existing game objects
GameEnv.destroy();

// Stop background music
GameEnv.stopAllSounds();

// Load GameLevel objects
if (GameEnv.currentLevel !== newLevel) {
GameEnv.claimedCoinIds = [];
Expand Down
16 changes: 16 additions & 0 deletions assets/js/platformer/GameEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ export class GameEnv {
sound.play();
}

// Play a sound by its ID in a loop
static loopSound(id) {
const sound = document.getElementById(id);
sound.loop = true;
sound.play();
}

// Stop all sounds
static stopAllSounds() {
const sounds = document.getElementsByTagName('audio');
for (let sound of sounds) {
sound.pause();
sound.currentTime = 0;
}
}

static updateParallaxDirection(key) {
switch (key) {
case "a":
Expand Down
5 changes: 5 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ image: /images/platformer/backgrounds/home.png
<!--Audio for coin collection -->
<audio id ="coin" src="{{site.baseurl}}/assets/audio/coin.mp3" preload="auto"></audio>

<!--Audio for music -->

<!--Audio for Everlong by Foo Fighters (Winter) -->
<audio id="everlong" src="{{site.baseurl}}/assets/audio/everlong.mp3" preload="auto"></audio>

<!--Audio for when it hits top of platform -->
<audio id ="stomp" src="{{site.baseurl}}/assets/audio/stomp2-93279.mp3" preload="auto"></audio>

Expand Down

0 comments on commit bce7258

Please sign in to comment.