diff --git a/public/index.html b/public/index.html index a18d31b..af17dda 100644 --- a/public/index.html +++ b/public/index.html @@ -36,7 +36,5 @@
- - diff --git a/public/sounds/amazing.mp3 b/public/sounds/amazing.mp3 deleted file mode 100644 index 490c10b..0000000 Binary files a/public/sounds/amazing.mp3 and /dev/null differ diff --git a/public/sounds/excitationMusic.mp3 b/public/sounds/excitationMusic.mp3 deleted file mode 100644 index 822c1d0..0000000 Binary files a/public/sounds/excitationMusic.mp3 and /dev/null differ diff --git a/public/sounds/unbelievable.mp3 b/public/sounds/unbelievable.mp3 deleted file mode 100644 index 9bbf63f..0000000 Binary files a/public/sounds/unbelievable.mp3 and /dev/null differ diff --git a/src/classes/main.js b/src/classes/main.js index 6b67626..8f14629 100644 --- a/src/classes/main.js +++ b/src/classes/main.js @@ -52,10 +52,12 @@ Main.prototype.play = function (direction) { if (Date.now() - this.prevTime <= 1200 || state !== 1) return; // if (state !== 1) return; this.element.play(); + if (direction === 99) return; + this.times += 1; this.computeScore(this.times, direction); - this.setMusic(direction); + window.soundInstance.playBomb(direction); this.prevTime = Date.now(); if (this.times >= this.max) { @@ -77,10 +79,3 @@ Main.prototype.computeScore = function (times, direction = 0) { sendMessage({ event: 'play', data: { currentTimes: times, currentScore: config.currentScore } }); } }; - -Main.prototype.setMusic = function (direction) { - let audio1 = document.getElementById('audio1'); - if (direction === 0) { - audio1.play(); - } -}; diff --git a/src/classes/sound.js b/src/classes/sound.js index c40575a..e744277 100644 --- a/src/classes/sound.js +++ b/src/classes/sound.js @@ -18,7 +18,10 @@ Sound.of = (function () { Sound.prototype.init = function () { createjs.Sound.alternateExtensions = ['mp3']; - const sounds = [{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }]; + const sounds = [ + { src: 'sounds/bgmMusic.mp3', id: 'bgm' }, + { src: 'sounds/audio1.mp3', id: 'audio1' }, + ]; const _this = this; createjs.Sound.addEventListener('fileload', function (event) { _this.music[event.id] = createjs.Sound.createInstance(event.id); @@ -31,6 +34,12 @@ Sound.prototype.playBgm = function () { this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐 }; +Sound.prototype.playBomb = function (direction) { + if (direction === 0 || direction === 1) { + this.music.audio1 && this.music.audio1.play(); // 播放爆炸声 + } +}; + // let music = {}; // function initSound() { // createjs.Sound.alternateExtensions = ['mp3']; diff --git a/src/classes/time.js b/src/classes/time.js index 1fc201e..4a16f63 100644 --- a/src/classes/time.js +++ b/src/classes/time.js @@ -65,7 +65,7 @@ Time.prototype.start = function (startTime = Date.now()) { this.startTime = startTime; this.duration = leftDuration ? leftDuration : this.duration; this.update(); - main.play(); + main.play(99); }; // 暂停游戏 暂停倒计时