林旭祥 1 settimana fa
parent
commit
64b85a1620
1 ha cambiato i file con 44 aggiunte e 4 eliminazioni
  1. 44 4
      src/views/game/fruit.vue

+ 44 - 4
src/views/game/fruit.vue

@@ -846,7 +846,7 @@ class PlayScene extends Phaser.Scene {
     this.blade = null;
     this.fruits = [];
     this.score = 0;
-    this.playing = true;
+    this.playing = false; // 改为false,在初始化方法中设置为true
     this.bombExplode = false;
     this.lostCount = 0;
     this.scoreImage = null;
@@ -880,9 +880,46 @@ class PlayScene extends Phaser.Scene {
     this.scoreTextAnim();
     this.bestAnim();
     this.xxxAnim();
+    
+    // 添加调试信息
+    console.log("PlayScene created");
+    
+    // 调用初始化方法,而不是直接开始生成水果
+    this.initGame();
+  }
+  
+  initGame() {
+    // 重置游戏状态
+    this.fruits = [];
+    this.score = 0;
+    this.lostCount = 0;
+    this.bombExplode = false;
+    this.scoreText.setText(this.score.toString());
+    
+    // 重置失去计数UI
+    if (this.xxxGroup) {
+      this.xxxGroup.removeAll(true);
+      this.x = this.add.image(0, 0, 'x');
+      this.xx = this.add.image(22, 0, 'xx');
+      this.xxx = this.add.image(49, 0, 'xxx');
+      this.xxxGroup.add([this.x, this.xx, this.xxx]);
+    }
+    
+    // 开始游戏
+    this.playing = true;
+    console.log("Game initialized and started");
+    
+    // 延迟一点时间再生成第一个水果,让玩家有准备
+    this.time.delayedCall(1000, () => {
+      this.startFruit();
+      console.log("First fruit spawned");
+    });
   }
 
   update() {
+    // 如果游戏未开始,不执行任何操作
+    if (!this.playing) return;
+    
     // 检查是否有水果出界
     if (!this.bombExplode) {
       for (let i = this.fruits.length - 1; i >= 0; i--) {
@@ -1173,11 +1210,14 @@ class PlayScene extends Phaser.Scene {
       duration: 300,
       ease: 'Sine.InOut'
     });
+    setTimeout(()=>{
+      this.scene.start('main');
+    },2000)
 
     // 点击重新开始
-    this.input.once('pointerup', () => {
-      this.scene.start('main');
-    });
+    // this.input.once('pointerup', () => {
+    //   this.scene.start('main');
+    // });
   }
 }