Quellcode durchsuchen

增加了消除的时候的红包飞动画

mojunshou vor 8 Monaten
Ursprung
Commit
769b603644

+ 13 - 3
assets/bundle/gui/eliminate/eliminate.prefab

@@ -670,7 +670,7 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -154.493,
+      "x": -152.613,
       "y": 13.92,
       "z": 0
     },
@@ -784,7 +784,7 @@
     },
     "clickEvents": [],
     "_interactable": true,
-    "_transition": 2,
+    "_transition": 3,
     "_normalColor": {
       "__type__": "cc.Color",
       "r": 214,
@@ -1291,7 +1291,7 @@
     },
     "clickEvents": [],
     "_interactable": true,
-    "_transition": 2,
+    "_transition": 3,
     "_normalColor": {
       "__type__": "cc.Color",
       "r": 214,
@@ -5190,6 +5190,8 @@
       "__id__": 0
     },
     "fileId": "8b45hrbuhCgK4UTM5Fgs0h",
+    "instance": null,
+    "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {
@@ -6051,6 +6053,14 @@
     "awardLb": {
       "__id__": 39
     },
+    "coinPrefab": {
+      "__uuid__": "ab632405-8b7d-44f0-947d-bf46c1831fe7",
+      "__expectedType__": "cc.Prefab"
+    },
+    "redPacketPrefab": {
+      "__uuid__": "e7074ca1-499a-49b0-827b-15bfeb5af0eb",
+      "__expectedType__": "cc.Prefab"
+    },
     "_id": ""
   },
   {

+ 147 - 0
assets/bundle/gui/eliminate/prefabs/Coin.prefab

@@ -0,0 +1,147 @@
+[
+  {
+    "__type__": "cc.Prefab",
+    "_name": "Coin",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_native": "",
+    "data": {
+      "__id__": 1
+    },
+    "optimizationPolicy": 0,
+    "persistent": false
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "Coin",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_parent": null,
+    "_children": [],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 2
+      },
+      {
+        "__id__": 4
+      }
+    ],
+    "_prefab": {
+      "__id__": 6
+    },
+    "_lpos": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_lrot": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0,
+      "w": 1
+    },
+    "_lscale": {
+      "__type__": "cc.Vec3",
+      "x": 1,
+      "y": 1,
+      "z": 1
+    },
+    "_mobility": 0,
+    "_layer": 33554432,
+    "_euler": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.UITransform",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 3
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 45,
+      "height": 47
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "48L+9Xk6lMEY/gZiwwwtR4"
+  },
+  {
+    "__type__": "cc.Sprite",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 5
+    },
+    "_customMaterial": null,
+    "_srcBlendFactor": 2,
+    "_dstBlendFactor": 4,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_spriteFrame": {
+      "__uuid__": "851b0014-569f-4d9d-a6be-0d0f4d4b0d29@f9941",
+      "__expectedType__": "cc.SpriteFrame"
+    },
+    "_type": 0,
+    "_fillType": 0,
+    "_sizeMode": 1,
+    "_fillCenter": {
+      "__type__": "cc.Vec2",
+      "x": 0,
+      "y": 0
+    },
+    "_fillStart": 0,
+    "_fillRange": 0,
+    "_isTrimmedMode": true,
+    "_useGrayscale": false,
+    "_atlas": null,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "ebN7KWPi5EHbt91bzF05pY"
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__id__": 0
+    },
+    "fileId": "c46/YsCPVOJYA4mWEpNYRx",
+    "instance": null,
+    "targetOverrides": null
+  }
+]

+ 13 - 0
assets/bundle/gui/eliminate/prefabs/Coin.prefab.meta

@@ -0,0 +1,13 @@
+{
+  "ver": "1.1.50",
+  "importer": "prefab",
+  "imported": true,
+  "uuid": "ab632405-8b7d-44f0-947d-bf46c1831fe7",
+  "files": [
+    ".json"
+  ],
+  "subMetas": {},
+  "userData": {
+    "syncNodeName": "Coin"
+  }
+}

+ 147 - 0
assets/bundle/gui/eliminate/prefabs/RedPacket.prefab

@@ -0,0 +1,147 @@
+[
+  {
+    "__type__": "cc.Prefab",
+    "_name": "RedPacket",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_native": "",
+    "data": {
+      "__id__": 1
+    },
+    "optimizationPolicy": 0,
+    "persistent": false
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "RedPacket",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_parent": null,
+    "_children": [],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 2
+      },
+      {
+        "__id__": 4
+      }
+    ],
+    "_prefab": {
+      "__id__": 6
+    },
+    "_lpos": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_lrot": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0,
+      "w": 1
+    },
+    "_lscale": {
+      "__type__": "cc.Vec3",
+      "x": 1,
+      "y": 1,
+      "z": 1
+    },
+    "_mobility": 0,
+    "_layer": 33554432,
+    "_euler": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.UITransform",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 3
+    },
+    "_contentSize": {
+      "__type__": "cc.Size",
+      "width": 40,
+      "height": 49
+    },
+    "_anchorPoint": {
+      "__type__": "cc.Vec2",
+      "x": 0.5,
+      "y": 0.5
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "14tTjdyTBPA5TZMBo9evIm"
+  },
+  {
+    "__type__": "cc.Sprite",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 5
+    },
+    "_customMaterial": null,
+    "_srcBlendFactor": 2,
+    "_dstBlendFactor": 4,
+    "_color": {
+      "__type__": "cc.Color",
+      "r": 255,
+      "g": 255,
+      "b": 255,
+      "a": 255
+    },
+    "_spriteFrame": {
+      "__uuid__": "b26678f8-846f-4447-bd57-0659cca862e1@f9941",
+      "__expectedType__": "cc.SpriteFrame"
+    },
+    "_type": 0,
+    "_fillType": 0,
+    "_sizeMode": 1,
+    "_fillCenter": {
+      "__type__": "cc.Vec2",
+      "x": 0,
+      "y": 0
+    },
+    "_fillStart": 0,
+    "_fillRange": 0,
+    "_isTrimmedMode": true,
+    "_useGrayscale": false,
+    "_atlas": null,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "5eLEQrjGRGt7oH7Xmxin5M"
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__id__": 0
+    },
+    "fileId": "c46/YsCPVOJYA4mWEpNYRx",
+    "instance": null,
+    "targetOverrides": null
+  }
+]

+ 13 - 0
assets/bundle/gui/eliminate/prefabs/RedPacket.prefab.meta

@@ -0,0 +1,13 @@
+{
+  "ver": "1.1.50",
+  "importer": "prefab",
+  "imported": true,
+  "uuid": "e7074ca1-499a-49b0-827b-15bfeb5af0eb",
+  "files": [
+    ".json"
+  ],
+  "subMetas": {},
+  "userData": {
+    "syncNodeName": "RedPacket"
+  }
+}

+ 139 - 21
assets/script/game/eliminate/view/EliminateViewComp.ts

@@ -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);
+        }
+    }
 }