Skip to content

Commit 003f48a

Browse files
author
jjteoh
committed
feat: add easter egg 🥚
1 parent 74c9624 commit 003f48a

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,19 @@ This project demonstrates:
6464
- Responsive design
6565
- Modern JavaScript features
6666

67-
6867
## License 📄
6968

7069
This project is open source and available under the [MIT License](LICENSE).
7170

72-
## Acknowledgments 🙏
71+
## Credits 🙏
7372

7473
- Inspired by the classic Nokia Snake game
75-
- Built with ❤️ for the web development community
74+
- Food eaten sound effect by [Ribhav Agrawal](https://pixabay.com/users/ribhavagrawal-39286533/)
75+
76+
- Game over sound effect by [FoxBoyTails](https://pixabay.com/users/foxboytails-49447089)
77+
78+
- Easter Egg video by [CuriosityShorts](https://www.youtube.com/watch?v=WAHoqt2y77k)
79+
7680

77-
---
7881

7982
*Enjoy the game? Star the repository and share it with your friends! ⭐*

index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ <h2>Classic Snake</h2>
5353
</div>
5454

5555
</div>
56+
57+
<!-- Easter Egg Video -->
58+
<video id="easterEggVideo" class="easter-egg-video hidden" playsinline>
59+
<source src="media/easter-egg-Lisan-al-Gaib.mp4" type="video/mp4">
60+
</video>
61+
5662
<footer class="footer">
5763
<p><small>Canvas Snake Game by <a href="https://github.com/jjteoh-thewebdev">JJTeoh</a> with ❤️</small></p>
5864
</footer>

media/easter-egg-Lisan-al-Gaib.mp4

376 KB
Binary file not shown.
File renamed without changes.

script.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const startMessageElement = document.getElementById("startMessage");
99
const startButton = document.getElementById("startButton");
1010
const gameContainer = document.querySelector(".game-container");
1111
const canvasContainer = document.querySelector(".canvas-container");
12+
const easterEggVideo = document.getElementById("easterEggVideo");
1213

1314
// --- Audio Elements ---
14-
const eatSound = new Audio('sounds/eat.mp3');
15-
const gameOverSound = new Audio('sounds/game-over.mp3');
15+
const eatSound = new Audio('media/eat.mp3');
16+
const gameOverSound = new Audio('media/game-over.mp3');
1617

1718
// --- Game Constants ---
1819
const GRID_SIZE = 20; // Number of cells in the grid
@@ -146,7 +147,12 @@ function moveSnake() {
146147
if (head.x === food.x && head.y === food.y) {
147148
score++;
148149
scoreElement.textContent = `Score: ${score}`;
149-
eatSound.play(); // Play eat sound effect
150+
eatSound.play();
151+
152+
// Check for easter egg
153+
if (score === 100) { // Trigger at 100
154+
triggerEasterEgg();
155+
}
150156

151157
// create food at a new position
152158
generateFood();
@@ -361,6 +367,24 @@ function showStartMessage() {
361367
gameOverElement.classList.add("hidden");
362368
}
363369

370+
function triggerEasterEgg() {
371+
// Pause the game
372+
gameActive = false;
373+
clearInterval(gameLoopInterval);
374+
375+
// Show and play the video
376+
easterEggVideo.classList.remove("hidden");
377+
easterEggVideo.play();
378+
379+
// Hide the video when it ends
380+
easterEggVideo.onended = function () {
381+
easterEggVideo.classList.add("hidden");
382+
// Resume the game
383+
gameActive = true;
384+
gameLoopInterval = setInterval(gameLoop, currentSpeed);
385+
};
386+
}
387+
364388
// --- Event Listeners ---
365389
document.addEventListener("keydown", handleKeyDown);
366390
restartButton.addEventListener("click", startGame);

style.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,18 @@
210210
padding: 8px 15px;
211211
}
212212
}
213-
213+
214+
.easter-egg-video {
215+
position: fixed;
216+
top: 50%;
217+
left: 50%;
218+
transform: translate(-50%, -50%);
219+
max-width: 90vw;
220+
max-height: 90vh;
221+
z-index: 1000;
222+
background-color: black;
223+
}
224+
225+
.easter-egg-video.hidden {
226+
display: none;
227+
}

0 commit comments

Comments
 (0)