Add sound effects
This commit is contained in:
parent
76ff02d988
commit
a54cd442a9
5 changed files with 18 additions and 2 deletions
BIN
correct.mp3
Normal file
BIN
correct.mp3
Normal file
Binary file not shown.
BIN
incorrect.mp3
Normal file
BIN
incorrect.mp3
Normal file
Binary file not shown.
|
@ -10,6 +10,9 @@
|
|||
<script src="words.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<audio id="incorrectSfx" src="incorrect.mp3" type="audio/mpeg"></audio>
|
||||
<audio id="correctSfx" src="correct.mp3" type="audio/mpeg"></audio>
|
||||
<audio id="successSfx" src="success.mp3" type="audio/mpeg"></audio>
|
||||
<details open>
|
||||
<summary>Keymap</summary>
|
||||
<img src="keymap.png" alt="Keymap">
|
||||
|
|
17
nicolator.js
17
nicolator.js
|
@ -108,7 +108,9 @@ const wordDisplay = document.getElementById("word");
|
|||
const input = document.getElementById("input");
|
||||
const timer = document.getElementById("timer");
|
||||
const hintDisplay = document.getElementById("hint");
|
||||
|
||||
const incorrect = document.getElementById("incorrectSfx");
|
||||
const correct = document.getElementById("correctSfx");
|
||||
const success = document.getElementById("successSfx");
|
||||
const leftShiftCode = 32; // space
|
||||
const rightShiftCode = 16; // shift key
|
||||
let leftShift = false;
|
||||
|
@ -137,6 +139,13 @@ addEventListener("keyup", event => {
|
|||
});
|
||||
const check = () => {
|
||||
if (input.value == word) {
|
||||
if (repeats == 0) {
|
||||
success.currentTime = 0;
|
||||
success.play();
|
||||
} else {
|
||||
correct.currentTime = 0;
|
||||
correct.play();
|
||||
}
|
||||
clearTimeout(incorrectTimeout);
|
||||
clearTimeout(timerTimeout);
|
||||
wordDisplay.style.color = "green";
|
||||
|
@ -177,6 +186,7 @@ let incorrectTimeout = null;
|
|||
let timerTimeout = null;
|
||||
let word = null;
|
||||
let repeats = 0;
|
||||
let failed = false;
|
||||
const reset = () => {
|
||||
input.value = "";
|
||||
hint.innerHTML = "";
|
||||
|
@ -188,7 +198,10 @@ const reset = () => {
|
|||
const typeTime = typeTimePerKana * word.length;
|
||||
incorrectTimeout = setTimeout(() => {
|
||||
repeats += repeats == 0 ? 3 : 1;
|
||||
failed = true;
|
||||
wordDisplay.innerHTML = `${word} ❌`;
|
||||
incorrect.currentTime = 0;
|
||||
incorrect.play();
|
||||
for (let i = 0; i < word.length; i++) {
|
||||
const letter = word[i];
|
||||
let key = null;
|
||||
|
@ -222,7 +235,7 @@ const reset = () => {
|
|||
timer.value -= (1 / timerFPS) / typeTime;
|
||||
}, 1000 / timerFPS);
|
||||
if (repeats > 0) {
|
||||
repeats -= 1;
|
||||
repeats--;
|
||||
}
|
||||
};
|
||||
reset();
|
||||
|
|
BIN
success.mp3
Normal file
BIN
success.mp3
Normal file
Binary file not shown.
Reference in a new issue