Commit 6bf0994a authored by Tt's avatar Tt

mrbr02增加棒棒糖效果 打乱

parent fabbf024
......@@ -28,14 +28,20 @@ export default class MouseStart extends cc.Component {
this.ske.x = this.startPosition.x;
this.ske.y = this.startPosition.y;
}
play() {
play(audioUrl?: string) {
this.moveInTime = Game.getIns().aniEnter.time || 5;
return new Promise((resolve, reject) => {
let isPlaying = true;
this.ske.x = this.startPosition.x;
this.ske.y = this.startPosition.y;
this.ske.active = true;
this.node.active = true;
this.block.active = true;
pg.load.loadDB(this.ske, { ske: Game.getIns().aniEnter.skeJsonData.url, tex: Game.getIns().aniEnter.texJsonData.url, png: Game.getIns().aniEnter.texPngData.url }).then((animationName) => {
cc.tween(this.ske).to(1.3, { x: this.targetPosition.x, y: this.targetPosition.y }).call(() => {
if (Game.getIns().aniEnter.audioUrl) {
this.playAudioByUrl(Game.getIns().aniEnter.audioUrl, () => {
audioUrl = audioUrl ? audioUrl : Game.getIns().aniEnter.audioUrl;
if (audioUrl) {
pg.audio.playAudioByUrl(audioUrl).then(() => {
isPlaying = false;
resolve('');
})
......@@ -56,18 +62,4 @@ export default class MouseStart extends cc.Component {
})
});
}
playAudioByUrl(audio_url, cb = null) {
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
});
}
});
} else {
cb && cb();
}
}
}
......@@ -5,6 +5,7 @@ export class Option {
audioUrl;
public data;
public id: number;
public count: number;
constructor(data, id) {
this.id = id;
this.data = data;
......@@ -23,9 +24,18 @@ export class Item {
this.audio = data.audio;
this.image = data.image;
let id = 0;
this.optionList = data.optionList.map(o => {
return new Option(o, id++);
})
this.optionList.sort(function () {
return (0.5 - Math.random());
});
for (let i = 0; i < this.optionList.length; i++) {
this.optionList[i].count = i;
}
this.page = page;
}
}
......@@ -65,7 +75,8 @@ export default class Game {
}
checkSuccess(arr: Option[]) {
let data = this.getCurrentPage();
let options = data.optionList;
let options = data.optionList.concat();
options.sort((A, B) => A.id - B.id)
for (let i = 0; i < options.length; i++) {
if (arr[i] && arr[i].id != options[i].id) {
return false;
......
This diff is collapsed.
......@@ -44,6 +44,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property(cc.Node)
bg_card: cc.Node = null;
@property(cc.Node)
layout_lollipop: cc.Node = null;
initData() {
Game.getIns().init(this.data);
}
......@@ -58,6 +61,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.event.on("gameOver", () => { this.gameOver() })
}
private currentCards: cc.Node[];
//开始游戏
startGame() {
Game.getIns().reset();
......@@ -71,6 +75,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
//自动创建卡片
this.layout_card.active = true;
this.layout_card_result.active = false;
this.layout_lollipop.active = false;
this.createCrads(data);
}
getCurrentOpSet() {
......@@ -126,6 +131,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
private cardBgs: cc.Node[];
createCrads(list) {
this.layout_card.removeAllChildren();
let count = 0;
list.optionList.forEach(li => {
let opSet = this.getCurrentOpSet();
......@@ -182,7 +188,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
item.data = data
item.active = true;
}
private currentCards: cc.Node[];
onItemTouchStart(e) {
let target: cc.Node = e.target;
let data = target.data;
......@@ -204,9 +209,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
let itemBg = this.cardBgs.find(bg => {
return rect1.intersects(cc.rect(bg.x, bg.y, bg.width * bg.scale, bg.height * bg.scale));
})
if (!itemBg || this.currentCards[itemBg.data.id]) {
if (!itemBg || this.currentCards[itemBg.data.count]) {
//回退
target.setPosition(this.getPostionById(data.id))
target.setPosition(this.getPostionById(data.count))
for (let i = 0; i < this.currentCards.length; i++) {
let cd = this.currentCards[i];
if (cd && cd.data.id == target.data.id) {
......@@ -217,9 +222,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
return;
}
//执行
let pos = this.getBgPostionById(itemBg.data.id);
let pos = this.getBgPostionById(itemBg.data.count);
target.setPosition(pos);
this.currentCards[itemBg.data.id] = target;
this.currentCards[itemBg.data.count] = target;
let ani_flower = cc.instantiate(this.ani_flower);
ani_flower.active = true;
......@@ -236,6 +241,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.visible(pg.view.find(this, 'bg/bg_card/btn_check_grey'), !isFull)
}
checkFull() {
if (!this.currentCards) return;
if (!this.cards) return;
if (this.currentCards.length != this.cards.length) return false;
return this.currentCards.every(card => !!card);
}
......@@ -245,17 +252,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
let isSuccess = Game.getIns().checkSuccess(this.currentCards.map(cd => cd.data));
if (!isSuccess) {
this.currentCards.forEach(card => {
cc.tween(card).to(0.3, { x: this.getPostionById(card.data.id).x, y: this.getPostionById(card.data.id).y }).start();
cc.tween(card).to(0.3, { x: this.getPostionById(card.data.count).x, y: this.getPostionById(card.data.count).y }).start();
})
this.currentCards.length = 0;
return;
}
this.onTouchCheckCantouch = true;
//成功更新小老鼠进度
//显示全部图片效果。
//显示棒棒糖
pg.event.emit("mouse_add");
this.updateCardResult().then(() => {
this.updateCardResult().then(this.updateLollipop.bind(this)).then(() => {
Game.getIns().addPage();
if (Game.getIns().isOver) {
pg.event.emit("gameOver")
......@@ -268,10 +272,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
updateCardResult() {
return new Promise((res, rej) => {
let page = Game.getIns().getCurrentPage();
//显示小老鼠
if (page.audio) {
pg.audio.playAudioByUrl(page.audio).then(() => {
pg.view.find(this, "mouse_start").getComponent("mstart").play(page.audio).then(() => {
res(true);
})
});
} else {
setTimeout(() => {
res(true);
......@@ -286,6 +292,77 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
})
}
updateLollipop() {
return new Promise((res, rej) => {
//出现棒棒糖的部分。
//1.波浪。
//2.倒计时转圈
//3.弹出goodJob
//4.resolve
this.layout_lollipop.active = true;
pg.view.find(this.layout_lollipop, 'icon').active = true;
pg.view.find(this.layout_lollipop, 'texts').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_red').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_grey').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_highlight').active = false;
let vs = [pg.view.find(this.layout_lollipop, 'v1'), pg.view.find(this.layout_lollipop, 'v2'), pg.view.find(this.layout_lollipop, 'v3')]
//出现波浪
let count = 0;
let i1 = setInterval(() => {
count++;
let max = count % (vs.length + 2);
vs[0].active = 1 < max;
vs[1].active = 2 < max;
vs[2].active = 3 < max;
}, 200)
let lolliTouch = () => {
clearInterval(i1);
vs[0].active = false;
vs[1].active = false;
vs[2].active = false;
pg.view.find(this.layout_lollipop, 'progressbar_red').active = true;
pg.view.find(this.layout_lollipop, 'progressbar_grey').active = true;
pg.view.find(this.layout_lollipop, 'progressbar_highlight').active = true;
pg.view.touchOff(this.layout_lollipop, lolliTouch, this);
let progressbar_red = pg.view.find(this.layout_lollipop, 'progressbar_red');
let sprite = progressbar_red.getComponent(cc.Sprite);
sprite.fillRange = 1;
let i2 = setInterval(() => {
sprite.fillRange -= 0.005;
}, 30)
setTimeout(() => {
clearInterval(i2);
pg.view.find(this.layout_lollipop, 'icon').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_red').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_grey').active = false;
pg.view.find(this.layout_lollipop, 'progressbar_highlight').active = false;
let texts = pg.view.find(this.layout_lollipop, 'texts')
texts.active = true;
let complate = texts.getChildByName("complate");
let well = texts.getChildByName("well");
let good = texts.getChildByName("good");
complate.active = false;
well.active = false;
good.active = false;
let words = [complate, well, good];
let item = words[Math.floor(Math.random() * words.length)];
item.active = true;
item.opacity = 0;
item.scale = 0.1;
cc.tween(item).to(0.2, { scale: 1.1, opacity: 255 }).to(0.1, { scale: 1 }).delay(0.5).to(0.1, { opacity: 0, scale: 0 }).call(() => {
this.layout_lollipop.active = false;
res(true);
}).start();
}, 3000);
}
pg.view.touchOn(this.layout_lollipop, lolliTouch, this);
})
}
update() {
this.updateCheckBtn();
......
......@@ -5,7 +5,8 @@ export const defaultData = {
"item": {
"questionList": [
{
"audio": "", "image": "http://staging-teach.cdn.ireadabc.com/a5b6943a004bc48b07220f832853bd46.png",
"audio": "http://staging-teach.cdn.ireadabc.com/116fb7accb5428361836fbc46287f769.mp3",
"image": "http://staging-teach.cdn.ireadabc.com/a5b6943a004bc48b07220f832853bd46.png",
"optionList": [
{
"type": "picText",
......
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