Skip to content

Commit

Permalink
Menu Songs added and configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Veneiro committed Nov 15, 2023
1 parent 70639dd commit 0e2e4ae
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 32 deletions.
57 changes: 29 additions & 28 deletions help.css
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url("background2.jpg");
background-repeat: no-repeat;
background-size: cover;
color:white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);

font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
background-image: url("background2.jpg");
background-repeat: no-repeat;
background-size: cover;
color: white;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.menu {
text-align: center;
text-align: center;
}

h1 {
font-size: 36px;
margin-bottom: 20px;
font-size: 36px;
margin-bottom: 20px;
}

button {
padding: 10px 20px;
font-size: 18px;
background-color: #3498db;
color: #fff;
border: solid;
cursor: pointer;
border-radius: 1em;
}
padding: 10px 20px;
font-size: 18px;
background-color: #3498db;
color: #fff;
border: solid;
cursor: pointer;
border-radius: 1em;
}

button:hover {
background-color: #2980b9;
background-color: #2980b9;
}

main {
padding: 2em;
background-color: rgba(0,0,0,0.4);
}
padding: 2em;
background-color: rgba(0, 0, 0, 0.4);
}

img {
height: 5em;
width: 5em;
}
7 changes: 7 additions & 0 deletions help.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<body>
<main>
<h1>Ayuda</h1>
<audio id="backgroundMusic" loop autoplay>
<source src="./helpmusic.wav" type="audio/wav">
</audio>
<button id="mute" onclick=music()>
<img src="./mute.jpg" alt="Mute/Unmute">
</button>
<input type="range" id="volumeControl" min="0" max="1" step="0.01" value="1">
<h2>Controles básicos</h2>
<section>
<p>Para poder jugar al juego tendrás que usar las flechas del teclado. Si pulsas la flecha izquierda la pala
Expand Down
53 changes: 53 additions & 0 deletions help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var musicState = localStorage.getItem("musicState");
var mute = document.getElementById("mute");
var muteText = '<img src="./mute.jpg" alt="Mute/Unmute">';
var playingText = '<img src="./volume.jpg" alt="Mute/Unmute">'

var backgroundMusic = document.getElementById("backgroundMusic");
volumeControl.addEventListener('input', function() {
backgroundMusic.volume = volumeControl.value;
});

// Pausar la música
function pauseMusic() {
backgroundMusic.pause();
localStorage.setItem("musicState", "paused");
mute.innerHTML = muteText;
}

// Detener la música
function stopMusic() {
backgroundMusic.pause();
backgroundMusic.currentTime = 0;
localStorage.setItem("musicState", "paused");
mute.innerHTML = "Stopped";
}

// Reproducir la música
function playMusic() {
backgroundMusic.play();
localStorage.setItem("musicState", "playing");
mute.innerHTML = playingText;
}

// Restaura el estado de la música
if (musicState === "playing") {
playMusic();
} else if (musicState === "paused") {
pauseMusic();
}

window.addEventListener('load', function () {
if(musicState === "playing"){
playMusic();
mute.innerHTML = playingText;
}
});

function music(){
if (backgroundMusic.paused) {
playMusic();
} else {
pauseMusic();
}
}
Binary file added helpmusic.wav
Binary file not shown.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<h1>GRAVITY PONG</h1>
<button onclick="startGame()">Iniciar Juego</button>
<button onclick="help()">Ayuda</button>
<button id="mute" onclick=music()></button>
<button id="mute" onclick=music()>
<img src="./mute.jpg" alt="Mute/Unmute">
</button>
<input type="range" id="volumeControl" min="0" max="1" step="0.01" value="1">
</main>
<script src="menu.js"></script>
</body>
Expand Down
5 changes: 5 additions & 0 deletions menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ body {
display:grid;
grid-row-gap:1em;
text-align: center;
}

img{
height: 5em;
width: 5em;
}
10 changes: 7 additions & 3 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ function back() {

var musicState = localStorage.getItem("musicState");
var mute = document.getElementById("mute");
var muteText = "Music Muted";
var playingText = "Playing now..."
var muteText = '<img src="./mute.jpg" alt="Mute/Unmute">';
var playingText = '<img src="./volume.jpg" alt="Mute/Unmute">'

var backgroundMusic = document.getElementById("backgroundMusic");
volumeControl.addEventListener('input', function() {
backgroundMusic.volume = volumeControl.value;
});

// Pausar la música
function pauseMusic() {
Expand All @@ -30,7 +35,6 @@ function stopMusic() {
mute.innerHTML = "Stopped";
}

var backgroundMusic = document.getElementById("backgroundMusic");
// Reproducir la música
function playMusic() {
backgroundMusic.play();
Expand Down
Binary file added mute.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class Pelota {
}

colisionDerecha() {
rebote.play();
let pos = this.body.position;
let posx = pos.x;
let posy = pos.y;
Expand All @@ -292,6 +293,7 @@ class Pelota {
}

colisionIzquierda() {
rebote.play();
let pos = this.body.position;
let posx = pos.x;
let posy = pos.y;
Expand All @@ -308,6 +310,7 @@ class Pelota {
}

colisionArriba() {
rebote.play();
let pos = this.body.position;
let posx = pos.x;
let posy = pos.y;
Expand Down
Binary file added volume.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e2e4ae

Please sign in to comment.