林旭祥 1 miesiąc temu
rodzic
commit
47c70d15e7
1 zmienionych plików z 92 dodań i 53 usunięć
  1. 92 53
      src/views/game/football.vue

+ 92 - 53
src/views/game/football.vue

@@ -82,7 +82,6 @@ const gameAssets = {
   images: [
     { key: 'gameStart', url: 'static/images/football/game_start.jpg' },
     { key: 'grass', url: 'static/images/football/Caopi.png' },
-    { key: 'player', url: 'static/images/football/Qiuyuan.png' },
     { key: 'playerShoot', url: 'static/images/football/QiuyuanShooting.png' },
     { key: 'pile', url: 'static/images/football/Pile.png' },
     { key: 'jersey', url: 'static/images/football/Jersey.png' },
@@ -239,14 +238,24 @@ class PreloaderScene extends Phaser.Scene {
     // 球员动画
     this.anims.create({
       key: 'playerLeft',
-      frames: this.anims.generateFrameNumbers('playerAnim', { start: 0, end: 3 }),
+      frames: [
+        { key: 'playerAnim', frame: 0 },
+        { key: 'playerAnim', frame: 2 },
+        { key: 'playerAnim', frame: 4 },
+        { key: 'playerAnim', frame: 6 }
+      ],
       frameRate: 10,
       repeat: -1
     });
 
     this.anims.create({
       key: 'playerRight',
-      frames: this.anims.generateFrameNumbers('playerAnim', { start: 4, end: 7 }),
+      frames: [
+        { key: 'playerAnim', frame: 1 },
+        { key: 'playerAnim', frame: 3 },
+        { key: 'playerAnim', frame: 5 },
+        { key: 'playerAnim', frame: 7 }
+      ],
       frameRate: 10,
       repeat: -1
     });
@@ -438,6 +447,9 @@ class GameScene extends Phaser.Scene {
       callback: () => { if (this.gameActive) this.spawnPowerUp('broom'); },
       loop: true
     });
+
+    // 新增:立即生成第一个障碍物,确保倒计时结束后立即出现
+    this.spawnObstacle();
   }
 
   spawnObstacle() {
@@ -829,28 +841,44 @@ class GameScene extends Phaser.Scene {
   update() {
     if (!this.gameActive) return;
 
-    // 背景滚动(添加存在性和活跃状态检查)
-    if (this.background && this.background.active) {
-      const scrollSpeed = this.speed * this.acceleration * 0.5; // 降低背景速度
-      this.background.tilePositionY -= scrollSpeed;
-    }
-
-    // 玩家移动逻辑(添加活跃状态检查)
+    // 玩家移动逻辑
     if (this.player && this.player.active && !this.isShooting) {
       if (this.cursors.left.isDown) {
-        this.player.setVelocityX(-200);
-        this.player.anims.play('playerLeft', true);
+        this.player.setVelocityX(-200);//速度
+        // 确保只播放左动画,且当前未播放时才切换
+        if (this.player.anims.currentAnim?.key !== 'playerLeft') {
+          this.player.anims.play('playerLeft', true);
+        }
       } else if (this.cursors.right.isDown) {
-        this.player.setVelocityX(200);
-        this.player.anims.play('playerRight', true);
+        this.player.setVelocityX(200);//速度
+        // 确保只播放右动画
+        if (this.player.anims.currentAnim?.key !== 'playerRight') {
+          this.player.anims.play('playerRight', true);
+        }
       } else if (this.cursors.up.isDown) {
-        this.player.setVelocityY(-150);
+        console.log("this.player.anims.currentAnim?.key", this.player.anims.currentAnim?.key)
+        this.player.setVelocityY(-200);
+        // 上下移动时保持当前左右动画(或根据需求调整)
+        if (this.player.anims.currentAnim?.key === 'playerLeft') {
+          this.player.anims.play('playerLeft', true);
+        } else if (this.player.anims.currentAnim?.key === 'playerRight') {
+          this.player.anims.play('playerRight', true);
+        } else {
+          this.player.anims.play('playerLeft', true);
+        }
       } else if (this.cursors.down.isDown) {
-        this.player.setVelocityY(150);
+        this.player.setVelocityY(200);
+        if (this.player.anims.currentAnim?.key === 'playerLeft') {
+          this.player.anims.play('playerLeft', true);
+        } else if (this.player.anims.currentAnim?.key === 'playerRight') {
+          this.player.anims.play('playerRight', true);
+        } else {
+          this.player.anims.play('playerLeft', true);
+        }
       } else {
         this.player.setVelocityX(0);
         this.player.setVelocityY(0);
-        this.player.anims.stop();
+        this.player.anims.stop();  // 停止动画
       }
     }
   }
@@ -1120,48 +1148,59 @@ onUnmounted(() => {
   justify-content: center;
   align-items: center;
 }
+
 .daojishi {
-    position: absolute;
-    width: 100%;
-    top: 0;
-    bottom: 0; display: none;
-    z-index: 11;
-    background: url(daojishu_bg.png) repeat left top;
-    background-size: 100%;
+  position: absolute;
+  width: 100%;
+  top: 0;
+  bottom: 0;
+  display: none;
+  z-index: 11;
+  background: url(daojishu_bg.png) repeat left top;
+  background-size: 100%;
 }
-.daojishiline{
-    width: 100%;
-    height: 95px;
-    position: absolute;
-    top: 109px;
-    left: 0;
-    background: #ffe400;
-    z-index: 1;
+
+.daojishiline {
+  width: 100%;
+  height: 95px;
+  position: absolute;
+  top: 109px;
+  left: 0;
+  background: #ffe400;
+  z-index: 1;
 }
-.daojishibox{
-    width: 180px;
-    height: 180px;
-    position: absolute;
-    left: 50%; top: 71px;
-    margin: 0 0 0 -90px;
-    background: url(daojishibox.png) no-repeat left top;
-    background-size: 100%;
-    z-index: 2;
+
+.daojishibox {
+  width: 180px;
+  height: 180px;
+  position: absolute;
+  left: 50%;
+  top: 71px;
+  margin: 0 0 0 -90px;
+  background: url(daojishibox.png) no-repeat left top;
+  background-size: 100%;
+  z-index: 2;
 }
+
 .daojishipangzi {
-    width: 111px;
-    height: 102px;
-    position: absolute;
-    left: 50%; bottom: 50px;
-    margin: 0 0 0 -55px;
-    background: url(daojishipangzi.png) no-repeat left top;
-    background-size: 100%;
-    z-index: -1;
+  width: 111px;
+  height: 102px;
+  position: absolute;
+  left: 50%;
+  bottom: 50px;
+  margin: 0 0 0 -55px;
+  background: url(daojishipangzi.png) no-repeat left top;
+  background-size: 100%;
+  z-index: -1;
 }
-.daojishinum{
-    width: 100%; text-align: center;
-    font-size: 80px; color: #FFFFFF;
-    padding: 70px 0 0 0; line-height: normal;
+
+.daojishinum {
+  width: 100%;
+  text-align: center;
+  font-size: 80px;
+  color: #FFFFFF;
+  padding: 70px 0 0 0;
+  line-height: normal;
 }
 
 @keyframes countDown {