Commit 81e8df3c authored by Tt's avatar Tt

热气球数据传输调整

parent 56532f95
......@@ -90,6 +90,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
initData() {
Game.getIns().init(this.data);
Game.getIns().reset();
this.tryData = [];
// 所有全局变量 默认都是null
this._cantouch = true;
}
......@@ -118,13 +119,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!Game.getIns().isOver) return pg.event.emit("game_start");
//发送给上端最后的数据
// alert("game_finish")
let player = { right: Game.getIns().player.score, error: Game.getIns().player.error }
let robot = { right: Game.getIns().robot.score, error: Game.getIns().robot.error }
if (Game.getIns().singleGame) {
onHomeworkFinish({ player })
} else {
onHomeworkFinish({ player, robot })
}
// int total
// int right
// int[] scores
// let player = { right: Game.getIns().player.score, error: Game.getIns().player.error }
let data: any = {};
data.total = Game.getIns().player.score;
data.right = Game.getIns().player.right;
data.scores = Game.getIns().player.voices;
onHomeworkFinish(data)
})
}
onTouchStart() {
......@@ -154,6 +158,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
list = JSON.parse(JSON.stringify(list));
list.sort((A, B) => { return Math.random() < 0.5 });
this.list = list;
Game.getIns().player.addScore(this.list.length);
this.count = 0;
this.lastCount = null;
this.fishs = [];
......@@ -210,7 +215,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
//左往右
item.x = -1334 / 2 + Math.random() * 1334;
item.y = -(720 / 2 + Math.random() * 400);//
cc.tween(item).to(10 + Math.random() * 10, { y: 1500 }).call(() => {
cc.tween(item).to(7 + Math.random() * 6, { y: 1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
this.viewFishs = this.viewFishs.filter(v => v.id != data.id);
}).start();
......@@ -332,10 +337,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
fishingRight(item, layout, data: Option, wpos) {
return new Promise(async (resolve, reject) => {
if (wpos.x > cc.view.getCanvasSize().width / 2 + 100) {
if (wpos.x > 1334 / 2 + 200) {
//弹弓动画。
await this.playGun(GUN_STATE.SHUT_RIGHT);
} else if (wpos.x < cc.view.getCanvasSize().width / 2 - 100) {
} else if (wpos.x < 1334 / 2 - 200) {
//弹弓动画。
await this.playGun(GUN_STATE.SHUT_LEFT);
} else {
......@@ -358,45 +363,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
// data.audioUrl && pg.audio.playAudioByUrl(data.audioUrl)
});
}
fishingError(item, layout, data) {
return new Promise((resolve, reject) => {
pg.audio.playLocalAudio(pg.view.find(this.res, "audio/error"))
if (data.fish.isLeft) {
//左往右
cc.tween(item).to(3, { x: 1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
item.active = false;
setTimeout(() => { item.parent = null; }, 1000);
if (this.touchFishs.every(fish => fish.id != data.id)) {
resolve('');
}
}).start();
} else {
//右往左
cc.tween(item).to(3, { x: -1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
item.active = false;
setTimeout(() => { item.parent = null; }, 1000);
if (this.touchFishs.every(fish => fish.id != data.id)) {
resolve('');
}
}).start();
}
setTimeout(() => { this.touching = false; }, 500);
});
}
fishing(item, layout, wpos) {
return new Promise(async (resolve, reject) => {
let data = item.data;
//item停止动画并
cc.Tween.stopAllByTarget(item);
await this.fishingRight(item, layout, data, wpos);
// if (data.right) {
// await this.fishingRight(item, layout, data);
// } else {
// await this.fishingError(item, layout, data);
// }
this.touchFishs.push(data);
return resolve(data.right);
});
}
......@@ -406,16 +378,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.touching) return;
let item: cc.Node = e.target;
let p = e.touch.getLocation();
let wpos = item.convertToWorldSpaceAR(p);
let wpos = p;
// let wpos = item.convertToWorldSpaceAR(p);
let data = item.data;
if (this.touchFishs.some(fish => fish.id == data.id)) return;
if (data.fish.isOut != FISH_OUT.RUNNING) return;
this.touching = true;
this.touchData = data;
data.fish.isOut = FISH_OUT.TOUCH;
let isRight = await this.fishing(item, this.layout_player, wpos);
isRight && Game.getIns().player.addScore();
!isRight && Game.getIns().player.addError();
await this.fishing(item, this.layout_player, wpos);
}
//机器人随机钓鱼
......@@ -539,14 +510,25 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.recrodEnd(data);
}); //结束录音
}
private tryData: Array<Option>;
async recrodEnd(data) {
Game.getIns().player.addVoice(data);
let score = data.result.overall;
if (score >= 80) {
//提示成功
this.updateTips(TIPS_STATE.GOOD);
Game.getIns().player.addRight();
this.touchFishs.push(this.touchData);
} else {
//提示失败
this.updateTips(TIPS_STATE.TRY);
if (this.tryData.some(td => td.id == this.touchData.id)) {
this.updateTips(TIPS_STATE.COM);
this.touchFishs.push(this.touchData);
} else {
this.updateTips(TIPS_STATE.TRY);
this.tryData.push(this.touchData);
this.viewFishs = this.viewFishs.filter(v => v.id != this.touchData.id);
}
}
await pg.time.delay(3);
this.updateTips(null);
......
......@@ -63,10 +63,14 @@ export class Item {
}
class Role {
public score: number;
public right: number;
public error: number;
public voices: Array<any>;
constructor() {
this.score = 0;
this.error = 0;
this.right = 0;
this.voices = [];
}
addScore(score: number = 1) {
this.score += score;
......@@ -74,6 +78,12 @@ class Role {
addError(score: number = 1) {
this.error += score;
}
addRight() {
this.right += 1;
}
addVoice(obj: any) {
this.voices.push(obj);
}
}
export class Player extends Role {
constructor() {
......
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