Commit 32067dad authored by 范雪寒's avatar 范雪寒

feat: 加音效

parent 93a5aa83
...@@ -153,17 +153,17 @@ cc.Class({ ...@@ -153,17 +153,17 @@ cc.Class({
await asyncTweenTo(BtnStart, 0.1, { opacity: 0 }); await asyncTweenTo(BtnStart, 0.1, { opacity: 0 });
BtnStart.active = false; BtnStart.active = false;
this.gameStart(); this.gameStart();
}); }, this.playAudio.bind(this, 'btn'));
const BtnRestart = cc.find('Canvas/bg/BtnRestart'); const BtnRestart = cc.find('Canvas/bg/BtnRestart');
addBtnListener(BtnRestart, async () => { addBtnListener(BtnRestart, async () => {
await asyncTweenTo(BtnRestart, 0.1, { opacity: 0 }); await asyncTweenTo(BtnRestart, 0.1, { opacity: 0 });
BtnRestart.active = false; BtnRestart.active = false;
this.gameStart(); this.gameStart();
}); }, this.playAudio.bind(this, 'btn'));
const BtnSpeaker = cc.find('Canvas/bg/BtnSpeaker'); const BtnSpeaker = cc.find('Canvas/bg/BtnSpeaker');
addBtnListener(BtnSpeaker, async () => { addBtnListener(BtnSpeaker, async () => {
await this.playQuestionAudio(); await this.playQuestionAudio();
}); }, this.playAudio.bind(this, 'btn'));
const bg = cc.find('Canvas/bg'); const bg = cc.find('Canvas/bg');
bg.on('touchstart', (event) => { bg.on('touchstart', (event) => {
...@@ -217,6 +217,8 @@ cc.Class({ ...@@ -217,6 +217,8 @@ cc.Class({
star.x = startPos.x; star.x = startPos.x;
star.y = startPos.y - starBig.height; star.y = startPos.y - starBig.height;
this.playAudio('star');
cc.tween(star) cc.tween(star)
.to(0.3, { y: middlePos.y + 80 }, { easing: 'quadOut' }) .to(0.3, { y: middlePos.y + 80 }, { easing: 'quadOut' })
.to(0.1, { y: middlePos.y + 40, scaleX: 1.2 / starBase.scale, scaleY: 0.8 / starBase.scale }, { easing: 'quadOut' }) .to(0.1, { y: middlePos.y + 40, scaleX: 1.2 / starBase.scale, scaleY: 0.8 / starBase.scale }, { easing: 'quadOut' })
...@@ -244,10 +246,12 @@ cc.Class({ ...@@ -244,10 +246,12 @@ cc.Class({
onGameEnd() { onGameEnd() {
showTrebleFirework(cc.find('Canvas/bg'), cc.find('RabbonBase').children); showTrebleFirework(cc.find('Canvas/bg'), cc.find('RabbonBase').children);
this.playAudio('end');
onHomeworkFinish(); onHomeworkFinish();
this.hideGuns();
const BtnRestart = cc.find('Canvas/bg/BtnRestart'); const BtnRestart = cc.find('Canvas/bg/BtnRestart');
BtnRestart.active = true; BtnRestart.active = true;
BtnRestart.opacity = 255;
}, },
async gameStart() { async gameStart() {
...@@ -264,9 +268,17 @@ cc.Class({ ...@@ -264,9 +268,17 @@ cc.Class({
showGuns() { showGuns() {
const bg = cc.find('Canvas/bg'); const bg = cc.find('Canvas/bg');
const gunBase = cc.find('Canvas/bg/GunBase'); const gunBase = cc.find('Canvas/bg/GunBase');
this.playAudio('move');
asyncTweenTo(gunBase, 0.5, { y: -bg.height / 2 }); asyncTweenTo(gunBase, 0.5, { y: -bg.height / 2 });
}, },
hideGuns() {
const bg = cc.find('Canvas/bg');
const gunBase = cc.find('Canvas/bg/GunBase');
this.playAudio('move');
asyncTweenTo(gunBase, 0.5, { y: -bg.height / 2 - gunBase.height });
},
showBallsinterval: null, showBallsinterval: null,
startShowBalls() { startShowBalls() {
const currentQuestion = this.data.questionList[this._status.currentQuestionIdx]; const currentQuestion = this.data.questionList[this._status.currentQuestionIdx];
...@@ -316,6 +328,8 @@ cc.Class({ ...@@ -316,6 +328,8 @@ cc.Class({
.repeatForever() .repeatForever()
.start(); .start();
this.playAudio('appare');
ball.on('touchstart', async (event) => { ball.on('touchstart', async (event) => {
if (ball.canNotTouch) { if (ball.canNotTouch) {
return; return;
...@@ -393,9 +407,11 @@ cc.Class({ ...@@ -393,9 +407,11 @@ cc.Class({
if (!currentQuestion) { if (!currentQuestion) {
return; return;
} }
this.playAudio('question', async () => {
this.speakerBlink(); this.speakerBlink();
await playAudioByUrlSync(currentQuestion.questionAudio); await playAudioByUrlSync(currentQuestion.questionAudio);
this.speakerStopBlink(); this.speakerStopBlink();
});
}, },
speakerList: null, speakerList: null,
...@@ -414,6 +430,7 @@ cc.Class({ ...@@ -414,6 +430,7 @@ cc.Class({
async shootTarget(node, location, shootBullet) { async shootTarget(node, location, shootBullet) {
const GunPos = cc.find('Canvas/bg/GunBase/GunPos'); const GunPos = cc.find('Canvas/bg/GunBase/GunPos');
const Gun = cc.find('Canvas/bg/GunBase/Gun'); const Gun = cc.find('Canvas/bg/GunBase/Gun');
const Water = cc.find('Canvas/bg/GunBase/Gun/Water');
const Muzzle = cc.find('Canvas/bg/GunBase/Gun/Muzzle'); const Muzzle = cc.find('Canvas/bg/GunBase/Gun/Muzzle');
const bg = cc.find('Canvas/bg') const bg = cc.find('Canvas/bg')
let offsetY = 0; let offsetY = 0;
...@@ -432,6 +449,7 @@ cc.Class({ ...@@ -432,6 +449,7 @@ cc.Class({
const angle = cc.v2(0, 1).signAngle(shootSide) * 180 / Math.PI; const angle = cc.v2(0, 1).signAngle(shootSide) * 180 / Math.PI;
bullet.angle = angle; bullet.angle = angle;
asyncTweenTo(Water, 0.1, { angle: -angle });
await asyncTweenTo(Gun, 0.1, { angle: angle, scaleY: 0.95 }); await asyncTweenTo(Gun, 0.1, { angle: angle, scaleY: 0.95 });
let startPos = exchangeNodePos(bg, Muzzle); let startPos = exchangeNodePos(bg, Muzzle);
bullet.x = startPos.x; bullet.x = startPos.x;
...@@ -442,6 +460,8 @@ cc.Class({ ...@@ -442,6 +460,8 @@ cc.Class({
.to(0.1, { scaleX: 1, scaleY: 1 }) .to(0.1, { scaleX: 1, scaleY: 1 })
.start(); .start();
this.playAudio('light');
let targetPos = bg.convertToNodeSpaceAR(cc.v2(location.x, location.y + offsetY)); let targetPos = bg.convertToNodeSpaceAR(cc.v2(location.x, location.y + offsetY));
let flySide = cc.v2(targetPos.x - startPos.x, targetPos.y - startPos.y); let flySide = cc.v2(targetPos.x - startPos.x, targetPos.y - startPos.y);
await asyncTweenTo(bullet, 0.1, { await asyncTweenTo(bullet, 0.1, {
...@@ -457,6 +477,7 @@ cc.Class({ ...@@ -457,6 +477,7 @@ cc.Class({
}, },
async targetDistroy(node) { async targetDistroy(node) {
this.playAudio('right');
const bg = node.getChildByName('bg'); const bg = node.getChildByName('bg');
bg.active = false; bg.active = false;
const DistroyAnime = node.getChildByName('DistroyAnime'); const DistroyAnime = node.getChildByName('DistroyAnime');
...@@ -468,6 +489,7 @@ cc.Class({ ...@@ -468,6 +489,7 @@ cc.Class({
}, },
async targetLaugh(node) { async targetLaugh(node) {
this.playAudio('wrong');
const x = node.x; const x = node.x;
let offsetX = RandomInt(20, 50) * 2 * (RandomInt(2) - 0.5); let offsetX = RandomInt(20, 50) * 2 * (RandomInt(2) - 0.5);
let offsetY = RandomInt(20, 50) * 2 * (RandomInt(2) - 0.5); let offsetY = RandomInt(20, 50) * 2 * (RandomInt(2) - 0.5);
...@@ -478,9 +500,14 @@ cc.Class({ ...@@ -478,9 +500,14 @@ cc.Class({
await asyncTweenTo(node, 0.05, { x: x }); await asyncTweenTo(node, 0.05, { x: x });
}, },
async playAudio(audioName) { playAudio(audioName, cb) {
const audioNode = cc.find(`AudioBase/${audioName}`); const audioNode = cc.find(`AudioBase/${audioName}`);
const audioClip = audioNode.getComponent(cc.AudioSource).clip; const audioClip = audioNode.getComponent(cc.AudioSource).clip;
cc.audioEngine.play(audioClip, false, 0.8); const id = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(id, () => {
if (cb) {
cb();
}
});
} }
}); });
...@@ -409,7 +409,7 @@ export async function jelly(node, offset = 0.1) { ...@@ -409,7 +409,7 @@ export async function jelly(node, offset = 0.1) {
}); });
} }
export function addBtnListener(node, cb) { export function addBtnListener(node, cb, beforeJelly = null) {
const button = node.getComponent(cc.Button); const button = node.getComponent(cc.Button);
if (!button) { if (!button) {
node.addComponent(cc.Button); node.addComponent(cc.Button);
...@@ -419,6 +419,9 @@ export function addBtnListener(node, cb) { ...@@ -419,6 +419,9 @@ export function addBtnListener(node, cb) {
return; return;
} }
node.canNotClick = true; node.canNotClick = true;
if (beforeJelly) {
beforeJelly();
}
await jelly(node); await jelly(node);
await cb(); await cb();
node.canNotClick = false; node.canNotClick = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment