Commit 81e8df3c authored by Tt's avatar Tt

热气球数据传输调整

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