Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#218 Enhancing User Experience with Subtle Background Music #227

Merged
merged 1 commit into from
Jun 2, 2024
Merged
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
Binary file not shown.
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<title>Rubik Cube</title>
<link rel="icon" type="image/x-icon" href="images\icon.png">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><link rel="stylesheet" href="./style.css">
<!--For volume icon-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">


</head>
<body>
Expand Down Expand Up @@ -107,8 +110,14 @@ <h1 class="text text--title">
<button class="btn btn--br btn--reset">
<icon reset></icon>
</button>
<button class="btn btn--tr fa-solid fa-volume-high" id="play-btn">
</div>

<!-- Audio element for background music -->
<audio id="background-music" autoplay loop >
<source src="Music/8 Bit Space Groove! Chill Pretty Chiptune Game Music by HeatleyBros.mp3" type="audio/mpeg">
</audio>

</div>
<!-- partial -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/95/three.min.js'></script><script src="./script.js"></script>
Expand Down
16 changes: 16 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3706,6 +3706,7 @@ class Game {

constructor() {

this.audio = document.getElementById('background-music');
this.dom = {
ui: document.querySelector( '.ui' ),
game: document.querySelector( '.ui__game' ),
Expand Down Expand Up @@ -4080,6 +4081,21 @@ class Game {
}

}
// Volume button functionality
const musicButton = document.getElementById('play-btn');
const music = document.getElementById('background-music');

musicButton.addEventListener('click', () => {
if (music.paused) {
music.play();
musicButton.classList.remove('fa-volume-xmark');
musicButton.classList.add('fa-volume-high');
} else {
music.pause();
musicButton.classList.remove('fa-volume-high');
musicButton.classList.add('fa-volume-xmark');
}
});

window.version = '0.99.2';
window.game = new Game();
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ body {
bottom: 0.8em;
left: calc(50% - 0.5em);
}
/* For volume button */
.btn--tr {
top: 1.2em;
right: 1.2em;
opacity: 1;
pointer-events: auto;
}
.btn svg {
display: block;
}
Expand Down