Browse Source

修改动作音频

master
song 4 years ago
parent
commit
03255545ff
  1. 2
      public/index.html
  2. BIN
      public/sounds/amazing.mp3
  3. BIN
      public/sounds/excitationMusic.mp3
  4. BIN
      public/sounds/unbelievable.mp3
  5. 11
      src/classes/main.js
  6. 11
      src/classes/sound.js
  7. 2
      src/classes/time.js

2
public/index.html

@ -36,7 +36,5 @@
</div>
</div>
<div id='_preload_div_' style='position:absolute; top:0; left:0; display: inline-block; height:720px; width: 1280px; text-align: center;'> <span style='display: inline-block; height: 100%; vertical-align: middle;'></span> <img src=images/_preloader.gif style='vertical-align: middle; max-height: 100%'/></div>
<!-- 音频 -->
<audio src="sounds/audio1.mp3" id="audio1" controls="controls" hidden="true"></audio>
</body>
</html>

BIN
public/sounds/amazing.mp3

Binary file not shown.

BIN
public/sounds/excitationMusic.mp3

Binary file not shown.

BIN
public/sounds/unbelievable.mp3

Binary file not shown.

11
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();
}
};

11
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'];

2
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);
};
// 暂停游戏 暂停倒计时

Loading…
Cancel
Save