Browse Source

解决弓箭

181404010226 2 months ago
parent
commit
0e866fbc92

BIN
assets/Animation/EnemyAni/005/arrow.png


+ 134 - 0
assets/Animation/EnemyAni/005/arrow.png.meta

@@ -0,0 +1,134 @@
+{
+  "ver": "1.0.27",
+  "importer": "image",
+  "imported": true,
+  "uuid": "cb557d70-78bb-44d4-9a11-1685a22fa310",
+  "files": [
+    ".json",
+    ".png"
+  ],
+  "subMetas": {
+    "6c48a": {
+      "importer": "texture",
+      "uuid": "cb557d70-78bb-44d4-9a11-1685a22fa310@6c48a",
+      "displayName": "arrow",
+      "id": "6c48a",
+      "name": "texture",
+      "userData": {
+        "wrapModeS": "clamp-to-edge",
+        "wrapModeT": "clamp-to-edge",
+        "imageUuidOrDatabaseUri": "cb557d70-78bb-44d4-9a11-1685a22fa310",
+        "isUuid": true,
+        "visible": false,
+        "minfilter": "linear",
+        "magfilter": "linear",
+        "mipfilter": "none",
+        "anisotropy": 0
+      },
+      "ver": "1.0.22",
+      "imported": true,
+      "files": [
+        ".json"
+      ],
+      "subMetas": {}
+    },
+    "f9941": {
+      "importer": "sprite-frame",
+      "uuid": "cb557d70-78bb-44d4-9a11-1685a22fa310@f9941",
+      "displayName": "arrow",
+      "id": "f9941",
+      "name": "spriteFrame",
+      "userData": {
+        "trimThreshold": 1,
+        "rotated": false,
+        "offsetX": 0,
+        "offsetY": 0,
+        "trimX": 0,
+        "trimY": 0,
+        "width": 70,
+        "height": 13,
+        "rawWidth": 70,
+        "rawHeight": 13,
+        "borderTop": 0,
+        "borderBottom": 0,
+        "borderLeft": 0,
+        "borderRight": 0,
+        "packable": true,
+        "pixelsToUnit": 100,
+        "pivotX": 0.5,
+        "pivotY": 0.5,
+        "meshType": 0,
+        "vertices": {
+          "rawPosition": [
+            -35,
+            -6.5,
+            0,
+            35,
+            -6.5,
+            0,
+            -35,
+            6.5,
+            0,
+            35,
+            6.5,
+            0
+          ],
+          "indexes": [
+            0,
+            1,
+            2,
+            2,
+            1,
+            3
+          ],
+          "uv": [
+            0,
+            13,
+            70,
+            13,
+            0,
+            0,
+            70,
+            0
+          ],
+          "nuv": [
+            0,
+            0,
+            1,
+            0,
+            0,
+            1,
+            1,
+            1
+          ],
+          "minPos": [
+            -35,
+            -6.5,
+            0
+          ],
+          "maxPos": [
+            35,
+            6.5,
+            0
+          ]
+        },
+        "isUuid": true,
+        "imageUuidOrDatabaseUri": "cb557d70-78bb-44d4-9a11-1685a22fa310@6c48a",
+        "atlasUuid": "",
+        "trimType": "auto"
+      },
+      "ver": "1.0.12",
+      "imported": true,
+      "files": [
+        ".json"
+      ],
+      "subMetas": {}
+    }
+  },
+  "userData": {
+    "type": "sprite-frame",
+    "hasAlpha": true,
+    "fixAlphaTransparencyArtifacts": false,
+    "redirect": "cb557d70-78bb-44d4-9a11-1685a22fa310@6c48a"
+  }
+}

+ 29 - 29
assets/Scenes/GameLevel.scene

@@ -164,7 +164,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 360,
+      "x": 360.00000000000006,
       "y": 667,
       "z": 0
     },
