Commit 58994e8b authored by Tt's avatar Tt

拖拽基础及校验完成

parent 953b0d58
...@@ -163,7 +163,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -163,7 +163,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
for (let y = 0; y < 9; y++) { for (let y = 0; y < 9; y++) {
for (let x = 0; x < 12; x++) { for (let x = 0; x < 12; x++) {
let node = cc.instantiate(block); let node = cc.instantiate(block);
let data = { x, y, val: '' }; let data = { x, y, val: '', rightVal: '' };
node.data = data; node.data = data;
node.x = -495 + space.x * x; node.x = -495 + space.x * x;
node.y = 365 - space.y * y; node.y = 365 - space.y * y;
...@@ -178,7 +178,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -178,7 +178,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
let first = null; let first = null;
this.layout_blocks.children.forEach(node => { this.layout_blocks.children.forEach(node => {
let point = node.data; let point = node.data;
if (list.some(li => li.compare(point))) { let li = list.find(li => li.compare(point))
if (li) {
point.rightVal = li.rightVal
pg.view.visible(pg.view.find(node, 'img_undone'), false) pg.view.visible(pg.view.find(node, 'img_undone'), false)
pg.view.visible(pg.view.find(node, 'img_focus'), true) pg.view.visible(pg.view.find(node, 'img_focus'), true)
if (!point.val && !first) { if (!point.val && !first) {
...@@ -217,6 +219,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -217,6 +219,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
node.x = 280 + space.x * (index - 9) node.x = 280 + space.x * (index - 9)
node.y = -110 - space.y * 2; node.y = -110 - space.y * 2;
} }
data.pos = cc.v2(node)
this.layout_words.addChild(node); this.layout_words.addChild(node);
this.updateWord(node, data); this.updateWord(node, data);
}); });
...@@ -262,39 +265,35 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -262,39 +265,35 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (!this.touching) return; if (!this.touching) return;
if (this.touching != data) return; if (this.touching != data) return;
// let rect = cc.rect(target.x, target.y, target.width, target.height); // let rect = cc.rect(target.x, target.y, target.width, target.height);
let rect = cc.rect(target.x, target.y, 50, 50); let rect = cc.rect(target.x, target.y, 1, 1);
//坐标转换 //坐标转换
console.log("1123123123") console.log("1123123123")
return; let collNode = null;
this.layout_blocks.children.forEach(node => {
// 开始做碰撞
let boat_left = pg.view.find(this, 'layout_bottom/boat_left') // 坐标转换
let boat_right = pg.view.find(this, 'layout_bottom/boat_right') let nodeWP = node.convertToWorldSpaceAR(cc.v2(-40, -40));
let leftRect = cc.rect(boat_left.x - boat_left.width / 2, boat_left.y - boat_left.height / 2, boat_left.width, boat_left.height); let nodeNP = this.layout_words.convertToNodeSpaceAR(nodeWP);
let rightRect = cc.rect(boat_right.x - boat_right.width / 2, boat_right.y - boat_right.height / 2, boat_right.width, boat_right.height); let nodeRect = cc.rect(nodeNP.x, nodeNP.y, node.width, node.height);
if (rect.intersects(nodeRect)) {
let isRight = false; collNode = node;
let currentRect = null; }
// if (rect.intersects(leftRect)) { })
// isRight = !!Game.getIns().boatLeft.isChild(data); //是否碰撞
// Game.getIns().boatLeft.setRight(data); if (!collNode) {
// currentRect = leftRect;
// } else if (rect.intersects(rightRect)) {
// isRight = !!Game.getIns().boatRight.isChild(data);
// Game.getIns().boatRight.setRight(data);
// currentRect = rightRect;
// }
if (!currentRect) {
this.touching = null; this.touching = null;
this.playLocalAudio('error').then(() => { target.x = target.data.pos.x;
this.touching = null; target.y = target.data.pos.y;
// this.updateItem(target, data); // this.playLocalAudio('error').then(() => {
}) // this.touching = null;
// // this.updateItem(target, data);
// })
return; return;
} }
//是否正确
let isRight = collNode.data.rightVal == data.word;
if (isRight) { if (isRight) {
let item = target; let item = target;
let lastArea = 100;
// this.playLocalAudio('right').then(() => { // this.playLocalAudio('right').then(() => {
// if (data.audioUrl) { // if (data.audioUrl) {
// pg.audio.playAudioByUrlThen(data.audioUrl).then(() => { // pg.audio.playAudioByUrlThen(data.audioUrl).then(() => {
...@@ -304,29 +303,63 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -304,29 +303,63 @@ export default class SceneComponent extends MyCocosSceneComponent {
// this.touching = null; // this.touching = null;
// } // }
// }) // })
this.touching = null;
if (item.scaleX == -1) {
// 计算当前坐标距离最左侧的距离
let space = currentRect.width - ((rect.x + rect.width) - currentRect.x) - lastArea / 5;
let time = space / 10;
cc.tween(item).by(time, { x: space }).start();
} else {
// 计算当前坐标距离最左侧的距离
let space = rect.x - currentRect.x - lastArea;
let time = space / 10;
cc.tween(item).by(time, { x: -space }).start();
}
item.off(cc.Node.EventType.TOUCH_START, this.onItemTouchStart, this); item.off(cc.Node.EventType.TOUCH_START, this.onItemTouchStart, this);
item.off(cc.Node.EventType.TOUCH_MOVE, this.onItemTouchMove, this); item.off(cc.Node.EventType.TOUCH_MOVE, this.onItemTouchMove, this);
item.off(cc.Node.EventType.TOUCH_END, this.onItemTouchEnd, this); item.off(cc.Node.EventType.TOUCH_END, this.onItemTouchEnd, this);
item.off(cc.Node.EventType.TOUCH_CANCEL, this.onItemTouchCancel, this); item.off(cc.Node.EventType.TOUCH_CANCEL, this.onItemTouchCancel, this);
pg.event.emit('mouse_05_add')
} else { } else {
this.playLocalAudio('error').then(() => { // this.playLocalAudio('error').then(() => {
this.touching = null; // this.touching = null;
// this.updateItem(target, data); // // this.updateItem(target, data);
}) // })
this.touching = null;
target.x = target.data.pos.x;
target.y = target.data.pos.y;
} }
// 检测一行是否完成, 完成加星星
// pg.event.emit('mouse_05_add')
return;
// if (isRight) {
// let item = target;
// let lastArea = 100;
// // this.playLocalAudio('right').then(() => {
// // if (data.audioUrl) {
// // pg.audio.playAudioByUrlThen(data.audioUrl).then(() => {
// // this.touching = null;
// // })
// // } else {
// // this.touching = null;
// // }
// // })
// if (item.scaleX == -1) {
// // 计算当前坐标距离最左侧的距离
// let space = currentRect.width - ((rect.x + rect.width) - currentRect.x) - lastArea / 5;
// let time = space / 10;
// cc.tween(item).by(time, { x: space }).start();
// } else {
// // 计算当前坐标距离最左侧的距离
// let space = rect.x - currentRect.x - lastArea;
// let time = space / 10;
// cc.tween(item).by(time, { x: -space }).start();
// }
// item.off(cc.Node.EventType.TOUCH_START, this.onItemTouchStart, this);
// item.off(cc.Node.EventType.TOUCH_MOVE, this.onItemTouchMove, this);
// item.off(cc.Node.EventType.TOUCH_END, this.onItemTouchEnd, this);
// item.off(cc.Node.EventType.TOUCH_CANCEL, this.onItemTouchCancel, this);
// pg.event.emit('mouse_05_add')
// } else {
// this.playLocalAudio('error').then(() => {
// this.touching = null;
// // this.updateItem(target, data);
// })
// }
//判断是否结束了 //判断是否结束了
// if (Game.getIns().boatLeft.isAllRight() && Game.getIns().boatRight.isAllRight()) { // if (Game.getIns().boatLeft.isAllRight() && Game.getIns().boatRight.isAllRight()) {
// this.showGameOver(); // this.showGameOver();
......
...@@ -167,6 +167,7 @@ export class GameNGT14 { ...@@ -167,6 +167,7 @@ export class GameNGT14 {
list.push({ list.push({
x: line.point.x + i, x: line.point.x + i,
y: line.point.y, y: line.point.y,
rightVal: line.answer[i],
compare: function (p) { compare: function (p) {
return this.x == p.x && this.y == p.y; return this.x == p.x && this.y == p.y;
} }
......
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