Commit d5665d78 authored by Tt's avatar Tt

游戏完成

parent aef36fe4
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
"ver": "2.0.1", "ver": "2.0.1",
"uuid": "665e544c-fe92-4f24-bdcc-9475a763ff0c", "uuid": "665e544c-fe92-4f24-bdcc-9475a763ff0c",
"downloadMode": 0, "downloadMode": 0,
"duration": 0.264, "duration": 1.149388,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "552984b3-b335-40f3-94f7-b4360f0e9304",
"downloadMode": 0,
"duration": 2.448,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.0.1",
"uuid": "d26934ee-8708-4319-a122-ef3d4fb9d2dc",
"downloadMode": 0,
"duration": 3.24,
"subMetas": {}
}
\ No newline at end of file
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
"ver": "2.0.1", "ver": "2.0.1",
"uuid": "342d6b41-d606-43d5-9676-7b67f03d236f", "uuid": "342d6b41-d606-43d5-9676-7b67f03d236f",
"downloadMode": 0, "downloadMode": 0,
"duration": 0.653061, "duration": 0.365714,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
properties: {
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
let item = this.node;
// alert("抖动效果");
// let tween = cc.tween(item);
// tween.to(0.06, { angle: 10 })
// .to(0.06, { angle: 0 })
// .to(0.06, { angle: -10 })
// .to(0.06, { angle: 0 });
// tween.repeat(100);
// tween.start();
let ani = cc.repeatForever(cc.sequence(cc.moveBy(0.5, cc.v2(0, 25)), cc.moveBy(0.5, cc.v2(0, -25))));
item.runAction(ani);
},
start() {
},
// update (dt) {},
});
{
"ver": "1.0.8",
"uuid": "02c49c54-b257-4df4-a4d1-53b76a3e9c3a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -42,6 +42,12 @@ class CardManager { ...@@ -42,6 +42,12 @@ class CardManager {
getPage() { getPage() {
return this._cardArray; return this._cardArray;
} }
getAudio() {
return this._audio_url;
}
allRightNum() {
return this._cardArray.filter(c => c.right).length;
}
addPageNum() { addPageNum() {
this.pageId++; this.pageId++;
if (!this.getPage()) { if (!this.getPage()) {
......
...@@ -232,6 +232,18 @@ pg.view = { ...@@ -232,6 +232,18 @@ pg.view = {
skl.setAnimation(0, aniName, loop); skl.setAnimation(0, aniName, loop);
return skl; return skl;
}, },
playDragonBone(item, aniName, loop) {
if (!item || !cc.isValid(item)) return log.w("动画播放失败,传入了错误的item");
if (!aniName) return log.w("动画播放失败,传入了错误的aniName");
let node = item.node ? item.node : item;
if (!cc.isValid(node)) return log.w("节点已销毁");
let dba = node.getComponent(dragonBones.ArmatureDisplay);
dba.playAnimation(aniName, loop);
return dba;
},
cloneNode(node) {
return cc.instantiate(node);
}
} }
//加载 未封装bundle //加载 未封装bundle
pg.load = { pg.load = {
......
This diff is collapsed.
...@@ -171,6 +171,9 @@ cc.Class({ ...@@ -171,6 +171,9 @@ cc.Class({
pg.view.visible(this.btn_replay, false); pg.view.visible(this.btn_replay, false);
pg.view.touchOn(this.btn_replay, this.onTouchReplay, this); pg.view.touchOn(this.btn_replay, this.onTouchReplay, this);
this.initLayout(); this.initLayout();
this.catBegin().then(() => {
this.catChoice();
});
}, },
initStars() { initStars() {
// this.length = CardManager.getIns().getTestlet(); // this.length = CardManager.getIns().getTestlet();
...@@ -213,20 +216,24 @@ cc.Class({ ...@@ -213,20 +216,24 @@ cc.Class({
pg.view.touchOn(audio, this.onTouchAudio, this); pg.view.touchOn(audio, this.onTouchAudio, this);
}, },
onTouchAudio(touch) { onTouchAudio(touch) {
if (this._gameCode != 0) return resolve('');
if (!this._cantouch) return; if (!this._cantouch) return;
this._cantouch = false; this._cantouch = false;
let item = touch.target.parent; let item = touch.target.parent;
let data = item.data;
this.playAudioAni(item).then(() => { this.playAudioAni(item).then(() => {
this._cantouch = true; this._cantouch = true;
}); });
}, },
onTouchItem(touch, info) { onTouchItem(touch, info) {
if (!this._cantouch) return; return new Promise((resolve, reject) => {
this._cantouch = false; if (this._gameCode != 0) return resolve('');
if (!this._cantouch) return resolve('');
let item = touch.target; let item = touch.target;
if (this._successItems.indexOf(item) > -1) return resolve('');
let data = item.data; let data = item.data;
this._cantouch = false;
if (data.right) { if (data.right) {
this.catRight();
pg.view.visible(pg.view.find(item, 'box'), true); pg.view.visible(pg.view.find(item, 'box'), true);
this.playSFX("audio_right").then(() => { this.playSFX("audio_right").then(() => {
//audio 播放的时候动画播放, audio停的时候 动画正好能停下 //audio 播放的时候动画播放, audio停的时候 动画正好能停下
...@@ -234,83 +241,26 @@ cc.Class({ ...@@ -234,83 +241,26 @@ cc.Class({
//下一次播放没有问题即可 //下一次播放没有问题即可
this.playAudioAni(item).then(() => { this.playAudioAni(item).then(() => {
this._cantouch = true; this._cantouch = true;
this._successItems.push(item);
this.catNormal();
this.groupEnd();
resolve('');
}) })
}); });
} else { } else {
this.catError();
//失败--抖动效果 //失败--抖动效果
ani.shake(item); ani.shake(item);
// this.playAudioAni(item).then(() => {
// });
this.playSFX("audio_error").then(() => { this.playSFX("audio_error").then(() => {
this.playAudioAni(item).then(() => {
this._cantouch = true; this._cantouch = true;
this.catNormal();
resolve('');
});
}); });
} }
// this._cardTouchItems.push(item);
// if (this._cardTouchItems.length == 2) { });
// let item0 = this._cardTouchItems[0];
// let item1 = this._cardTouchItems[1];
// //检测重复点击 取消选中
// if (item0.data && item1.data && item0.data.cardId == item1.data.cardId) {
// pg.view.visible(pg.view.find(item, 'box'), false);
// this._cantouch = true;
// } else if (item0.data && item1.data && item0.data.cardDid == item1.data.cardDid) {
// //成功--变小 消失
// this._successItems.push(item0);
// this._successItems.push(item1);
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// this.createRightAni(cc.v2(item0.x, item0.y));
// this.createRightAni(cc.v2(item1.x, item1.y));
// this.playSFX("audio_right").then(() => {
// this._cantouch = true;
// this.playAudioAni(item0).then(() => {
// this.playAudioAni(item1).then(() => {
// ani.scaleOut(item0);
// ani.scaleOut(item1).then(() => {
// setTimeout(() => {
// this.groupEnd();//判定单组结束
// }, 100);
// });
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// });
// });
// });
// })
// });
// } else {
// //失败--抖动效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// this.playAudioAni(item).then(() => {
// ani.shake(item0);
// ani.shake(item1);
// pg.view.visible(pg.view.find(item0, 'box'), false);
// pg.view.visible(pg.view.find(item1, 'box'), false);
// this.playSFX("audio_error").then(() => {
// this._cantouch = true;
// });
// });
// });
// }
// this._cardTouchItems.length = 0;
// } else if (this._cardTouchItems.length == 1) {
// //显示选中效果
// pg.view.visible(pg.view.find(item, 'box'), true);
// this.playSFX("audio_choice").then(() => {
// //audio 播放的时候动画播放, audio停的时候 动画正好能停下
// //如果动画停的位置不对,直接强制设置对应的效果
// //下一次播放没有问题即可
// this.playAudioAni(item).then(() => {
// this._cantouch = true;
// })
// });
// } else {
// //异常情况
// this._cardTouchItems.length = 0;
// this._cantouch = true;
// }
}, },
playAudioAni(item) { playAudioAni(item) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -339,37 +289,42 @@ cc.Class({ ...@@ -339,37 +289,42 @@ cc.Class({
}, },
//回合结束 //回合结束
groupEnd() { groupEnd() {
if (this._successItems.length < this._cardPage.length) return; if (this._successItems.length >= CardManager.getIns().allRightNum()) {
if (this._gameCode != 0) return; //判定结束
let code = CardManager.getIns().addPageNum();
if (code == 0) {
this._gameCode = 0;
this.initSingleData();
this.initLayout();
} else if (code == 1) {
this._gameCode = 1;
//播放星星动画 然后下一页
this.playSFX("audio_bigStar");
this.createStarAni().then(() => {
this._gameCode = 0;
this.initSingleData();
this.initLayout();
})
} else if (code == 2) {
this._gameCode = 2; this._gameCode = 2;
//播放星星动画 然后结束 this.catFinish();
this.playSFX("audio_bigStar");
this.playSFX("audio_sahua");
this.createStarAni().then(() => { })
this.createFireworkAni().then(() => {
//gameOver
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
pg.view.visible(this.btn_replay, true);
})
} }
// if (this._successItems.length < this._cardPage.length) return;
// if (this._gameCode != 0) return;
// let code = CardManager.getIns().addPageNum();
// if (code == 0) {
// this._gameCode = 0;
// this.initSingleData();
// this.initLayout();
// } else if (code == 1) {
// this._gameCode = 1;
// //播放星星动画 然后下一页
// this.playSFX("audio_bigStar");
// this.createStarAni().then(() => {
// this._gameCode = 0;
// this.initSingleData();
// this.initLayout();
// })
// } else if (code == 2) {
// this._gameCode = 2;
// //播放星星动画 然后结束
// this.playSFX("audio_bigStar");
// this.playSFX("audio_sahua");
// this.createStarAni().then(() => { })
// this.createFireworkAni().then(() => {
// //gameOver
// // 游戏结束时需要调用这个方法通知系统作业完成
// onHomeworkFinish();
// pg.view.visible(this.btn_replay, true);
// })
// }
}, },
createRightAni(pos) { createRightAni(pos) {
// let right = pg.view.find(this, 'right'); // let right = pg.view.find(this, 'right');
...@@ -420,8 +375,10 @@ cc.Class({ ...@@ -420,8 +375,10 @@ cc.Class({
if (!audioSource) return resolve(); if (!audioSource) return resolve();
let audioClip = audioSource.clip; let audioClip = audioSource.clip;
if (!audioClip) return resolve(); if (!audioClip) return resolve();
cc.audioEngine.play(audioClip, false, 1); let id = cc.audioEngine.play(audioClip, false, 1);
cc.audioEngine.setFinishCallback(id, () => {
resolve(''); resolve('');
})
}); });
}, },
length, length,
...@@ -572,4 +529,49 @@ cc.Class({ ...@@ -572,4 +529,49 @@ cc.Class({
return quadBase; return quadBase;
}, },
catBegin() {
return new Promise((resolve, reject) => {
this._cantouch = false;
let cat = pg.view.find(this, "cat");
pg.view.playDragonBone(cat, "begin");
pg.audio.playAudioByUrl(CardManager.getIns().getAudio()).then(() => {
resolve('');
});
});
},
catChoice() {
return new Promise((resolve, reject) => {
this.playSFX("mao_choice").then(() => {
let items = this._cardLayout.children;
let item = items.filter(it => {
return it.data.cardId == 0
})[0];
this._cantouch = true;
this.onTouchItem({ target: item }).then(() => {
resolve('');
})
});
});
},
catFinish() {
return new Promise((resolve, reject) => {
let cat = pg.view.find(this, "cat");
pg.view.playDragonBone(cat, "finish");
this.playSFX("mao_right").then(() => {
});
});
},
catRight() {
let cat = pg.view.find(this, "cat");
pg.view.playDragonBone(cat, "right");
},
catError() {
let cat = pg.view.find(this, "cat");
pg.view.playDragonBone(cat, "wrong");
},
catNormal() {
let cat = pg.view.find(this, "cat");
pg.view.playDragonBone(cat, "normal");
}
}); });
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