12345678910111213141516171819202122232425262728293031323334353637383940 |
- import ModuleMedia from "./module/media";
- import ModuleGame from "./module/game";
- class Index {
- constructor() {
- this.startEle = document.querySelector(".mod-start");
- this.mainEle = document.querySelector(".mod-main");
- this.videoElement = document.getElementById("cameraVideo");
- this.gameElement = this.mainEle.querySelector(".mod-game");
- this.decibelStandard = 60; //分贝值,超过这个值才能触发游戏交互
- this.init();
- }
- init() {
- this.initEvent();
- }
- initEvent() {
- this.startEle.addEventListener("click", () => {
- this.initMedia();
- this.initGame();
- this.startEle.classList.add("hide");
- this.mainEle.classList.remove("hide");
- this.media.add(decibel => {
- if (decibel >= this.decibelStandard) {
- console.log("声贝达到标准", decibel);
- this.game.jump(decibel - this.decibelStandard);
- }
- });
- });
- }
- initMedia() {
- this.media = new ModuleMedia(this.videoElement);
- }
- initGame() {
- this.game = new ModuleGame(this.gameElement);
- }
- }
- new Index();
|