Add sound effects

main
Elnu 2 years ago
parent 76ff02d988
commit a54cd442a9

Binary file not shown.

Binary file not shown.

@ -10,6 +10,9 @@
<script src="words.js"></script> <script src="words.js"></script>
</head> </head>
<body> <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> <details open>
<summary>Keymap</summary> <summary>Keymap</summary>
<img src="keymap.png" alt="Keymap"> <img src="keymap.png" alt="Keymap">

@ -108,7 +108,9 @@ const wordDisplay = document.getElementById("word");
const input = document.getElementById("input"); const input = document.getElementById("input");
const timer = document.getElementById("timer"); const timer = document.getElementById("timer");
const hintDisplay = document.getElementById("hint"); 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 leftShiftCode = 32; // space
const rightShiftCode = 16; // shift key const rightShiftCode = 16; // shift key
let leftShift = false; let leftShift = false;
@ -137,6 +139,13 @@ addEventListener("keyup", event => {
}); });
const check = () => { const check = () => {
if (input.value == word) { if (input.value == word) {
if (repeats == 0) {
success.currentTime = 0;
success.play();
} else {
correct.currentTime = 0;
correct.play();
}
clearTimeout(incorrectTimeout); clearTimeout(incorrectTimeout);
clearTimeout(timerTimeout); clearTimeout(timerTimeout);
wordDisplay.style.color = "green"; wordDisplay.style.color = "green";
@ -177,6 +186,7 @@ let incorrectTimeout = null;
let timerTimeout = null; let timerTimeout = null;
let word = null; let word = null;
let repeats = 0; let repeats = 0;
let failed = false;
const reset = () => { const reset = () => {
input.value = ""; input.value = "";
hint.innerHTML = ""; hint.innerHTML = "";
@ -188,7 +198,10 @@ const reset = () => {
const typeTime = typeTimePerKana * word.length; const typeTime = typeTimePerKana * word.length;
incorrectTimeout = setTimeout(() => { incorrectTimeout = setTimeout(() => {
repeats += repeats == 0 ? 3 : 1; repeats += repeats == 0 ? 3 : 1;
failed = true;
wordDisplay.innerHTML = `${word}`; wordDisplay.innerHTML = `${word}`;
incorrect.currentTime = 0;
incorrect.play();
for (let i = 0; i < word.length; i++) { for (let i = 0; i < word.length; i++) {
const letter = word[i]; const letter = word[i];
let key = null; let key = null;
@ -222,7 +235,7 @@ const reset = () => {
timer.value -= (1 / timerFPS) / typeTime; timer.value -= (1 / timerFPS) / typeTime;
}, 1000 / timerFPS); }, 1000 / timerFPS);
if (repeats > 0) { if (repeats > 0) {
repeats -= 1; repeats--;
} }
}; };
reset(); reset();

Binary file not shown.