Browse Source

添加背景音乐

master
song 4 years ago
parent
commit
cdf6527aa5
  1. 4
      public/bird.js
  2. BIN
      public/images/suspend.png
  3. BIN
      public/sounds/bgmMusic.mp3
  4. BIN
      public/鸟妈妈回家_HTML5 Canvas.fla
  5. 8
      src/classes/sound.js
  6. 4
      src/custom.js
  7. 12
      src/message.js

4
public/bird.js

@ -175,13 +175,13 @@ if (reversed == null) { reversed = false; }
// 图层_1
this.instance = new lib.suspend();
this.instance.setTransform(37,-21);
this.instance.setTransform(138,-21);
this.timeline.addTween(cjs.Tween.get(this.instance).wait(1));
this._renderFirstFrame();
}).prototype = getMCSymbolPrototype(lib.Suspend, new cjs.Rectangle(37,-21,107,43), null);
}).prototype = getMCSymbolPrototype(lib.Suspend, new cjs.Rectangle(138,-21,107,43), null);
(lib.stopDemo_1 = function(mode,startPosition,loop,reversed) {

BIN
public/images/suspend.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
public/sounds/bgmMusic.mp3

Binary file not shown.

BIN
public/鸟妈妈回家_HTML5 Canvas.fla

Binary file not shown.

8
src/classes/sound.js

@ -14,10 +14,10 @@ Sound.of = function () {
Sound.prototype.init = function () {
createjs.Sound.alternateExtensions = ['mp3'];
const sounds = [
{ src: 'sounds/bgmMusic.mp3', id: 'bgm' },
{ src: 'sounds/excitationMusic.mp3', id: 'excitation' },
{ src: 'sounds/amazing.mp3', id: 'amazing' },
{ src: 'sounds/unbelievable.mp3', id: 'unbelievable' },
{ src: 'public/sounds/bgmMusic.mp3', id: 'bgm' },
{ src: 'public/sounds/excitationMusic.mp3', id: 'excitation' },
{ src: 'public/sounds/amazing.mp3', id: 'amazing' },
{ src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' },
];
createjs.Sound.addEventListener('fileload', function (event) {
this.music[event.id] = createjs.Sound.createInstance(event.id);

4
src/custom.js

@ -19,7 +19,7 @@ function initStage(lib) {
window.main = Main.of(gameOver); // 初始化鸟等
window.timeInstance = Time.of(gameOver); // 初始化游戏时间
// window.soundInstance = Sound.of(); // 初始化音频
Sound.of(); // 初始化音频
Level.of(2); // 游戏难度级别
Back.of(); // 返回按钮
isHash();
@ -31,7 +31,7 @@ function gameOver() {
const times = main.times;
const score = parseInt((config.total / config.times) * times);
setTimeout(() => {
End.of(score);
End.of(score || 0);
finishMessage(score, times);
}, 2000);
}

12
src/message.js

@ -21,6 +21,10 @@ window.addEventListener(
}
function startGame(data) {
if (state === 2) {
location.reload();
return;
}
const { count, game, status, param } = data;
config.count = count.duration;
config.duration = game.duration;
@ -28,7 +32,6 @@ window.addEventListener(
config.times = game.totalTimes;
config.level = game.level;
config.config = game.config;
state = status;
window.timeInstance.setDuration(game.duration);
// 开始倒计时
@ -36,10 +39,11 @@ window.addEventListener(
}
function playGame(data) {
if (state !== 1) return;
const { score, times, status, param } = data;
state = status;
config.currentScore = score;
config.currentTimes = times;
state = status;
if (config.config.directions[times - 1] === param.direction) {
main.play();
} else {
@ -48,12 +52,14 @@ window.addEventListener(
}
function pauseGame(data) {
if (state !== 1) return;
state = data.status;
Suspend.of();
window.timeInstance.pause();
}
function continueGame(data) {
if (state !== 3) return;
state = data.status;
window.timeInstance.start();
}
@ -63,6 +69,8 @@ window.addEventListener(
state = status;
config.total = score;
config.times = times;
End.of(score || 0);
window.timeInstance.setDuration(0);
}
},
false,

Loading…
Cancel
Save