Commit 66b3465f authored by yu's avatar yu

1

parent b3ec34b8
...@@ -323,143 +323,143 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -323,143 +323,143 @@ export default class SceneComponent extends MyCocosSceneComponent {
private audioId: any; private audioId: any;
addPieceTouchEventListener(node: cc.Node, color) { addPieceTouchEventListener(node: cc.Node, color) {
node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => { // node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
if (playerMe.color != this._status.current) { // if (playerMe.color != this._status.current) {
this.blinkPiece(node); // this.blinkPiece(node);
return; // return;
} // }
if (this._status.current != color) { // if (this._status.current != color) {
this.blinkPiece(node); // this.blinkPiece(node);
return; // return;
} // }
if (this._status.letter == "") { // if (this._status.letter == "") {
this.blinkPiece(node); // this.blinkPiece(node);
return; // return;
} // }
if (node["cantMove"]) { // if (node["cantMove"]) {
this.blinkPiece(node); // this.blinkPiece(node);
return; // return;
} // }
this.stopRollPiece(node); // this.stopRollPiece(node);
node["touchStartPos"] = { // node["touchStartPos"] = {
nodeX: node.x, // nodeX: node.x,
nodeY: node.y, // nodeY: node.y,
touchX: event.getLocation().x, // touchX: event.getLocation().x,
touchY: event.getLocation().y, // touchY: event.getLocation().y,
}; // };
node.zIndex = 1; // node.zIndex = 1;
this.showStars(node); // this.showStars(node);
}); // });
node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => { // node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
if (playerMe.color != this._status.current) { // if (playerMe.color != this._status.current) {
return; // return;
} // }
if (this._status.current != color) { // if (this._status.current != color) {
return; // return;
} // }
if (this._status.letter == "") { // if (this._status.letter == "") {
return; // return;
} // }
if (node["cantMove"]) { // if (node["cantMove"]) {
return; // return;
} // }
const pos = event.getLocation(); // const pos = event.getLocation();
const touchStartPos = node["touchStartPos"]; // const touchStartPos = node["touchStartPos"];
const worldNodePos = node.parent.convertToWorldSpaceAR( // const worldNodePos = node.parent.convertToWorldSpaceAR(
cc.v2(touchStartPos.nodeX, touchStartPos.nodeY) // cc.v2(touchStartPos.nodeX, touchStartPos.nodeY)
); // );
const nodePos = node.parent.convertToNodeSpaceAR( // const nodePos = node.parent.convertToNodeSpaceAR(
cc.v2( // cc.v2(
worldNodePos.x + pos.x - touchStartPos.touchX, // worldNodePos.x + pos.x - touchStartPos.touchX,
worldNodePos.y + pos.y - touchStartPos.touchY // worldNodePos.y + pos.y - touchStartPos.touchY
) // )
); // );
node.setPosition(nodePos); // node.setPosition(nodePos);
}); // });
node.on(cc.Node.EventType.TOUCH_END, async (event: cc.Event.EventTouch) => { // node.on(cc.Node.EventType.TOUCH_END, async (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
if (playerMe.color != this._status.current) { // if (playerMe.color != this._status.current) {
return; // return;
} // }
if (this._status.current != color) { // if (this._status.current != color) {
return; // return;
} // }
if (this._status.letter == "") { // if (this._status.letter == "") {
return; // return;
} // }
if (node["cantMove"]) { // if (node["cantMove"]) {
return; // return;
} // }
node["cantMove"] = true; // node["cantMove"] = true;
if (this.checkNodeInRightBlock(node, color)) { // if (this.checkNodeInRightBlock(node, color)) {
const idx = this.getNextRightIdx(); // const idx = this.getNextRightIdx();
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
this.networkHelper.sendFrame({ // this.networkHelper.sendFrame({
type: "right", // type: "right",
idx: idx, // idx: idx,
uuid: playerMe.uuid, // uuid: playerMe.uuid,
color: playerMe.color, // color: playerMe.color,
}); // });
} else { // } else {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
this.networkHelper.sendFrame({ // this.networkHelper.sendFrame({
type: "wrong", // type: "wrong",
uuid: playerMe.uuid, // uuid: playerMe.uuid,
color: playerMe.color, // color: playerMe.color,
}); // });
} // }
}); // });
node.on(cc.Node.EventType.TOUCH_CANCEL, async (event: cc.Event.EventTouch) => { // node.on(cc.Node.EventType.TOUCH_CANCEL, async (event: cc.Event.EventTouch) => {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
if (playerMe.color != this._status.current) { // if (playerMe.color != this._status.current) {
return; // return;
} // }
if (this._status.current != color) { // if (this._status.current != color) {
return; // return;
} // }
if (this._status.letter == "") { // if (this._status.letter == "") {
return; // return;
} // }
if (node["cantMove"]) { // if (node["cantMove"]) {
return; // return;
} // }
node["cantMove"] = true; // node["cantMove"] = true;
if (this.checkNodeInRightBlock(node, color)) { // if (this.checkNodeInRightBlock(node, color)) {
const idx = this.getNextRightIdx(); // const idx = this.getNextRightIdx();
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
this.networkHelper.sendFrame({ // this.networkHelper.sendFrame({
type: "right", // type: "right",
idx: idx, // idx: idx,
uuid: playerMe.uuid, // uuid: playerMe.uuid,
color: playerMe.color, // color: playerMe.color,
}); // });
} else { // } else {
const playerMe = this.allPlayerList.find( // const playerMe = this.allPlayerList.find(
(player) => player.uuid == this.playerId // (player) => player.uuid == this.playerId
); // );
this.networkHelper.sendFrame({ // this.networkHelper.sendFrame({
type: "wrong", // type: "wrong",
uuid: playerMe.uuid, // uuid: playerMe.uuid,
color: playerMe.color, // color: playerMe.color,
}); // });
} // }
}); // });
} }
blinkPiece(node) { blinkPiece(node) {
...@@ -606,17 +606,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -606,17 +606,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
async pieceFindRightBlock(rightBlock, idx) { async pieceFindRightBlock(rightBlock, idx) {
const board = this._status.current == "Red" ? cc.find("Canvas/bg/chessBoard/boardItems") : cc.find("Canvas/bg/chessBoard/righttIems");
const color = this._status.current; const color = this._status.current;
const piece = cc.find(`Canvas/bg/chessBoard/piece${color}`); const piece = cc.find(`Canvas/bg/chessBoard/piece${color}`);
const prograssbar = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
const mask = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
);
let targetHeight =
(idx / (board.children.length - 2)) * prograssbar.height;
// console.log(idx + "_进度条高:" + targetHeight); // console.log(idx + "_进度条高:" + targetHeight);
const offsetX = { Red: -45, Blue: 45 }; const offsetX = { Red: -45, Blue: 45 };
...@@ -661,15 +653,29 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -661,15 +653,29 @@ export default class SceneComponent extends MyCocosSceneComponent {
piece.stopAllActions(); piece.stopAllActions();
await this.playLocalAudio("落子"); await this.playLocalAudio("落子");
piece.zIndex = 0; piece.zIndex = 0;
const effectNode = cc.find(`Canvas/bg/Life${color.toLowerCase()}/effect`);
effectNode.active = true;
asyncTweenTo(mask, 1, { height: targetHeight }, { easing: "cubicInOut" });
this.playLocalAudio("进度条升高");
await asyncPlayDragonBoneAnimation(effectNode, "normal", 1);
effectNode.active = false;
} }
updateProgress(idx) {
const color = this._status.current;
return new Promise(async (resolve, reject) => {
// const board = cc.find("Canvas/bg/chessBoard/boardItems");
const board = this._status.current == "Red" ? cc.find("Canvas/bg/chessBoard/boardItems") : cc.find("Canvas/bg/chessBoard/righttIems");
const prograssbar = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
const mask = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
);
let targetHeight =
(idx / (board.children.length - 2)) * prograssbar.height;
const effectNode = cc.find(`Canvas/bg/Life${color.toLowerCase()}/effect`);
effectNode.active = true;
asyncTweenTo(mask, 1, { height: targetHeight }, { easing: "cubicInOut" });
this.playLocalAudio("进度条升高");
await asyncPlayDragonBoneAnimation(effectNode, "normal", 1);
effectNode.active = false;
resolve('');
});
}
updateStatus(status = null) { updateStatus(status = null) {
if (status) { if (status) {
console.log(status); console.log(status);
...@@ -914,6 +920,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -914,6 +920,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
let isSuccess = await this.showVoice(rightBlock); let isSuccess = await this.showVoice(rightBlock);
this.hideVoice(); this.hideVoice();
if (isSuccess) { if (isSuccess) {
this.updateProgress(idx);
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "right", type: "right",
idx: nextIdx, idx: nextIdx,
...@@ -1300,48 +1307,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1300,48 +1307,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
} }
async movePiece(letter, color) {
const offsetX = { Red: -45, Blue: 45 };
const offsetY = { Red: -90, Blue: -90 };
const pieceNode = cc.find(`Canvas/bg/chessBoard/piece${color}`);
const board = this._status.current == "Red" ? cc.find("Canvas/bg/chessBoard/boardItems") : cc.find("Canvas/bg/chessBoard/righttIems");
const startIdx = this._status[color];
for (let i = startIdx + 1; i < board.children.length; i++) {
const targetNode = board.children[i];
const itemData = targetNode.getComponent("BoardGame4_double_ItemData");
const prograssbar = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask/prograssbar`
);
const mask = cc.find(
`Canvas/bg/Life${color.toLowerCase()}/life_${color.toLowerCase()}/mask`
);
const targetHeight = (i / board.children.length) * prograssbar.height;
this.playLocalAudio("movePiece 进度条升高");
cc.tween(mask)
.to(1, { height: targetHeight }, { easing: "cubicInOut" })
.start();
await asyncTweenTo(
pieceNode,
1,
{
x: targetNode.x + offsetX[color],
y: targetNode.y + offsetY[color],
},
{ easing: "cubicInOut" }
);
if (itemData.letter.toLowerCase() == letter.toLowerCase()) {
this._status[color] = i;
return;
}
}
this.finish();
}
finish() { finish() {
// onHomeworkFinish(); // onHomeworkFinish();
} }
......
...@@ -47,10 +47,10 @@ export class AI { ...@@ -47,10 +47,10 @@ export class AI {
}); });
} else { } else {
//调试加速 2 Math.random() * 3 + 4 //调试加速 2 Math.random() * 3 + 4
await asyncDelay(Math.random() * 3 + 4); await asyncDelay(Math.random() * 1 + 10 );
const idx = this.getNextRightIdx(); const idx = this.getNextRightIdx();
if (Math.random() < 1) { if (Math.random() < 0.8) {
this.networkHelper.sendFrame({ this.networkHelper.sendFrame({
type: "right", type: "right",
idx: idx, idx: idx,
......
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