Selaa lähdekoodia

Merge branch 'dev' of http://git.trops-global.com/linxuxiang/tropsCode into dev

林旭祥 1 kuukausi sitten
vanhempi
commit
bb32c04399
1 muutettua tiedostoa jossa 134 lisäystä ja 0 poistoa
  1. 134 0
      src/views/game/football.vue

+ 134 - 0
src/views/game/football.vue

@@ -566,8 +566,142 @@ class GameScene extends Phaser.Scene {
     this.scoreText.setText(`分数: ${this.score}`);
     // 触发全局分数更新事件
     this.game.events.emit('scoreChanged', this.score);
+
+    // 每200分触发一次射门环节
+    if (this.score % 200 === 0 && this.score > 0 && !this.isShooting) {
+      this.enterShootingMode();
+    }
   }
 
+enterShootingMode() {
+  this.gameActive = false; // 暂停奔跑场景
+  this.isShooting = true;
+
+  // 清除现有障碍物
+  this.obstacles.forEach(obs => obs.destroy());
+  this.obstacles = [];
+
+  // 创建射门场景背景
+  this.background.setTexture('goalBackground');
+  
+  // 创建球门
+  this.goal = this.physics.add.sprite(GAME_WIDTH/2, 100, 'goal');
+  this.goal.setScale(0.8);
+  this.goal.setImmovable(true);
+  this.goal.setDepth(5);
+
+  // 创建守门员
+  this.goalkeeper = this.physics.add.sprite(GAME_WIDTH/2, 150, 'goalkeeperAnim');
+  this.goalkeeper.setScale(0.9);
+  this.goalkeeper.setImmovable(true);
+  this.goalkeeper.anims.play('goalkeeperAnim', true);
+  this.goalkeeper.setDepth(6);
+
+  // 让守门员左右移动
+  this.tweens.add({
+    targets: this.goalkeeper,
+    x: [GAME_WIDTH/2 - 50, GAME_WIDTH/2 + 50],
+    duration: 2000,
+    ease: 'Sine.inOut',
+    repeat: -1,
+    yoyo: true
+  });
+
+  // 调整球员位置(准备射门)
+  this.player.setPosition(GAME_WIDTH/2, GAME_HEIGHT - 100);
+  this.player.setTexture('playerShoot');
+
+  // 创建足球
+  this.ball = this.physics.add.sprite(GAME_WIDTH/2, GAME_HEIGHT - 150, 'ballAnim');
+  this.ball.setScale(0.8);
+  this.ball.anims.play('ballAnim', true);
+  this.ball.setDepth(7);
+
+  // 射门控制(空格键或触摸)
+  this.input.keyboard.on('keydown-SPACE', this.shootBall, this);
+  this.input.on('pointerdown', this.shootBall, this);
+}
+
+shootBall() {
+  if (!this.isShooting) return;
+
+  // 移除射门输入监听(防止重复射门)
+  this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
+  this.input.off('pointerdown', this.shootBall, this);
+
+  // 足球飞行动画
+  this.tweens.add({
+    targets: this.ball,
+    y: -50, // 飞向球门
+    duration: 1000,
+    ease: 'Power1',
+    onUpdate: () => {
+      // 检测射门结果(碰撞检测)
+      if (Phaser.Geom.Intersects.RectangleToRectangle(
+        this.ball.getBounds(), 
+        this.goalkeeper.getBounds()
+      )) {
+        // 被守门员挡住
+        this.ball.setTint(0xff0000); // 变红
+        this.failShoot();
+      } else if (Phaser.Geom.Intersects.RectangleToRectangle(
+        this.ball.getBounds(), 
+        this.goal.getBounds()
+      )) {
+        // 射入球门
+        this.score += 3; // 射门得分
+        this.updateScore();
+        this.successShoot();
+      }
+    }
+  });
+}
+
+// 射门成功处理
+successShoot() {
+  this.isShooting = false;
+  this.add.text(GAME_WIDTH/2, GAME_HEIGHT/2, '射门成功!', {
+    fontSize: '24px',
+    fill: '#0f0'
+  }).setOrigin(0.5);
+
+  // 2秒后返回奔跑场景
+  setTimeout(() => {
+    this.resetToRunningScene();
+  }, 2000);
+}
+
+// 射门失败处理
+failShoot() {
+  this.isShooting = false;
+  this.add.text(GAME_WIDTH/2, GAME_HEIGHT/2, '射门失败!', {
+    fontSize: '24px',
+    fill: '#f00'
+  }).setOrigin(0.5);
+
+  // 2秒后返回奔跑场景
+  setTimeout(() => {
+    this.resetToRunningScene();
+  }, 2000);
+}
+
+// 重置为奔跑场景
+resetToRunningScene() {
+  // 清除射门场景元素
+  this.goal.destroy();
+  this.goalkeeper.destroy();
+  this.ball.destroy();
+  this.children.each(child => {
+    if (child.type === 'Text' && child.text.includes('射门')) child.destroy();
+  });
+
+  // 恢复奔跑场景
+  this.background.setTexture('grass');
+  this.player.setTexture('playerAnim');
+  this.gameActive = true;
+  this.startSpawning(); // 重新开始生成障碍物
+}
+
   gameOver() {
     this.gameActive = false;