Commit 8b846837 authored by Nguyễn Quang Sáng's avatar Nguyễn Quang Sáng

07/10/23 commit

parent 2e09a438
......@@ -147,6 +147,9 @@ export default class GameController extends cc.Component {
}
checkMergeability(row: number, col: number) {
const node = this.board.children[row * 5 + col].children[0];
if (node) this.currentBlock = node;
const mergedValue = this.currentBlock.getComponent(Block).value;
const neighbors = [
......@@ -324,6 +327,7 @@ export default class GameController extends cc.Component {
const data = this.blocksData.blockData;
const cells = this.board.children;
let fallingDown = false;
let hasCheckMerge = false;
for (let row = 0; row < data.length; row++) {
for (let col = 0; col < data[row].length; col++) {
......@@ -351,6 +355,9 @@ export default class GameController extends cc.Component {
const globalPos = cellMerge.convertToWorldSpaceAR(cc.Vec2.ZERO);
const localPos = cellMove.convertToNodeSpaceAR(globalPos);
data[newRow][newCol] = data[newRow - 1][newCol];
data[newRow - 1][newCol] = 0;
cc.tween(nodeToMove)
.to(0.3, { position: cc.v3(localPos.x, localPos.y) })
.call(() => {
......@@ -359,11 +366,12 @@ export default class GameController extends cc.Component {
cellMerge.addChild(nodeToMove);
nodeToMove.setPosition(cc.Vec2.ZERO);
data[newRow][newCol] = data[newRow - 1][newCol];
data[newRow - 1][newCol] = 0;
console.log(data);
if (!hasCheckMerge) {
console.log(row, col);
this.checkMergeability(row, col);
this.checkMergeability(row, col);
hasCheckMerge = true;
}
})
.start();
}
......@@ -372,6 +380,7 @@ export default class GameController extends cc.Component {
}
}
}
if (!fallingDown) {
this.checkMergeability(this.currentBlockRow, this.currentBlockCol);
}
......
import GameController from "../Controllers/GameController";
import BlockData from "../Data/BlockData";
import Utils from "../Tools/Utils";
const { ccclass, property } = cc._decorator;
......
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