@@ -373,7 +373,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 1000,
+      "width": 1000.0000000000001,
       "height": 5
     },
     "_anchorPoint": {
@@ -593,10 +593,10 @@
         "__id__": 21
       },
       {
-        "__id__": 261
+        "__id__": 29
       },
       {
-        "__id__": 29
+        "__id__": 261
       },
       {
         "__id__": 11
@@ -737,7 +737,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -852,7 +852,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0,
+      "x": -5.684341886080802e-14,
       "y": 0,
       "z": 0
     },
@@ -9815,7 +9815,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0,
+      "x": -5.684341886080802e-14,
       "y": 0,
       "z": 0
     },
@@ -13688,7 +13688,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -310,
+      "x": -310.00000000000006,
       "y": 577.3409999999999,
       "z": 0
     },
@@ -13746,7 +13746,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 360,
+      "x": 360.00000000000006,
       "y": 667,
       "z": 0
     },
@@ -13876,7 +13876,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -18649,7 +18649,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -19089,7 +19089,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0,
+      "x": -5.684341886080802e-14,
       "y": 97.5,
       "z": 0
     },
@@ -21239,7 +21239,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -21379,7 +21379,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0.14999999999997726,
+      "x": 0.1500000000000341,
       "y": -588.66,
       "z": 0
     },
@@ -21443,7 +21443,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -342.65,
+      "x": -342.6500000000001,
       "y": 0,
       "z": 0
     },
@@ -26831,7 +26831,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 705.3,
+      "width": 705.3000000000002,
       "height": 130
     },
     "_anchorPoint": {
@@ -34213,7 +34213,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 1,
+      "x": 0.9999999999999432,
       "y": -6,
       "z": 0
     },
@@ -35951,7 +35951,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -36003,7 +36003,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {
@@ -36129,7 +36129,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -216,
+      "x": -216.00000000000003,
       "y": 138.5,
       "z": 0
     },
@@ -37917,7 +37917,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 216,
+      "x": 216.00000000000003,
       "y": 138.5,
       "z": 0
     },
@@ -39114,7 +39114,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 469
     },
     "_anchorPoint": {
@@ -39256,7 +39256,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 1000,
+      "width": 1000.0000000000001,
       "height": 5
     },
     "_anchorPoint": {
@@ -39630,7 +39630,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 1604.706,
+      "x": 1604.7060000000001,
       "y": 0,
       "z": 0
     },
@@ -39793,7 +39793,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 257,
+      "x": 257.0000000000002,
       "y": 175.274,
       "z": 0
     },
@@ -43661,7 +43661,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 609,
+      "width": 609.0000000000005,
       "height": 428
     },
     "_anchorPoint": {
@@ -43843,7 +43843,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 281.9,
+      "x": 281.90000000000003,
       "y": 553.12,
       "z": 0
     },
@@ -44040,7 +44040,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 281.5,
+      "x": 281.50000000000006,
       "y": 485.124,
       "z": 0
     },
@@ -45159,7 +45159,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 720,
+      "width": 720.0000000000001,
       "height": 1334
     },
     "_anchorPoint": {

+ 5 - 5
assets/assets/Prefabs/Enemy.prefab

@@ -901,13 +901,13 @@
     },
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 79,
-      "height": 95
+      "width": 83.5,
+      "height": 89
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
-      "x": 0.31645569620253167,
-      "y": 0.08421052631578947
+      "x": 0.3772455089820359,
+      "y": 0.11797752808988764
     },
     "_id": ""
   },
@@ -938,7 +938,7 @@
       "a": 255
     },
     "_skeletonData": {
-      "__uuid__": "f25d87ae-d447-4b09-a391-0748f139b15b",
+      "__uuid__": "e7866e74-2d88-481a-bc69-4ad71b5d86eb",
       "__expectedType__": "sp.SkeletonData"
     },
     "defaultSkin": "default",

+ 7 - 7
assets/assets/Prefabs/EnemyProjectile.prefab

@@ -41,7 +41,7 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 0,
+      "x": 6.743,
       "y": 0,
       "z": 0
     },
