index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import ModuleMedia from "./module/media";
  2. import ModuleGame from "./module/game";
  3. class Index {
  4. constructor() {
  5. this.startEle = document.querySelector(".mod-start");
  6. this.mainEle = document.querySelector(".mod-main");
  7. // this.videoElement = document.getElementById("cameraVideo");
  8. this.gameElement = this.mainEle.querySelector(".mod-game");
  9. this.decibelStandard = 60; //分贝值,超过这个值才能触发游戏交互
  10. this.init();
  11. }
  12. init() {
  13. this.initEvent();
  14. }
  15. initEvent() {
  16. this.startEle.addEventListener("click", () => {
  17. this.initMedia();
  18. this.initGame();
  19. this.startEle.classList.add("hide");
  20. this.mainEle.classList.remove("hide");
  21. this.media.add(decibel => {
  22. if (decibel >= this.decibelStandard) {
  23. console.log("声贝达到标准", decibel);
  24. this.game.jump(decibel - this.decibelStandard);
  25. }
  26. });
  27. });
  28. }
  29. initMedia() {
  30. this.media = new ModuleMedia();
  31. }
  32. initGame() {
  33. this.game = new ModuleGame(this.gameElement);
  34. }
  35. }
  36. new Index();