|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-11 18:05:45
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-03-17 14:06:35
|
|
|
+ * @LastEditTime: 2025-03-17 14:54:40
|
|
|
* @Description:
|
|
|
*/
|
|
|
import { _decorator, Color, EventTouch, instantiate, JsonAsset, Node, Prefab, Sprite, UITransform, Vec3, Widget, tween } from "cc";
|
|
|
@@ -70,6 +70,12 @@ export class EliminateViewComp extends CCComp {
|
|
|
@property({ type: LabelChange, displayName: "额外奖励" })
|
|
|
private awardLb: LabelChange = null!;
|
|
|
|
|
|
+ @property({ type: Prefab, displayName: "金币预制体" })
|
|
|
+ private coinPrefab: Prefab = null!;
|
|
|
+
|
|
|
+ @property({ type: Prefab, displayName: "红包预制体" })
|
|
|
+ private redPacketPrefab: Prefab = null!;
|
|
|
+
|
|
|
//游戏状态
|
|
|
game_status: number = GameStatus.None;
|
|
|
max_row: number = 0;
|
|
|
@@ -280,11 +286,13 @@ export class EliminateViewComp extends CCComp {
|
|
|
private async loadPrefabsAsset() {
|
|
|
const loadMap = {
|
|
|
gridPrefab: "gui/eliminate/prefabs/Grid",
|
|
|
- rotatePrefab: "gui/eliminate/prefabs/Rotation"
|
|
|
+ rotatePrefab: "gui/eliminate/prefabs/Rotation",
|
|
|
+ coinPrefab: "gui/eliminate/prefabs/Coin", // 添加金币预制体路径
|
|
|
+ redPacketPrefab: "gui/eliminate/prefabs/RedPacket" // 添加红包预制体路径
|
|
|
};
|
|
|
Object.keys(loadMap).forEach(key => {
|
|
|
let path = loadMap[key as keyof typeof loadMap];
|
|
|
- const keyTyped = key as 'gridPrefab' | 'rotatePrefab';
|
|
|
+ const keyTyped = key as 'gridPrefab' | 'rotatePrefab' | 'coinPrefab' | 'redPacketPrefab';
|
|
|
new Promise((resolve, reject) => {
|
|
|
oops.res.load(path, Prefab, (err: Error | null, res: any) => {
|
|
|
if (err) {
|
|
|
@@ -293,26 +301,20 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
if (res) {
|
|
|
this[keyTyped] = res;
|
|
|
- console.log("this.gridPrefab", this.gridPrefab);
|
|
|
resolve(0);
|
|
|
}
|
|
|
});
|
|
|
})
|
|
|
});
|
|
|
|
|
|
- //加载类型预制体
|
|
|
- console.log("this.gameConfig", this.gameConfig);
|
|
|
-
|
|
|
const prefabUrls: string[] = [];
|
|
|
const typeList = this.gameConfig['GridType'];
|
|
|
Object.keys(typeList).forEach(key => {
|
|
|
- console.log(">>>>>>>>>>", key);
|
|
|
let path = typeList[key]['prefabUrl'];
|
|
|
prefabUrls.push(path);
|
|
|
});
|
|
|
|
|
|
prefabUrls.forEach(path => {
|
|
|
- console.log("11111111", path)
|
|
|
new Promise((resolve, reject) => {
|
|
|
oops.res.load(path, Prefab, (err: Error | null, res: any) => {
|
|
|
if (err) {
|
|
|
@@ -326,7 +328,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
});
|
|
|
})
|
|
|
});
|
|
|
- console.log("this.prefabUrlMap", this.prefabUrlMap)
|
|
|
+ // console.log("this.prefabUrlMap", this.prefabUrlMap)
|
|
|
}
|
|
|
|
|
|
private initGrids() {
|
|
|
@@ -407,9 +409,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 初始化格子状态
|
|
|
for (let rowIndex = 0; rowIndex < this.max_row; rowIndex++) {
|
|
|
for (let columnIndex = 0; columnIndex < this.max_col; columnIndex++) {
|
|
|
@@ -759,7 +758,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
// 方块到格子
|
|
|
else if (this.editingData.brickData && this.editingData.gridList.length > 0) {
|
|
|
- console.log("移动到格子了")
|
|
|
// 修改格子
|
|
|
this.editingData.gridList.forEach((gridData) => {
|
|
|
gridData.status = GridStatus.Used
|
|
|
@@ -1109,14 +1107,16 @@ export class EliminateViewComp extends CCComp {
|
|
|
const gridEliminateList = d.gridEliminateList
|
|
|
const eliminateRowNum = d.eliminateRowNum
|
|
|
const eliminateColumnNum = d.eliminateColumnNum
|
|
|
- // 无行可消除
|
|
|
+
|
|
|
if (gridEliminateList.length < 1) {
|
|
|
resolve(false)
|
|
|
return
|
|
|
}
|
|
|
- // 消除格子
|
|
|
+
|
|
|
gridEliminateList.forEach((gridData) => {
|
|
|
- if (gridData.gridNode) {
|
|
|
+ if (gridData.gridNode?.children[0]) {
|
|
|
+ const startPos = gridData.gridNode.getWorldPosition();
|
|
|
+
|
|
|
tween(gridData.gridNode.children[0])
|
|
|
.to(0.2, { scale: new Vec3(0.5, 0.5) })
|
|
|
.call(() => {
|
|
|
@@ -1124,13 +1124,26 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.generateGrid(gridData)
|
|
|
})
|
|
|
.start()
|
|
|
+
|
|
|
+ if (this.coinPrefab && this.amountLb?.node) {
|
|
|
+ this.createCoinFlyAnimation(
|
|
|
+ this.coinPrefab,
|
|
|
+ startPos,
|
|
|
+ this.amountLb.node.getWorldPosition(),
|
|
|
+ 5
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //增加红包
|
|
|
+ this.createCoinFlyAnimation(
|
|
|
+ this.redPacketPrefab,
|
|
|
+ startPos,
|
|
|
+ this.awardLb.node.getWorldPosition(),
|
|
|
+ 5
|
|
|
+ );
|
|
|
}
|
|
|
})
|
|
|
- // 音效
|
|
|
- // this.audioManager.playEliminate()
|
|
|
|
|
|
this.scheduleOnce(() => {
|
|
|
- // 成绩
|
|
|
let score = 0
|
|
|
for (let i = 1; i <= eliminateRowNum; i++) {
|
|
|
score += this.max_col * i
|
|
|
@@ -1139,6 +1152,18 @@ export class EliminateViewComp extends CCComp {
|
|
|
score += this.max_row * i
|
|
|
}
|
|
|
this.score += score
|
|
|
+
|
|
|
+ const lastGrid = gridEliminateList[gridEliminateList.length - 1];
|
|
|
+ if (lastGrid?.gridNode && this.coinPrefab && this.amountLb?.node) {
|
|
|
+ const lastPos = lastGrid.gridNode.getWorldPosition();
|
|
|
+ this.createCoinFlyAnimation(
|
|
|
+ this.coinPrefab,
|
|
|
+ lastPos,
|
|
|
+ this.amountLb.node.getWorldPosition(),
|
|
|
+ score
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
resolve(true)
|
|
|
}, 0.2)
|
|
|
})
|
|
|
@@ -1526,9 +1551,36 @@ export class EliminateViewComp extends CCComp {
|
|
|
private btn_reopen() {
|
|
|
console.log("重新开始");
|
|
|
if (this.game_status === GameStatus.None) return
|
|
|
- this.initGameData()
|
|
|
+ this.initGameData();
|
|
|
+ this.reopenGrid();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private reopenGrid() {
|
|
|
+ for (let rowIndex = 0; rowIndex < this.max_row; rowIndex++) {
|
|
|
+ for (let columnIndex = 0; columnIndex < this.max_col; columnIndex++) {
|
|
|
+ this.gridList[rowIndex][columnIndex].status = GridStatus.NotUse
|
|
|
+ this.generateGrid(this.gridList[rowIndex][columnIndex])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 初始化方块
|
|
|
+ if (this.itemNode) {
|
|
|
+ if (this.itemNode) {
|
|
|
+ this.itemNode.children.forEach(node => { node.destroy() });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.bricksList.length = 0
|
|
|
+ for (let i = 1; i <= this.brickNum; i++) {
|
|
|
+ this.addBrick(i)
|
|
|
+ }
|
|
|
+ // 清除旋转数据
|
|
|
+ if (this.rotateNode) {
|
|
|
+ this.rotateNode.children.forEach(node => { node.destroy() })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// ... 添加自动模式的开关方法
|
|
|
onAutoButtonClick() {
|
|
|
if (
|
|
|
@@ -1582,4 +1634,70 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ // 修改 createCoinFlyAnimation 方法为公共方法,扩展参数列表
|
|
|
+ public createCoinFlyAnimation(prefab: Prefab, startPos: Vec3, endPos: Vec3, score: number, parent: Node = this.node) {
|
|
|
+ const coinNum = Math.min(Math.max(Math.floor(score / 10), 1), 10);
|
|
|
+
|
|
|
+ for (let i = 0; i < coinNum; i++) {
|
|
|
+ if (!prefab) {
|
|
|
+ console.warn('金币预制体未加载');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const coin = instantiate(prefab);
|
|
|
+ parent.addChild(coin);
|
|
|
+
|
|
|
+ const randomOffset = new Vec3(
|
|
|
+ (Math.random() - 0.5) * 50,
|
|
|
+ (Math.random() - 0.5) * 50,
|
|
|
+ 0
|
|
|
+ );
|
|
|
+ const startPosition = startPos.clone().add(randomOffset);
|
|
|
+ coin.setWorldPosition(startPosition);
|
|
|
+
|
|
|
+ const controlPoint = new Vec3(
|
|
|
+ (startPosition.x + endPos.x) / 2 + (Math.random() - 0.5) * 100,
|
|
|
+ (startPosition.y + endPos.y) / 2 + Math.random() * 100,
|
|
|
+ 0
|
|
|
+ );
|
|
|
+
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ tween(coin)
|
|
|
+ .parallel(
|
|
|
+ tween().to(0.2, { scale: new Vec3(1.2, 1.2, 1.2) })
|
|
|
+ .to(0.1, { scale: new Vec3(1, 1, 1) }),
|
|
|
+ tween().by(0.3, { angle: 360 })
|
|
|
+ )
|
|
|
+ .start();
|
|
|
+
|
|
|
+ const bezierCurve = (target: Node | undefined, ratio?: number) => {
|
|
|
+ if (!target || ratio === undefined) return;
|
|
|
+ const t = ratio;
|
|
|
+ const pos = new Vec3();
|
|
|
+ Vec3.multiplyScalar(pos, startPosition, (1 - t) * (1 - t));
|
|
|
+ Vec3.scaleAndAdd(pos, pos, controlPoint, 2 * (1 - t) * t);
|
|
|
+ Vec3.scaleAndAdd(pos, pos, endPos, t * t);
|
|
|
+ target.setWorldPosition(pos);
|
|
|
+ };
|
|
|
+
|
|
|
+ tween(coin)
|
|
|
+ .to(0.8, {
|
|
|
+ worldPosition: endPos
|
|
|
+ }, {
|
|
|
+ easing: 'cubicIn',
|
|
|
+ onUpdate: bezierCurve
|
|
|
+ })
|
|
|
+ .call(() => {
|
|
|
+ tween(coin)
|
|
|
+ .to(0.1, { scale: new Vec3(0.7, 0.7, 0.7) })
|
|
|
+ .call(() => {
|
|
|
+ coin.destroy();
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ })
|
|
|
+ .start();
|
|
|
+ }, i * 0.1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|