Skip to content

Commit

Permalink
added audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Chen authored and Rachel Chen committed Mar 8, 2022
1 parent 8655779 commit 4aab42d
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file removed flower-icon.png
Binary file not shown.
Binary file added forest-with-birds.ogg
Binary file not shown.
Binary file added game-over.ogg
Binary file not shown.
Binary file added img/watering can.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
href="https://fonts.googleapis.com/css2?family=Odibee+Sans&family=Press+Start+2P&display=swap"
rel="stylesheet"
/>
<link rel="apple-touch-icon" sizes="150x150" href="/apple-touch-icon.png" />
</head>
<body>
<section>
<h1>Speed Game</h1>
<div class="game-area">
<h2>Your score is: <span id="score">0</span></h2>
<div class="container">
<div class="circle">1</div>
<div class="circle">2</div>
<div class="circle">3</div>
<div class="circle">4</div>
<div class="circle"><span class="flower">🌻</span></div>
<div class="circle"><span class="flower">🌻</span></div>
<div class="circle"><span class="flower">🌻</span></div>
<div class="circle"><span class="flower">🌻</span></div>
</div>
<div class="container">
<button type="button" id="start">Start game</button>
<button type="button" id="start" onclick="play()">Start game</button>
<button type="button" id="stop">Stop game</button>
</div>
</div>
Expand All @@ -37,6 +38,12 @@ <h2>Your score is: <span id="score">0</span></h2>
<button type="button" id="close">Close</button>
</div>
</section>
<audio
id="startMusic"
src="./forest-with-birds.ogg"
type="audio/ogg"
></audio>
<audio id="failMusic" src="./game-over.ogg" type="audio/ogg"></audio>
<script src="main.js"></script>
</body>
</html>
11 changes: 10 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const overlay = document.querySelector("#overlay");
const scoreText = document.querySelector("#score");
const resultText = document.querySelector("#result");

const startMusic = document.querySelector("#startMusic");
const failMusic = document.querySelector("#failMusic");

let active = 0;
let score = 0;
let pace = 1000;
Expand Down Expand Up @@ -36,6 +39,9 @@ const clickedCircle = (i) => {
const startGame = () => {
startButton.style.display = "none";
endButton.style.display = "inline";
startMusic.currentTime = 0;
startMusic.play();

for (let i = 0; i < circles.length; i++) {
circles[i].style.pointEvents = "auto";
}
Expand All @@ -51,7 +57,7 @@ const startGame = () => {
console.log("active circle:", active);
timer = setTimeout(startGame, pace);
pace = pace - 10;
if (rounds >= 1) {
if (rounds >= 3) {
endGame();
}
rounds++;
Expand All @@ -68,6 +74,9 @@ const startGame = () => {
};

const endGame = () => {
startMusic.pause();
startMusic.currentTime = 0;
failMusic.play();
console.log("game ended");
clearTimeout(timer);
overlay.style.visibility = "visible";
Expand Down
10 changes: 6 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ h1 {
background-color: saddlebrown;
display: inline-block;
margin: 2rem 1rem;
cursor: pointer;
/* cursor: pointer; */
display: flex;
align-items: center;
justify-content: center;
cursor: url("./img/watering\ can.png"), auto;
}
.circle.active {
/* background-image: url("https://cdn.pixabay.com/photo/2016/01/20/17/16/flower-1151963_1280.png"); */
background-color: yellow;
/* background-image: url(./flower-icon.png);
background-attachment: fixed; */
}

button {
Expand Down Expand Up @@ -98,3 +96,7 @@ button {
#stop {
display: none;
}

.flower {
font-size: 4rem;
}

0 comments on commit 4aab42d

Please sign in to comment.