Explorar o código

倒计时完成 添加结算

woso_javan hai 2 meses
pai
achega
a6ae8cab4b

+ 1 - 1
assets/module_storm_sunder/Prefabs/UI/Result/UI_BattleResult.prefab

@@ -970,7 +970,7 @@
     },
     "_type": 0,
     "_fillType": 0,
-    "_sizeMode": 1,
+    "_sizeMode": 0,
     "_fillCenter": {
       "__type__": "cc.Vec2",
       "x": 0,

+ 2 - 1
assets/module_storm_sunder/Prefabs/UI/Result/UI_BattleResult_Impl.ts

@@ -7,6 +7,7 @@ import { Layout_BattleResult } from "./Layout_BattleResult";
 import { GtagMgr, GtagType } from "db://assets/core_tgx/base/GtagMgr";
 import { GameEvent } from "../../../Script/Enum/GameEvent";
 import { StormSunderAudioMgr } from "../../../Script/Manager/StormSunderAudioMgr";
+import { GameMgr } from "../../../Script/Manager/GameMgr";
 
 export class UI_BattleResult_Impl extends UI_BattleResult {
     timeoutIds: Array<number> = [];
@@ -21,7 +22,7 @@ export class UI_BattleResult_Impl extends UI_BattleResult {
     }
 
     protected onCreated(): void {
-        this.win = true
+        this.win = GameMgr.inst.isWin;
         const soundId = this.win ? 7 : 8;
         StormSunderAudioMgr.playOneShot(StormSunderAudioMgr.getMusicIdName(soundId), 1.0);
 

+ 0 - 4
assets/module_storm_sunder/RoosterStormSunder.ts

@@ -38,10 +38,6 @@ export class RoosterStormSunder extends Component {
     }
 
     private async onClickStart(): Promise<void> {
-        const homeUI = StormSunderGlobalInstance.instance.homeUI;
-        const battleUI = StormSunderGlobalInstance.instance.battleUI;
-        homeUI.active = false;
-        battleUI.active = true;
         GameUtil.delay(0.2);
         GameMgr.inst.startGame();
     }

+ 1 - 4
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts

@@ -17,8 +17,6 @@ export class PropMoveComponent extends PropComponent {
     private currentDirection: Vec3 = new Vec3();
     // 已移动距离
     private distanceMoved: number = 0;
-    // 是否正在移动
-    private isMoving: boolean = false;
 
     start() {
         super.start();
@@ -54,13 +52,12 @@ export class PropMoveComponent extends PropComponent {
 
         // 重置已移动距离
         this.distanceMoved = 0;
-        this.isMoving = true;
 
         // console.log(`改变移动方向: (${this.currentDirection.x}, ${this.currentDirection.z})`);
     }
 
     update(deltaTime: number) {
-        if (!this.isMoving || this.status === PropStatus.DIE) return;
+        if (this.status === PropStatus.DIE) return;
 
         // 计算当前帧移动距离
         const moveStep = this.moveSpeed * deltaTime;

+ 6 - 1
assets/module_storm_sunder/Script/Component/TornadoComponent.ts

@@ -72,7 +72,6 @@ export class TornadoComponent extends Component {
         this.attack = 20;
         this.speed = 50;
         this.nickName = '爸爸在此';
-        this.playerStatus = PlayerStatus.LIFE;
         this.ai = false;
 
         this.playerInfo = {
@@ -80,6 +79,8 @@ export class TornadoComponent extends Component {
             level: 1,
             exp: 0,
         }
+
+        this.changeStatus(PlayerStatus.LIFE);
     }
 
     protected registerEvent() {
@@ -205,6 +206,10 @@ export class TornadoComponent extends Component {
         this.currentExp = 0;
     }
 
+    private changeStatus(status: PlayerStatus) {
+        this.playerStatus = status;
+    }
+
     protected onDestroy(): void {
         this.unregisterEvent();
     }

+ 27 - 0
assets/module_storm_sunder/Script/Manager/GameMgr.ts

@@ -1,7 +1,10 @@
 /** 游戏管理器*/
 
+import { tgxUIMgr } from "db://assets/core_tgx/tgx";
+import { StormSunderGlobalInstance } from "../StormSunderGlobalInstance";
 import { PropMgr } from "./PropMgr";
 import { TimerMgr } from "./TimerMgr";
+import { UI_BattleResult } from "db://assets/scripts/UIDef";
 
 export class GameMgr {
     private static _instance: GameMgr;
@@ -15,9 +18,33 @@ export class GameMgr {
     //游戏状态
     public gameStatus: GameStatus = GameStatus.None;
 
+    //输赢状态
+    public isWin: boolean = true;
+
     //设置游戏状态
     public setGameStatus(status: GameStatus) {
         this.gameStatus = status;
+        this.updateGameStatusUI();
+    }
+
+    //游戏状态更新UI
+    public updateGameStatusUI() {
+        const homeUI = StormSunderGlobalInstance.instance.homeUI;
+        const battleUI = StormSunderGlobalInstance.instance.battleUI;
+
+        switch (this.gameStatus) {
+            case GameStatus.None:
+                homeUI.active = true;
+                battleUI.active = false;
+                break;
+            case GameStatus.Playing:
+                homeUI.active = false;
+                battleUI.active = true;
+                break;
+            case GameStatus.End:
+                tgxUIMgr.inst.showUI(UI_BattleResult);
+                break;
+        }
     }
 
     public static get inst(): GameMgr {

+ 10 - 1
assets/module_storm_sunder/Script/Manager/TimerMgr.ts

@@ -1,7 +1,8 @@
-import { assetManager, instantiate, Prefab, Node, UITransform, Vec3, Vec2, view, game, director, Scheduler } from "cc";
+import { assetManager, instantiate, Prefab, Node, UITransform, Vec3, Vec2, view, game, director, Scheduler, Label } from "cc";
 import { resLoader } from "db://assets/core_tgx/base/ResLoader";
 import { StormSunderGlobalInstance } from "../StormSunderGlobalInstance";
 import { PropMgr } from "./PropMgr"; // 假设PropMgr在同一个目录下
+import { GameMgr, GameStatus } from "./GameMgr";
 
 /** 时间管理器*/
 export class TimerMgr {
@@ -33,17 +34,25 @@ export class TimerMgr {
                 this.stopCountdown();
                 console.log("Countdown finished!");
             }
+            this.upateLbTime();
         }, 1000); // 每秒减少一次
 
         Scheduler.enableForTarget(this);
         director.getScheduler().schedule(this.update, this, 0);
     }
 
+    private upateLbTime() {
+        const battleUI = StormSunderGlobalInstance.instance.battleUI;
+        const lbTime = battleUI.getChildByName('LbTime')!;
+        lbTime.getComponent(Label).string = this.countDownTime.toString();
+    }
+
     // 停止倒计时
     private stopCountdown(): void {
         if (this.timerId) {
             clearInterval(this.timerId);
             this.timerId = 0;
+            GameMgr.inst.setGameStatus(GameStatus.End);
         }
     }