|
@@ -1,7 +1,10 @@
|
|
import Gamecfg from "../../common/gameCfg";
|
|
import Gamecfg from "../../common/gameCfg";
|
|
|
|
+import { gameMethod } from "../../common/gameMethod";
|
|
import { xlsChapterLayout } from "../../common/xlsConfig";
|
|
import { xlsChapterLayout } from "../../common/xlsConfig";
|
|
import UEBase from "../../frameWork/compment/UEBase";
|
|
import UEBase from "../../frameWork/compment/UEBase";
|
|
|
|
+import { uiCommon } from "../../utils/UICommon";
|
|
import { GridConstant } from "./GridConstant";
|
|
import { GridConstant } from "./GridConstant";
|
|
|
|
+import { GridEvent } from "./GridEvent";
|
|
import UECell, { I_CellData } from "./UECell";
|
|
import UECell, { I_CellData } from "./UECell";
|
|
import UECube from "./UECube";
|
|
import UECube from "./UECube";
|
|
|
|
|
|
@@ -39,6 +42,7 @@ export default class UEGridMap extends UEBase {
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_MOVE, this.OnTouchMove, this);
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_MOVE, this.OnTouchMove, this);
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_END, this.OnTouchEnd, this);
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_END, this.OnTouchEnd, this);
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.OnTouchEnd, this);
|
|
this.gridLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.OnTouchEnd, this);
|
|
|
|
+ this.initEvent(GridEvent.TRIGGER_EMITTER, this.TriggerEmitter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -82,33 +86,35 @@ export default class UEGridMap extends UEBase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /** 创建格子 */
|
|
|
|
- private CreateCell(i: number, j: number) {
|
|
|
|
|
|
+ /** 根据索引获取实际像素坐标 */
|
|
|
|
+ private GetPosByIdx(i: number, j: number): cc.Vec3 {
|
|
const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
|
|
const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
|
|
|
|
+ return cc.v3(
|
|
|
|
+ startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
|
|
|
|
+ startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** 创建格子 */
|
|
|
|
+ private CreateCell(i: number, j: number) {
|
|
let cell = cc.instantiate(this.cellPrefab).getComponent(UECell);
|
|
let cell = cc.instantiate(this.cellPrefab).getComponent(UECell);
|
|
this.cellLayer.addChild(cell.node);
|
|
this.cellLayer.addChild(cell.node);
|
|
cell.node.width = GridConstant.CELL_WIDTH;
|
|
cell.node.width = GridConstant.CELL_WIDTH;
|
|
cell.node.height = GridConstant.CELL_HEIGHT;
|
|
cell.node.height = GridConstant.CELL_HEIGHT;
|
|
- cell.node.setPosition(cc.v2(
|
|
|
|
- startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
|
|
|
|
- startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
|
|
|
|
- ));
|
|
|
|
|
|
+ let pos = this.GetPosByIdx(i, j);
|
|
|
|
+ cell.node.setPosition(pos);
|
|
return cell;
|
|
return cell;
|
|
}
|
|
}
|
|
|
|
|
|
/** 创建棋子 */
|
|
/** 创建棋子 */
|
|
private CreateCube(i: number, j: number) {
|
|
private CreateCube(i: number, j: number) {
|
|
- const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
|
|
- const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
|
|
|
|
let cube = cc.instantiate(this.cubePrefab).getComponent(UECube);
|
|
let cube = cc.instantiate(this.cubePrefab).getComponent(UECube);
|
|
this.cubeLayer.addChild(cube.node);
|
|
this.cubeLayer.addChild(cube.node);
|
|
cube.node.width = GridConstant.CELL_WIDTH;
|
|
cube.node.width = GridConstant.CELL_WIDTH;
|
|
cube.node.height = GridConstant.CELL_HEIGHT;
|
|
cube.node.height = GridConstant.CELL_HEIGHT;
|
|
- cube.node.setPosition(cc.v2(
|
|
|
|
- startX + j * GridConstant.CELL_WIDTH + GridConstant.CELL_WIDTH / 2,
|
|
|
|
- startY - i * GridConstant.CELL_HEIGHT - GridConstant.CELL_HEIGHT / 2
|
|
|
|
- ));
|
|
|
|
|
|
+ let pos = this.GetPosByIdx(i, j);
|
|
|
|
+ cube.node.setPosition(pos);
|
|
return cube;
|
|
return cube;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -162,6 +168,7 @@ export default class UEGridMap extends UEBase {
|
|
targetCell.GetCube().PlayJellyAnim();
|
|
targetCell.GetCube().PlayJellyAnim();
|
|
if (this.clickCnt >= 2) {
|
|
if (this.clickCnt >= 2) {
|
|
console.log("二次点击同一个格子");
|
|
console.log("二次点击同一个格子");
|
|
|
|
+ targetCell.GetCube().TriggerClick();
|
|
} else {
|
|
} else {
|
|
this.clickCnt++;
|
|
this.clickCnt++;
|
|
}
|
|
}
|
|
@@ -181,6 +188,7 @@ export default class UEGridMap extends UEBase {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /** 根据像素坐标获取格子 */
|
|
private GetCellByPos(pos: cc.Vec2): UECell | null {
|
|
private GetCellByPos(pos: cc.Vec2): UECell | null {
|
|
const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
const startX = -(GridConstant.ROW * GridConstant.CELL_WIDTH) / 2;
|
|
const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
|
|
const startY = (GridConstant.COL * GridConstant.CELL_HEIGHT) / 2;
|
|
@@ -227,7 +235,7 @@ export default class UEGridMap extends UEBase {
|
|
}
|
|
}
|
|
|
|
|
|
private CanMergeItems(fromCell: UECell, toCell: UECell): boolean {
|
|
private CanMergeItems(fromCell: UECell, toCell: UECell): boolean {
|
|
- if (fromCell.GetCube().getCubeData().type == toCell.GetCube().getCubeData().type) {
|
|
|
|
|
|
+ if (fromCell.GetCube().GetCubeData().type == toCell.GetCube().GetCubeData().type) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -244,9 +252,101 @@ export default class UEGridMap extends UEBase {
|
|
fromCube.MoveToNewPos(cc.v3(toCell.node.x, toCell.node.y), 0.05);
|
|
fromCube.MoveToNewPos(cc.v3(toCell.node.x, toCell.node.y), 0.05);
|
|
}
|
|
}
|
|
|
|
|
|
- /** 抛出新的物品 */
|
|
|
|
- private ThrowNewItem() {
|
|
|
|
|
|
+ private GetEmptyCell(): UECell {
|
|
|
|
+ for (const key in this.cellMap) {
|
|
|
|
+ const element = this.cellMap[key];
|
|
|
|
+ if (element.IsEmpty()) {
|
|
|
|
+ return element;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** 发射出新的物品 */
|
|
|
|
+ private TriggerEmitter(idx: number, itemId: number, targetIdx: number) {
|
|
|
|
+ let emptyCell = this.GetEmptyCell();
|
|
|
|
+ if (!emptyCell) return;
|
|
|
|
+ targetIdx = emptyCell.GetZIndex();
|
|
|
|
+ let startPos = this.TranIdxToPos(idx);
|
|
|
|
+ let mergeCube = this.CreateCube(startPos.y, startPos.x);
|
|
|
|
+ mergeCube.Init({
|
|
|
|
+ type: 3,
|
|
|
|
+ id: itemId,
|
|
|
|
+ zIndex: idx,
|
|
|
|
+ unlock: 0
|
|
|
|
+ });
|
|
|
|
+ emptyCell.SetCube(mergeCube);
|
|
|
|
+ mergeCube.SetZIndex(1000);
|
|
|
|
+ let targetPos = this.TranIdxToPos(targetIdx);
|
|
|
|
+
|
|
|
|
+ // 设置动画时间
|
|
|
|
+ const duration = 0.8;
|
|
|
|
+ // 设置最大高度(向上弹跳的高度)
|
|
|
|
+ const maxHeight = 400;
|
|
|
|
+
|
|
|
|
+ // 计算起点和终点
|
|
|
|
+ const startWorldPos = mergeCube.node.getPosition();
|
|
|
|
+ const endWorldPos = this.GetPosByIdx(targetPos.y, targetPos.x);
|
|
|
|
+
|
|
|
|
+ // 计算方向向量和总距离
|
|
|
|
+ const moveVec = cc.v2(endWorldPos.x - startWorldPos.x, endWorldPos.y - startWorldPos.y);
|
|
|
|
+ const totalDistance = moveVec.mag();
|
|
|
|
+ const normalizedDir = moveVec.normalize();
|
|
|
|
+
|
|
|
|
+ // 计算最后弹跳的起点(在终点前100像素)
|
|
|
|
+ const bounceStartPos = cc.v3(
|
|
|
|
+ endWorldPos.x - normalizedDir.x * 100,
|
|
|
|
+ endWorldPos.y - normalizedDir.y * 100,
|
|
|
|
+ 0
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // 创建第一段抛物线(抛向空中然后落到弹跳起点)
|
|
|
|
+ const bezier1 = [];
|
|
|
|
+ const midPoint1 = cc.v3(
|
|
|
|
+ startWorldPos.x + moveVec.x * 0.3,
|
|
|
|
+ Math.max(startWorldPos.y, bounceStartPos.y) + maxHeight,
|
|
|
|
+ 0
|
|
|
|
+ );
|
|
|
|
+ bezier1.push(cc.v2(startWorldPos.x, startWorldPos.y));
|
|
|
|
+ bezier1.push(cc.v2(midPoint1.x, midPoint1.y));
|
|
|
|
+ bezier1.push(cc.v2(bounceStartPos.x, bounceStartPos.y));
|
|
|
|
+
|
|
|
|
+ // 创建最后的弹跳到终点
|
|
|
|
+ const bezier2 = [];
|
|
|
|
+ const bounceHeight = 80; // 弹跳高度
|
|
|
|
+
|
|
|
|
+ // 计算弹跳的最高点(在起跳点和终点之间)
|
|
|
|
+ const bounceTopPoint = cc.v2(
|
|
|
|
+ (bounceStartPos.x + endWorldPos.x) / 2, // 水平位置在中间
|
|
|
|
+ endWorldPos.y + bounceHeight // 垂直高度为弹跳高度
|
|
|
|
+ );
|
|
|
|
+ // const bounceSecondPos = cc.v3(
|
|
|
|
+ // endWorldPos.x - normalizedDir.x * 100,
|
|
|
|
+ // endWorldPos.y - normalizedDir.y * 100,
|
|
|
|
+ // 0
|
|
|
|
+ // );
|
|
|
|
+
|
|
|
|
+ // 最后一次弹跳到终点
|
|
|
|
+ bezier2.push(cc.v2(bounceStartPos.x, bounceStartPos.y)); // 起跳点
|
|
|
|
+ bezier2.push(bounceTopPoint); // 最高点
|
|
|
|
+ bezier2.push(cc.v2(endWorldPos.x, endWorldPos.y)); // 终点
|
|
|
|
+
|
|
|
|
+ // 创建动作序列
|
|
|
|
+ const bezierAction1 = cc.bezierTo(duration * 0.8, bezier1);
|
|
|
|
+ const bezierAction2 = cc.bezierTo(duration * 0.2, bezier2);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 组合所有动作
|
|
|
|
+ const seq = cc.sequence(
|
|
|
|
+ bezierAction1,
|
|
|
|
+ bezierAction2,
|
|
|
|
+ cc.callFunc(() => {
|
|
|
|
+ mergeCube.SetZIndex(targetIdx);
|
|
|
|
+ })
|
|
|
|
+ );
|
|
|
|
|
|
|
|
+ // 执行动画
|
|
|
|
+ mergeCube.node.runAction(seq);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|