2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

58 rader
1.2 KiB

  1. function AudioForm(el) {
  2. const interval = el.elements['interval']
  3. const play = el.elements['play']
  4. const output = el.querySelector('output')
  5. const audioPool = []
  6. let intervalHandle = null
  7. let audioIndex = 0
  8. const items = 50
  9. for (let i = 0; i < items; i += 1) {
  10. const newAudio = new Audio('./sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav')
  11. newAudio.volume = 0.2;
  12. newAudio.addEventListener('canplaythrough', () => {
  13. audioPool[i].ready = true
  14. })
  15. newAudio.addEventListener('ended', () => {
  16. newAudio.pause()
  17. newAudio.currentTime = 0
  18. })
  19. audioPool[i] = {
  20. audio: newAudio,
  21. ended: true,
  22. ready: false,
  23. }
  24. newAudio.load()
  25. }
  26. const playSound = () => {
  27. for (let i = 0; i < items; i += 1) {
  28. if (!audioPool[i].ready) {
  29. return;
  30. }
  31. }
  32. audioPool[audioIndex].audio.play();
  33. audioIndex = (audioIndex + 1) % items;
  34. }
  35. el.addEventListener('submit', (e) => {
  36. e.preventDefault()
  37. const ms = 60000 / Number(interval.value);
  38. output.innerText = `${ms} ms`
  39. if (play.checked) {
  40. intervalHandle = window.setInterval(() => {
  41. playSound()
  42. }, ms)
  43. } else {
  44. window.clearInterval(intervalHandle);
  45. }
  46. play.checked = !play.checked
  47. })
  48. }
  49. const audioForm = new AudioForm(window.document.getElementById('formAudio'))