@@ -54,8 +54,8 @@
     },
     "_lscale": {
       "__type__": "cc.Vec3",
-      "x": 0.3,
-      "y": 0.3,
+      "x": 1,
+      "y": 1,
       "z": 1
     },
     "_mobility": 0,
@@ -82,8 +82,8 @@
     },
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 142,
-      "height": 142
+      "width": 70,
+      "height": 13
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -119,7 +119,7 @@
       "a": 255
     },
     "_spriteFrame": {
-      "__uuid__": "80f212d1-c325-4e21-b2f5-19f7fa77c9b1@f9941",
+      "__uuid__": "cb557d70-78bb-44d4-9a11-1685a22fa310@f9941",
       "__expectedType__": "cc.SpriteFrame"
     },
     "_type": 0,
@@ -198,7 +198,7 @@
       "x": 0,
       "y": 0
     },
-    "_radius": 66,
+    "_radius": 37.7,
     "_id": ""
   },
   {

+ 18 - 5
assets/scripts/CombatSystem/EnemyInstance.ts

@@ -6,6 +6,7 @@ import { HPBarAnimation } from '../Animations/HPBarAnimation';
 import { EnemyComponent } from './EnemyComponent';
 import { EnemyAudio } from '../AudioManager/EnemyAudios';
 import { ScreenShakeManager } from './EnemyWeapon/ScreenShakeManager';
+
 import EventBus, { GameEvents } from '../Core/EventBus';
 const { ccclass, property } = _decorator;
 
@@ -81,6 +82,7 @@ export class EnemyInstance extends Component {
     
     // 攻击属性
     public attackInterval: number = 0; // 攻击间隔(秒),从配置文件读取
+    public attackRange: number = 0; // 攻击范围,从配置文件读取
     private attackTimer: number = 0;
     
     // 对控制器的引用
@@ -913,6 +915,11 @@ export class EnemyInstance extends Component {
             
             // 重置攻击计时器
             this.attackTimer = this.attackInterval;
+        } else {
+            // 攻击冷却期间播放待机动画(只有在不播放攻击动画时)
+            if (!this.isPlayingAttackAnimation) {
+                this.playIdleAnimationSafe();
+            }
         }
     }
 
@@ -979,7 +986,10 @@ export class EnemyInstance extends Component {
             
             // 在动画播放到90%时发射抛掷物,让抛掷物发射与动画同步
             const projectileFireTime = animationDuration * 0.9;
+            
+            // 在动画播放到90%时发射抛掷物
             this.scheduleOnce(() => {
+                // 发射抛掷物
                 this.fireProjectile();
             }, projectileFireTime);
             
@@ -1401,15 +1411,18 @@ export class EnemyInstance extends Component {
                 console.log(`[EnemyInstance] 敌人 ${this.getEnemyName()} 进入${attackTypeStr}范围,距离墙体 ${wallNode.name}: ${distance.toFixed(2)},攻击范围: ${attackRange}`);
                 
                 if (isRangedAttack) {
-                    // 远程攻击:切换到攻击状态,继续移动并发射抛掷物
-                    this.state = EnemyState.ATTACKING;
+                    // 远程攻击:切换到待机状态,停止移动并轮流播放攻击和待机动画
+                    this.state = EnemyState.IDLE;
                     this.attackTimer = 0; // 立即开始攻击
                     this.collidedWall = wallNode; // 记录目标墙体
                     
-                    // 远程攻击时继续播放walk动画,不停止移动
-                    this.playWalkAnimation();
+                    // 停止移动
+                    this.stopRigidBodyMovement();
+                    
+                    // 切换到待机动画
+                    this.playIdleAnimation();
                     
-                    console.log(`[EnemyInstance] 远程敌人 ${this.getEnemyName()} 进入攻击状态,继续移动并播放walk动画`);
+                    console.log(`[EnemyInstance] 远程敌人 ${this.getEnemyName()} 进入待机状态,停止移动并准备攻击`);
                 } else {
                     // 近战攻击:切换到待机状态,停止移动
                     this.state = EnemyState.IDLE;