|
@@ -200,7 +200,7 @@ export default class UEGridMap extends UEBase {
|
|
|
cube.node.setPosition(originalPos.x + deltaPos.x, originalPos.y + deltaPos.y);
|
|
|
this.dragStartPos = touchPos;
|
|
|
const targetCell = this.GetCellByPos(touchPos);
|
|
|
- if (targetCell && targetCell != this.selectedCell) {
|
|
|
+ if (targetCell && !targetCell.IsEmpty() && targetCell != this.selectedCell) {
|
|
|
if (GameDataCenter.gridMap.CellCanPut(this.selectedCell, targetCell)) {
|
|
|
this.ueMergeTip.node.setPosition(targetCell.node.getPosition());
|
|
|
this.ueMergeTip.Init({
|
|
@@ -374,6 +374,35 @@ export default class UEGridMap extends UEBase {
|
|
|
mergeCube.node.runAction(seq);
|
|
|
}
|
|
|
|
|
|
+ /** 计算圆上的位置 */
|
|
|
+ private GetCirclePosition(index: number, total: number): cc.Vec2 {
|
|
|
+ const radius = 150; // 圆的半径
|
|
|
+
|
|
|
+ if (total === 1) {
|
|
|
+ // 只有一个元素时,放在正上方
|
|
|
+ return cc.v2(0, radius);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算每个元素之间的角度
|
|
|
+ const angleStep = 60; // 相邻两个元素之间的角度
|
|
|
+ const startAngle = 90 + ((total - 1) * angleStep) / 2; // 从90度(正上方)开始,向右分布
|
|
|
+
|
|
|
+ // 计算当前元素的角度(角度转弧度)
|
|
|
+ const angle = (startAngle - index * angleStep) * Math.PI / 180; // 减去角度使其向右分布
|
|
|
|
|
|
+ // 计算圆上的位置
|
|
|
+ const x = radius * Math.cos(angle);
|
|
|
+ const y = radius * Math.sin(angle);
|
|
|
+
|
|
|
+ return cc.v2(x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 设置物品在圆上的位置 */
|
|
|
+ private SetItemsPosition(mergeArr: any[]) {
|
|
|
+ mergeArr.forEach((item, index) => {
|
|
|
+ const pos = this.GetCirclePosition(index, mergeArr.length);
|
|
|
+ item.node.setPosition(pos);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
}
|