Browse Source

墙体血量

181404010226 2 months ago
parent
commit
2f1cc0f3ce

File diff suppressed because it is too large
+ 130 - 239
assets/Scenes/GameLevel.scene


+ 34 - 121
assets/scripts/CombatSystem/BlockSelection/GameBlockSelection.ts

@@ -76,13 +76,6 @@ export class GameBlockSelection extends Component {
     })
     public cameraNode: Node = null;
 
-    // 武器配置JsonAsset - 通过装饰器预加载
-    // @property({
-    //     type: JsonAsset,
-    //     tooltip: '拖拽weapons.json文件到这里,实现配置预加载'
-    // })
-    // public weaponsConfig: JsonAsset = null;
-    
     // 武器配置数据,通过 BundleLoader 异步加载
     private weaponsConfigData: any = null;
 
@@ -168,7 +161,18 @@ export class GameBlockSelection extends Component {
     private getAddBallCost(): number {
         // 优先从JSON配置中获取价格
         if (this.ballPriceConfigData && this.ballPriceConfigData.addBallPricing) {
-            return this.ballPriceConfigData.addBallPricing.initialPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
+            const config = this.ballPriceConfigData.addBallPricing;
+            const basePrice = config.initialPrice || this.DEFAULT_ADD_BALL_BASE_PRICE;
+            const increment = config.priceIncrement || this.DEFAULT_ADD_BALL_INCREMENT;
+            const maxPrice = config.maxPrice || this.DEFAULT_ADD_BALL_MAX_PRICE;
+            
+            // 获取当前使用次数
+            const session = this.session || LevelSessionManager.inst;
+            const usageCount = session ? session.getAddBallUsageCount() : 0;
+            
+            // 计算当前价格
+            const currentPrice = Math.min(basePrice + (usageCount * increment), maxPrice);
+            return currentPrice;
         }
         
         // 其次从装饰器绑定的节点获取价格
@@ -200,7 +204,18 @@ export class GameBlockSelection extends Component {
         // 优先从JSON配置中获取价格
         console.log('[GameBlockSelection] 刷新方块价格配置:', this.ballPriceConfigData?.refreshBlockPricing);
         if (this.ballPriceConfigData && this.ballPriceConfigData.refreshBlockPricing) {
-            return this.ballPriceConfigData.refreshBlockPricing.initialPrice || this.DEFAULT_REFRESH_BASE_PRICE;
+            const config = this.ballPriceConfigData.refreshBlockPricing;
+            const basePrice = config.initialPrice || this.DEFAULT_REFRESH_BASE_PRICE;
+            const increment = config.priceIncrement || this.DEFAULT_REFRESH_INCREMENT;
+            const maxPrice = config.maxPrice || this.DEFAULT_REFRESH_MAX_PRICE;
+            
+            // 获取当前使用次数
+            const session = this.session || LevelSessionManager.inst;
+            const usageCount = session ? session.getRefreshUsageCount() : 0;
+            
+            // 计算当前价格
+            const currentPrice = Math.min(basePrice + (usageCount * increment), maxPrice);
+            return currentPrice;
         }
         
         // 其次从装饰器绑定的节点获取价格
@@ -461,8 +476,8 @@ export class GameBlockSelection extends Component {
             
             this.updateCoinDisplay();
             
-            // 更新价格配置(增加购买次数和价格)
-            this.updateAddBallPrice();
+            // 更新价格显示
+            this.updatePriceDisplay();
             
             // 通过事件系统创建新的小球
             const eventBus = EventBus.getInstance();
@@ -518,8 +533,8 @@ export class GameBlockSelection extends Component {
             // 成功扣除金币
             this.updateCoinDisplay();
             
-            // 更新价格配置(增加购买次数和价格)
-            this.updateRefreshPrice();
+            // 更新价格显示
+            this.updatePriceDisplay();
             
             // 刷新方块
             if (this.blockManager) {
@@ -725,8 +740,8 @@ export class GameBlockSelection extends Component {
         // 清理所有方块标签
         BlockTag.clearAllTags();
         
-        // 重置价格历史数据(局内数据,每局重置)
-        this.resetPriceHistory();
+        // 更新价格显示(使用次数已在session中重置)
+        this.updatePriceDisplay();
     
         // 更新金币显示
         this.updateCoinDisplay();
@@ -1382,89 +1397,13 @@ export class GameBlockSelection extends Component {
     
     // === 价格配置管理方法 ===
     
-    // 获取价格配置数据(如果装饰器配置不存在则返回默认值)
-    private getPriceConfigData(): any {
-        if (this.ballPriceConfigData && this.ballPriceConfigData.json) {
-            return this.ballPriceConfigData.json;
-        }
-        
-        // 返回默认配置
-        return {
-            addBallPricing: {
-                initialPrice: this.DEFAULT_ADD_BALL_BASE_PRICE,
-                priceIncrement: this.DEFAULT_ADD_BALL_INCREMENT,
-                maxPrice: this.DEFAULT_ADD_BALL_MAX_PRICE
-            },
-            refreshBlockPricing: {
-                initialPrice: this.DEFAULT_REFRESH_BASE_PRICE,
-                priceIncrement: this.DEFAULT_REFRESH_INCREMENT,
-                maxPrice: this.DEFAULT_REFRESH_MAX_PRICE
-            },
-            priceHistory: {
-                addBallCurrentPrice: this.DEFAULT_ADD_BALL_BASE_PRICE,
-                refreshBlockCurrentPrice: this.DEFAULT_REFRESH_BASE_PRICE,
-                addBallPurchaseCount: 0,
-                refreshBlockPurchaseCount: 0
-            }
-        };
-    }
-    
-    // 更新新增小球价格
-    private updateAddBallPrice() {
-        const configData = this.getPriceConfigData();
-        const config = configData.addBallPricing;
-        const history = configData.priceHistory;
-        
-        // 增加购买次数(局内数据,每局会重置)
-        history.addBallPurchaseCount++;
-        
-        // 计算新价格(随购买次数增加,但有上限)
-        const newPrice = Math.min(
-            config.initialPrice + (history.addBallPurchaseCount * config.priceIncrement),
-            config.maxPrice
-        );
-        
-        history.addBallCurrentPrice = newPrice;
-        
-        // 更新UI显示
-        this.updatePriceDisplay();
-        
-        // 保存配置(注意:装饰器配置是只读的,这里只是打印日志)
-        this.saveBallPriceConfig();
-        
-        console.log(`[GameBlockSelection] 新增小球价格更新: ${newPrice}, 购买次数: ${history.addBallPurchaseCount}`);
-    }
-    
-    // 更新刷新方块价格
-    private updateRefreshPrice() {
-        const configData = this.getPriceConfigData();
-        const config = configData.refreshBlockPricing;
-        const history = configData.priceHistory;
-        
-        // 增加购买次数
-        history.refreshBlockPurchaseCount++;
-        
-        // 计算新价格
-        const newPrice = Math.min(
-            config.initialPrice + (history.refreshBlockPurchaseCount * config.priceIncrement),
-            config.maxPrice
-        );
-        
-        history.refreshBlockCurrentPrice = newPrice;
-        
-        // 更新UI显示
-        this.updatePriceDisplay();
-        
-        // 保存配置(注意:装饰器配置是只读的,这里只是打印日志)
-        this.saveBallPriceConfig();
-        
-        console.log(`[GameBlockSelection] 刷新方块价格更新: ${newPrice}, 购买次数: ${history.refreshBlockPurchaseCount}`);
-    }
+
     
     // 更新价格显示
     private updatePriceDisplay() {
         // 更新新增小球价格显示 - 使用装饰器绑定的节点
         if (this.addBallPriceNode) {
+            console.log(`[GameBlockSelection] 更新新增小球价格显示: ${this.getAddBallCost()}`);
             const label = this.addBallPriceNode.getComponent(Label);
             if (label) {
                 label.string = this.getAddBallCost().toString();
@@ -1482,6 +1421,7 @@ export class GameBlockSelection extends Component {
         
         // 更新刷新方块价格显示 - 使用装饰器绑定的节点
         if (this.refreshBlockPriceNode) {
+            console.log(`[GameBlockSelection] 更新刷新方块价格显示: ${this.getRefreshCost()}`);
             const label = this.refreshBlockPriceNode.getComponent(Label);
             if (label) {
                 label.string = this.getRefreshCost().toString();
@@ -1522,32 +1462,5 @@ export class GameBlockSelection extends Component {
         }
     }
     
-    // 保存价格配置(装饰器配置是只读的,这里只是打印日志用于调试)
-    private saveBallPriceConfig() {
-        const configData = this.getPriceConfigData();
-        // 装饰器预加载的配置是只读的,无法直接修改
-        // 在实际项目中,价格变化应该保存到本地存储或服务器
-        console.log('[GameBlockSelection] 价格配置已更新:', JSON.stringify(configData, null, 2));
-    }
-    
-    // 重置价格历史数据(每局开始时调用)
-    private resetPriceHistory() {
-        const configData = this.getPriceConfigData();
-        const config = configData.addBallPricing;
-        const refreshConfig = configData.refreshBlockPricing;
-        const history = configData.priceHistory;
-        
-        // 重置购买次数
-        history.addBallPurchaseCount = 0;
-        history.refreshBlockPurchaseCount = 0;
-        
-        // 重置价格为初始价格
-        history.addBallCurrentPrice = config.initialPrice;
-        history.refreshBlockCurrentPrice = refreshConfig.initialPrice;
-        
-        // 更新UI显示
-        this.updatePriceDisplay();
-        
-        console.log('[GameBlockSelection] 价格历史数据已重置到初始状态');
-    }
+
 }

+ 99 - 9
assets/scripts/CombatSystem/Wall.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node, Label, find, JsonAsset, Collider2D, RigidBody2D, ERigidBody2DType, BoxCollider2D } from 'cc';
+import { _decorator, Component, Node, Label, find, JsonAsset, Collider2D, RigidBody2D, ERigidBody2DType, BoxCollider2D, Tween, tween, Vec3, Color } from 'cc';
 import { SaveDataManager } from '../LevelSystem/SaveDataManager';
 import EventBus, { GameEvents } from '../Core/EventBus';
 import { JsonConfigLoader } from '../Core/JsonConfigLoader';
@@ -19,12 +19,6 @@ export class Wall extends Component {
     })
     public heartLabelNode: Node = null;
 
-    // @property({
-    //     type: JsonAsset,
-    //     tooltip: '墙体配置文件'
-    // })
-    // public wallConfigAsset: JsonAsset = null;  // 已改为动态加载
-
     // === 私有属性 ===
     private currentHealth: number = 100;
     private heartLabel: Label = null;
@@ -33,6 +27,11 @@ export class Wall extends Component {
     // 墙体配置数据
     private wallConfig: any = null;
     private wallHpMap: Record<number, number> = {};
+    
+    // 动画相关属性
+    private originalLabelColor: Color = null;
+    private damageAnimationTween: Tween<Node> = null;
+    private colorAnimationTween: Tween<Label> = null;
 
     async start() {
         await this.initializeWall();
@@ -153,6 +152,10 @@ export class Wall extends Component {
         
         if (this.heartLabelNode) {
             this.heartLabel = this.heartLabelNode.getComponent(Label);
+            // 保存原始颜色
+            if (this.heartLabel && !this.originalLabelColor) {
+                this.originalLabelColor = this.heartLabel.color.clone();
+            }
         }
     }
 
@@ -198,6 +201,9 @@ export class Wall extends Component {
         // 更新血量显示
         this.updateHealthDisplay();
         
+        // 播放受伤动画效果
+        this.playDamageAnimation();
+        
         console.log(`[Wall] 墙体受到伤害: ${damage}, 当前血量: ${this.currentHealth}`);
         
         // 检查墙体是否被摧毁
@@ -233,6 +239,89 @@ export class Wall extends Component {
             this.heartLabel.string = Math.floor(this.currentHealth).toString();
         }
     }
+    
+    /**
+     * 播放受伤动画效果
+     * 字体变红并伴随缩放动画(先放大后缩回原来的大小)
+     */
+    private playDamageAnimation(): void {
+        if (!this.heartLabelNode || !this.heartLabel) {
+            return;
+        }
+        
+        // 停止之前的动画,防止动画冲突
+        this.stopDamageAnimation();
+        
+        // 重置到原始状态
+        this.heartLabelNode.setScale(Vec3.ONE);
+        if (this.originalLabelColor) {
+            this.heartLabel.color = this.originalLabelColor.clone();
+        }
+        
+        // 创建缩放动画:放大到1.3倍再缩小回原始大小
+        this.damageAnimationTween = tween(this.heartLabelNode)
+            .to(0.15, { scale: new Vec3(1.3, 1.3, 1) }, {
+                easing: 'sineOut'
+            })
+            .to(0.15, { scale: Vec3.ONE }, {
+                easing: 'sineIn'
+            })
+            .call(() => {
+                this.damageAnimationTween = null;
+            });
+        
+        // 创建颜色动画:变红后逐渐恢复原色
+        if (this.originalLabelColor) {
+            const redColor = Color.RED.clone();
+            this.colorAnimationTween = tween(this.heartLabel)
+                .to(0.1, { color: redColor }, {
+                    easing: 'sineOut'
+                })
+                .delay(0.2) // 保持红色一段时间
+                .to(0.5, { color: this.originalLabelColor }, {
+                    easing: 'sineIn'
+                })
+                .call(() => {
+                    this.colorAnimationTween = null;
+                });
+        }
+        
+        // 启动动画
+        if (this.damageAnimationTween) {
+            this.damageAnimationTween.start();
+        }
+        if (this.colorAnimationTween) {
+            this.colorAnimationTween.start();
+        }
+        
+        console.log('[Wall] 播放受伤动画效果');
+    }
+    
+    /**
+     * 停止受伤动画
+     */
+    private stopDamageAnimation(): void {
+        if (this.damageAnimationTween) {
+            this.damageAnimationTween.stop();
+            this.damageAnimationTween = null;
+        }
+        
+        if (this.colorAnimationTween) {
+            this.colorAnimationTween.stop();
+            this.colorAnimationTween = null;
+        }
+        
+        // 恢复原始状态
+        if (this.heartLabelNode) {
+            Tween.stopAllByTarget(this.heartLabelNode);
+            this.heartLabelNode.setScale(Vec3.ONE);
+        }
+        
+        if (this.heartLabel && this.originalLabelColor) {
+            Tween.stopAllByTarget(this.heartLabel);
+            this.heartLabel.color = this.originalLabelColor.clone();
+        }
+    }
 
     /**
      * 设置墙体血量
@@ -294,8 +383,6 @@ export class Wall extends Component {
         return this.saveDataManager?.getWallLevel() || 1;
     }
 
-
-
     /**
      * 恢复墙体血量
      */
@@ -417,5 +504,8 @@ export class Wall extends Component {
         eventBus.off(GameEvents.WALL_HEALTH_CHANGED, this.onWallHealthChangedEvent, this);
         
         this.cleanupSkillListeners();
+        
+        // 清理动画资源
+        this.stopDamageAnimation();
     }
 }

+ 7 - 7
assets/scripts/Core/PhysicsManager.ts

@@ -23,13 +23,13 @@ export class PhysicsManager extends BaseSingleton {
         PhysicsSystem2D.instance.gravity = new Vec2(0, 0);
         
         // 调试绘制
-        PhysicsSystem2D.instance.debugDrawFlags = this.debugDraw ?
-            (EPhysics2DDrawFlags.Aabb |
-             EPhysics2DDrawFlags.Pair |
-             EPhysics2DDrawFlags.CenterOfMass |
-             EPhysics2DDrawFlags.Joint |
-             EPhysics2DDrawFlags.Shape) :
-            EPhysics2DDrawFlags.None;
+        // PhysicsSystem2D.instance.debugDrawFlags = this.debugDraw ?
+        //     (EPhysics2DDrawFlags.Aabb |
+        //      EPhysics2DDrawFlags.Pair |
+        //      EPhysics2DDrawFlags.CenterOfMass |
+        //      EPhysics2DDrawFlags.Joint |
+        //      EPhysics2DDrawFlags.Shape) :
+        //     EPhysics2DDrawFlags.None;
     }
 
     /**

Some files were not shown because too many files changed in this diff