Jelajahi Sumber

【功能】增加2倍数快速消除

mojunshou 8 bulan lalu
induk
melakukan
f8d541544a

+ 1 - 0
assets/script/game/eliminate/view/DoubleSpeedViewComp.ts

@@ -62,6 +62,7 @@ export class DoubleSpeedViewComp extends CCComp {
     private btn_open() {
         this.openAd();
         oops.gui.remove(UIID.DoubleSpeed);
+
     }
 
 

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

@@ -2,7 +2,7 @@
  * @Author: mojunshou 1637302775@qq.com
  * @Date: 2025-03-20 15:01:09
  * @LastEditors: mojunshou 1637302775@qq.com
- * @LastEditTime: 2025-04-02 17:55:03
+ * @LastEditTime: 2025-04-02 19:24:30
  * @Description: 消除游戏主场景
  */
 import { _decorator, Color, EventTouch, instantiate, JsonAsset, Label, Node, Prefab, randomRangeInt, Sprite, Toggle, tween, UITransform, Vec2, Vec3, Widget } from "cc";
@@ -158,6 +158,7 @@ export class EliminateViewComp extends CCComp {
     private totalNum: number = 0;   //累计消除次数,断了就是又从0开始
 
     private _isDoubleSpeed: boolean = false;  //是否开启二倍速
+    private _doubleNum: number = 2;           //除2就是开启了2倍速,除1就是关闭了2倍速
 
     //网格列表
     // gridsNode: Node | null = null;          //中间网格区域
@@ -200,7 +201,6 @@ export class EliminateViewComp extends CCComp {
 
     // 添加新的属性来跟踪是否需要重置消除计数
     private shouldResetEliminateCount: boolean = true;
-    private consecutiveEliminations: boolean = false;
 
     // 添加配置属性 - 消除基础分
     @property({ displayName: "消除一行/列基础分" })
@@ -264,9 +264,9 @@ export class EliminateViewComp extends CCComp {
         this.money = 0;
         this.cash = 0;
         this.totalNum = 0;
+        // this._doubleNum = 2;
         this.autoState = false;
         this.shouldResetEliminateCount = true;
-        this.consecutiveEliminations = false;
         this.lab_score.string = this.score.toString();
         this.amountLb.string = this.money.toString();
         this.awardLb.string = this.cash.toString();
@@ -771,7 +771,6 @@ export class EliminateViewComp extends CCComp {
 
                 // 标记需要重置消除计数器
                 this.shouldResetEliminateCount = true;
-                this.consecutiveEliminations = true;
 
                 // 销毁方块节点
                 brickNode.destroy();
@@ -915,13 +914,15 @@ export class EliminateViewComp extends CCComp {
         this.node.addChild(scoreLabel);
         scoreLabel.setWorldPosition(position);
 
+        const num = this._isDoubleSpeed ? this._doubleNum : 1;
+
         // 创建动画效果
         tween(scoreLabel)
-            .to(0.5, {
+            .to(0.5 / num, {
                 position: new Vec3(scoreLabel.position.x, scoreLabel.position.y + 50, 0),
                 scale: new Vec3(1.2, 1.2, 1.2)
             })
-            .to(0.3, { opacity: 0 })
+            .to(0.3 / num, { opacity: 0 })
             .call(() => {
                 scoreLabel.destroy();
             })
@@ -971,13 +972,15 @@ export class EliminateViewComp extends CCComp {
         totalLabel.setWorldPosition(centerPos);
 
         // 创建动画效果
+
+        const num = this._isDoubleSpeed ? this._doubleNum : 1;
         tween(totalLabel)
-            .to(0.3, {
+            .to(0.3 / num, {
                 scale: new Vec3(1.5, 1.5, 1.5),
                 opacity: 255
             })
-            .delay(0.5) // 停留更长时间
-            .to(0.4, {
+            .delay(0.5 / num) // 停留更长时间
+            .to(0.4 / num, {
                 scale: new Vec3(1.2, 1.2, 1.2),
                 position: new Vec3(totalLabel.position.x, totalLabel.position.y + 50, 0),
                 opacity: 0
@@ -999,7 +1002,6 @@ export class EliminateViewComp extends CCComp {
             if (gridEliminateList.length < 1) {
                 // 没有发生消除
                 this.shouldResetEliminateCount = true;  // 下一次消除需要重置计数
-                this.consecutiveEliminations = false;   // 不是连续消除
                 resolve(false);
                 return;
             }
@@ -1017,19 +1019,16 @@ export class EliminateViewComp extends CCComp {
                 }
                 // 计算平均Y位置
                 const avgY = validGrids > 0 ? totalY / validGrids : 0;
-
-                // 标记为连续消除
-                this.consecutiveEliminations = true;
-
                 // 显示消除次数动画,传入Y轴位置
                 this.showEliminateCountAnimation(avgY);
             }
 
+            const num = this._isDoubleSpeed ? this._doubleNum : 1;
             gridEliminateList.forEach((gridData) => {
                 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) })
+                        .to(0.2 / num, { scale: new Vec3(0.5, 0.5) })
                         .call(() => {
                             gridData.status = CellState.EMPTY
                             this.generateGrid(gridData)
@@ -1164,15 +1163,16 @@ export class EliminateViewComp extends CCComp {
             );
 
             // 创建曲线动画
+            const num = this._isDoubleSpeed ? this._doubleNum : 1;
             tween(coin)
-                .to(0.2, {
+                .to(0.2 / num, {
                     position: new Vec3(
                         coin.position.x + randomOffset.x,
                         coin.position.y + randomOffset.y,
                         0
                     )
                 })
-                .to(0.5, { worldPosition: endPos })
+                .to(0.5 / num, { worldPosition: endPos })
                 .call(() => {
                     coin.destroy();
                     completedCount++;
@@ -1254,8 +1254,9 @@ export class EliminateViewComp extends CCComp {
         this.tweenRedNode.active = true;
 
         // 创建向上移动的动画
+        const num = this._isDoubleSpeed ? this._doubleNum : 1;
         tween(this.tweenRedNode)
-            .to(0.8, {
+            .to(0.8 / num, {
                 position: new Vec3(
                     originalPosition.x,
                     originalPosition.y + 80,
@@ -1263,7 +1264,7 @@ export class EliminateViewComp extends CCComp {
                 ),
                 opacity: 255
             })
-            .to(0.2, { opacity: 0 })
+            .to(0.2 / num, { opacity: 0 })
             .call(() => {
                 // 重置位置
                 this.tweenRedNode.setPosition(originalPosition);
@@ -1506,6 +1507,7 @@ export class EliminateViewComp extends CCComp {
     private btn_auto() {
         //自动放置
         this.autoState = !this.autoState;
+        this._isDoubleSpeed = !this._isDoubleSpeed;
         this.initButtonState(this.autoState);
         if (this.autoState) {
             this.gameState = GameState.PLAYING;
@@ -1637,12 +1639,13 @@ export class EliminateViewComp extends CCComp {
         this.editingData.brickData = this.bricksList.splice(index, 1)[0]
 
         // 如果需要旋转,执行旋转
+        const num = this._isDoubleSpeed ? this._doubleNum : 1;
         if (brickData.deg !== placement.deg) {
             // 更新方块配置和角度
             brickData.gridConfig = placement.gridConfig
             brickData.deg = placement.deg
             // 添加旋转动画
-            tween(brickData.brickNode).to(0.1, { angle: placement.deg }).start()
+            tween(brickData.brickNode).to(0.2 / num, { angle: placement.deg }).start()
         }
 
         // 准备网格列表
@@ -1684,9 +1687,10 @@ export class EliminateViewComp extends CCComp {
         brickData.brickNode.setParent(this.moveNode)
         brickData.brickNode.setWorldPosition(originPos)
 
+
         // 使用动画移动到目标位置--这里的最终放置有问题
         tween(brickData.brickNode)
-            .to(2, { worldPosition: centerPos })
+            .to(2 / num, { worldPosition: centerPos })
             .call(() => {
                 // 动画完成后修改格子状态
                 this.editingData.gridList.forEach((gridData) => {