Skip to content

Commit

Permalink
adding high score popup with sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Riyachauhan11 committed Nov 7, 2024
1 parent 0d426f9 commit 81607b0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 28 deletions.
107 changes: 82 additions & 25 deletions Alien.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ body {
body.dark-theme {
background-color: var(--background-dark);
color: var(--text-light);
background-image: radial-gradient(circle at 50% 50%,
background-image: radial-gradient(
circle at 50% 50%,
rgba(0, 255, 136, 0.1) 0%,
transparent 50%),
transparent 50%
),
linear-gradient(to bottom, #0a0b1a 0%, #1a1b3a 100%);
}

.image{
.image {
/* padding-right: 50px; */
}

Expand Down Expand Up @@ -105,14 +107,12 @@ body.dark-theme {
/* Rounded corners for hover effect */
transition: background-color 0.3s ease;
/* Smooth hover transition */

}

.home {
padding-left: 90px;
}


/* Other styles remain unchanged */

/* Game Container */
Expand Down Expand Up @@ -140,10 +140,7 @@ body.dark-theme {
left: 15%;
transform: translate(-50%, -50%);
text-align: center;
background-color: rgba(0,
0,
0,
0.7);
background-color: rgba(0, 0, 0, 0.7);
/* Optional: semi-transparent background */
color: white;
/* Text color */
Expand All @@ -162,10 +159,7 @@ body.dark-theme {
left: 35%;
transform: translate(-50%, -50%);
text-align: center;
background-color: rgba(242,
255,
0,
0.7);
background-color: rgba(242, 255, 0, 0.7);
/* Optional: semi-transparent background */
color: white;
/* Text color */
Expand Down Expand Up @@ -221,7 +215,6 @@ body.dark-theme #gameControls {
gap: 10px;
margin: 20px 0;
padding-left: 20px;

}

.theme-switch {
Expand Down Expand Up @@ -261,11 +254,11 @@ body.dark-theme #gameControls {
border-radius: 50%;
}

input:checked+.slider {
input:checked + .slider {
background-color: var(--primary-color-dark);
}

input:checked+.slider:before {
input:checked + .slider:before {
transform: translateX(26px);
}

Expand All @@ -277,10 +270,7 @@ input:checked+.slider:before {
left: 38%;
transform: translate(-50%, -50%);
text-align: center;
background-color: rgba(0,
0,
0,
0.7);
background-color: rgba(0, 0, 0, 0.7);
/* Optional: semi-transparent background */
color: white;
/* Text color */
Expand All @@ -290,6 +280,76 @@ input:checked+.slider:before {
z-index: 1000;
/* Ensure it appears above other content */
}
/* High Score Beaten Popup Styling */
#congratsPopup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.8);
color: var(--text-light);
padding: 20px;
border-radius: 10px;
display: none; /* Hidden by default */
z-index: 1000; /* Ensure it's above other content */
box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
transition: opacity var(--transition-speed);
}

/* Popup Content Styling */
.popupContent {
text-align: center;
font-size: 1.2em;
font-weight: bold;
margin-bottom: 15px;
}

/* Close Button Styling */
#closePopupBtn {
background-color: var(--secondary-color-light);
color: var(--text-light);
border: none;
padding: 12px 20px;
cursor: pointer;
border-radius: 5px;
font-size: 1em;
transition: background-color var(--transition-speed),
transform var(--transition-speed);
}

/* Close Button Hover Effect */
#closePopupBtn:hover {
background-color: var(--secondary-color-dark);
transform: scale(1.05);
}

/* Close Button Focus Effect */
#closePopupBtn:focus {
outline: none;
box-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}

/* Dark Theme Adjustments for Popup */
body.dark-theme #congratsPopup {
background-color: rgba(10, 11, 26, 0.9);
color: var(--text-light);
box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

/* Pop-up fade-in transition */
body:not(.dark-theme) #congratsPopup {
background-color: white;
color: var(--primary-color-light);
box-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

body:not(.dark-theme) .popupContent {
background-color: white;
}

body:not(.dark-theme) #congratsPopup.show {
opacity: 1;
}

/* Buttons */
button {
Expand Down Expand Up @@ -352,8 +412,7 @@ body.dark-theme button:hover {
background-color: var(--card-bg-light);
border-left: 2px solid var(--border-light);
transition: background-color var(--transition-speed),
border-color var(--transition-speed),
transform var(--transition-speed);
border-color var(--transition-speed), transform var(--transition-speed);
overflow-y: auto;
box-shadow: -4px 0 10px rgba(0, 0, 0, 0.1);
}
Expand Down Expand Up @@ -390,7 +449,6 @@ body.dark-mode .sidebar::-webkit-scrollbar-thumb {
}
}


body:not(.dark-theme) .sidebar {
background: var(--card-bg-light);
border-left: 2px solid var(--border-light);
Expand Down Expand Up @@ -460,7 +518,6 @@ body.dark-theme #instructionsTitle {

/* Display the sidebar and hamburger icon on screens <= 768px */
@media screen and (max-width: 768px) {

/* Hide the sidebar by default for smaller screens */
.sidebar {
display: none;
Expand Down Expand Up @@ -555,4 +612,4 @@ body.dark-theme #instructionsTitle {
font-size: 0.9em;
padding: 5px 8px;
}
}
}
23 changes: 20 additions & 3 deletions Alien.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const backgroundMusic = document.getElementById("backgroundMusic");
const hitSound = document.getElementById("hitSound");
const gameOverSound = document.getElementById("gameOverSound");
const shieldSound = document.getElementById("shieldSound");
const congratsSound = document.getElementById("congratsSound");

// Drop down menu
const instructionsTitle = document.getElementById("instructionsTitle");
Expand Down Expand Up @@ -962,6 +963,22 @@ function gameOver() {
localStorage.setItem("highScoreHistory", JSON.stringify(highScoreHistory));
// Update the high score in localStorage
localStorage.setItem("highScore", highScore);

// Delay the showing of the popup and the congratulatory sound by 2 seconds
setTimeout(() => {
// Show the congratulatory popup and play the congratulatory sound
const congratsPopup = document.getElementById("congratsPopup");
const newHighScoreElement = document.getElementById("newHighScore");
newHighScoreElement.textContent = highScore; // Display the high score
congratsPopup.style.display = "block"; // Show the popup
congratsSound.play(); // Play the congratulatory sound
}, 2000); // 2-second delay

// Close the popup when the close button is clicked
document.getElementById("closePopupBtn").addEventListener("click", () => {
const congratsPopup = document.getElementById("congratsPopup");
congratsPopup.style.display = "none"; // Hide the popup
});
}

// Start the explosion animation on the canvas at the player's position
Expand All @@ -970,13 +987,13 @@ function gameOver() {
level = 1;
aliensKilled = 0;

//Increment playCount when game ends
// Increment playCount when game ends
playCount++;
localStorage.setItem("playCount", playCount);

//Checking is player reached limit of 3 plays
// Checking if player reached the limit of 3 plays
if (playCount >= 3) {
setTimeOut(() => {
setTimeout(() => {
window.location.href = "./signup/signup.html";
}, 2000);
}
Expand Down
Binary file added congrats.wav
Binary file not shown.
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<audio id="healthBoostSound" src="health-boost-sound.m4a"></audio>
<audio id="speedBoostSound" src="speed-boost.m4a"></audio>
<audio id="shieldSound" src="shield.m4a"></audio>
<audio id="congratsSound" src="congrats.wav"></audio>

<style>
body {
Expand Down Expand Up @@ -646,6 +647,17 @@ <h2 class="primary-btn" id="logoutButton" style="display: none;">


</div>
<!-- Congratulatory Popup -->
<div id="congratsPopup" style="display: none;">
<div class="popupContent">
<h2>Congratulations!</h2>
<p>You've beat your high score!</p>
<p>Your new high score is: <span id="newHighScore"></span></p>
<button id="closePopupBtn">Close</button>
</div>
</div>



<header>

Expand Down

0 comments on commit 81607b0

Please sign in to comment.