-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4880 from somilyadav7/main
Added Virtual Piano Game
- Loading branch information
Showing
26 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# **Virtual Piano** | ||
|
||
--- | ||
|
||
<br> | ||
|
||
## **Description 📃** | ||
<!-- add your game description here --> | ||
An interactive virtual piano game built with HTML, CSS, and JavaScript. The objective of the game is to play musical notes by pressing the keys on the virtual piano, which correspond to real piano keys. | ||
</p> | ||
|
||
## **functionalities 🎮** | ||
<!-- add functionalities over here --> | ||
- Play Musical Notes: Press the keys on the virtual piano to play corresponding musical notes. | ||
- Keyboard Support: Use the keyboard to play notes for a more intuitive experience. | ||
- Sound Effects: Realistic piano sound effects for each key. | ||
|
||
<br> | ||
|
||
## **How to play? 🕹️** | ||
- Open the index.html file | ||
- Start typing the keys to play the sound | ||
- You can adjust the volume and allow visible of keys | ||
|
||
<br> | ||
|
||
## **Screenshots 📸** | ||
|
||
### Home | ||
|
||
![Home](virtual-piano.png) | ||
|
||
### Game | ||
|
||
![Game](virtual-piano-game.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html lang="pt-br"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Piano Simulator</title> | ||
|
||
<!-- styles --> | ||
<link rel="stylesheet" href="./src/styles/reset.css"> | ||
<link rel="stylesheet" href="./src/styles/main.css"> | ||
|
||
<!-- fonts --> | ||
<link rel="preconnect" href="https://fonts.googleapis.com"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,400;0,700;1,100;1,200;1,300;1,400&display=swap" | ||
rel="stylesheet"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<header> | ||
<h2>Virtual Piano</h2> | ||
<div class="column volume-slider"> | ||
<span>Volume</span> <input type="range" min="0" max="1" value="0.5" step="any"> | ||
</div> | ||
<div class="column keys-check"> | ||
<span>Keys</span> <input type="checkbox" checked> | ||
</div> | ||
</header> | ||
<ul class="piano-keys"> | ||
<li class="key white" data-key="a"><span>a</span></li> | ||
<li class="key black" data-key="w"><span>w</span></li> | ||
<li class="key white" data-key="s"><span>s</span></li> | ||
<li class="key black" data-key="e"><span>e</span></li> | ||
<li class="key white" data-key="d"><span>d</span></li> | ||
<li class="key black" data-key="f"><span>f</span></li> | ||
<li class="key white" data-key="t"><span>t</span></li> | ||
<li class="key black" data-key="g"><span>g</span></li> | ||
<li class="key white" data-key="y"><span>y</span></li> | ||
<li class="key black" data-key="h"><span>h</span></li> | ||
<li class="key white" data-key="u"><span>u</span></li> | ||
<li class="key black" data-key="j"><span>j</span></li> | ||
<li class="key white" data-key="k"><span>k</span></li> | ||
<li class="key black" data-key="o"><span>o</span></li> | ||
<li class="key white" data-key="l"><span>l</span></li> | ||
<li class="key black" data-key="p"><span>p</span></li> | ||
<li class="key white" data-key=";"><span>;</span></li> | ||
</ul> | ||
</div> | ||
|
||
<script src="./src/scripts/engine.js" defer></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const pianoKeys = document.querySelectorAll(".piano-keys .key"); | ||
const volumeSlider = document.querySelector(".volume-slider input"); | ||
const keysCheck = document.querySelector(".keys-check input"); | ||
|
||
let mapedKeys = []; | ||
let audio = new Audio("src/tunes/a.wav"); | ||
|
||
const playTune = (key) => { | ||
audio.src = `src/tunes/${key}.wav`; | ||
audio.play(); | ||
|
||
const clickedKey = document.querySelector(`[data-key="${key}"]`); | ||
clickedKey.classList.add("active"); | ||
setTimeout(() => { | ||
clickedKey.classList.remove("active"); | ||
}, 150); | ||
}; | ||
|
||
pianoKeys.forEach((key) => { | ||
key.addEventListener("click", () => playTune(key.dataset.key)); | ||
mapedKeys.push(key.dataset.key); | ||
}); | ||
|
||
document.addEventListener("keydown", (e) => { | ||
if (mapedKeys.includes(e.key)) { | ||
playTune(e.key); | ||
} | ||
}); | ||
|
||
const handleVolume = (e) => { | ||
audio.volume = e.target.value; | ||
}; | ||
|
||
const showHideKeys = () => { | ||
pianoKeys.forEach((key) => key.classList.toggle("hide")); | ||
}; | ||
|
||
volumeSlider.addEventListener("input", handleVolume); | ||
|
||
keysCheck.addEventListener("click", showHideKeys); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
body { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
background-color: #e3f2fd; | ||
color: #fff; | ||
} | ||
|
||
.container { | ||
width: 780px; | ||
border-radius: 20px; | ||
padding: 35px 40px; | ||
background-color: black; | ||
} | ||
|
||
.container header { | ||
color: #b2b2b2; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
|
||
header h2 { | ||
font-size: 1.6rem; | ||
} | ||
|
||
header .column { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
header .column span { | ||
font-weight: 500; | ||
margin-right: 15px; | ||
font-size: 1.19rem; | ||
} | ||
|
||
.volume-slider input { | ||
accent-color: #fff; | ||
} | ||
|
||
.keys-check input { | ||
width: 60px; | ||
height: 30px; | ||
appearance: none; | ||
border-radius: 30px; | ||
background-color: #4b4b4b; | ||
cursor: pointer; | ||
position: relative; | ||
} | ||
|
||
.keys-check input::before { | ||
content: ""; | ||
height: 20px; | ||
width: 20px; | ||
background-color: #8c8c8c; | ||
top: 50%; | ||
left: 0.3rem; | ||
border-radius: inherit; | ||
position: absolute; | ||
transform: translateY(-50%); | ||
transition: all 0.3s ease; | ||
} | ||
|
||
.keys-check input:checked::before { | ||
left: 2.1rem; | ||
background-color: #fff; | ||
} | ||
|
||
.piano-keys { | ||
display: flex; | ||
margin-top: 40px; | ||
} | ||
.piano-keys .key { | ||
cursor: pointer; | ||
user-select: none; | ||
list-style: none; | ||
color: #a2a2a2; | ||
position: relative; | ||
text-transform: uppercase; | ||
} | ||
|
||
.piano-keys .white { | ||
width: 70px; | ||
height: 230px; | ||
border: 1px solid black; | ||
border-radius: 8px; | ||
background: linear-gradient(#fff 96%, #eee 4%); | ||
} | ||
|
||
.piano-keys .black { | ||
width: 44px; | ||
height: 140px; | ||
z-index: 2; | ||
margin: 0 -22px 0 -22px; | ||
border: 1px solid black; | ||
border-radius: 0 0 5px 5px; | ||
background: linear-gradient(#333, #000); | ||
} | ||
|
||
.piano-keys span { | ||
position: absolute; | ||
bottom: 20px; | ||
width: 100%; | ||
text-align: center; | ||
font-size: 1.13rem; | ||
} | ||
|
||
.piano-keys .white.active { | ||
box-shadow: inset -5px 5px 20px rgba(0, 0, 0, 0.2); | ||
background: linear-gradient(to bottom #fff 0%, #eee 100%); | ||
} | ||
|
||
.piano-keys .black.active { | ||
box-shadow: inset -5px 5px 10px rgba(255, 255, 255, 0.1); | ||
background: linear-gradient(to bottom #000, #434343); | ||
} | ||
|
||
.piano-keys .key.hide span { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
outline: none; | ||
font-family: "Poppins", sans-serif; | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.