diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 8f16079..da8e0c9 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -21,8 +21,8 @@ [display] -window/size/viewport_width=1920 -window/size/viewport_height=1080 +window/size/viewport_width=1280 +window/size/viewport_height=720 window/stretch/aspect="keep_width" window/vsync/use_vsync=false diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png index d64d95a..e502322 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png Binary files differ diff --git a/DungeonShooting_Godot/src/framework/activity/Component.cs b/DungeonShooting_Godot/src/framework/activity/Component.cs index 30a1fd9..2837a48 100644 --- a/DungeonShooting_Godot/src/framework/activity/Component.cs +++ b/DungeonShooting_Godot/src/framework/activity/Component.cs @@ -299,6 +299,26 @@ { Master.Reparent(node); } + + public float GetProcessDeltaTime() + { + return (float)Master.GetProcessDeltaTime(); + } + + public float GetPhysicsProcessDeltaTime() + { + return (float)Master.GetPhysicsProcessDeltaTime(); + } + + public Vector2 GetGlobalMousePosition() + { + return Master.GetGlobalMousePosition(); + } + + public Vector2 GetLocalMousePosition() + { + return Master.GetLocalMousePosition(); + } public long StartCoroutine(IEnumerator able) { diff --git a/DungeonShooting_Godot/src/game/activity/role/SubLine.cs b/DungeonShooting_Godot/src/game/activity/role/SubLine.cs index a5beaf8..58f21e2 100644 --- a/DungeonShooting_Godot/src/game/activity/role/SubLine.cs +++ b/DungeonShooting_Godot/src/game/activity/role/SubLine.cs @@ -1,4 +1,5 @@  +using System.Collections; using Godot; public class SubLine : Component @@ -8,18 +9,18 @@ private bool _enableSubLine; private float _range; + private long _cid; public override void Ready() { //初始化瞄准辅助线 _line2D = new Line2D(); _line2D.Width = 1; - _line2D.DefaultColor = Colors.Red; + _line2D.DefaultColor = Colors.Orange; AddChild(_line2D); _rayCast2D = new RayCast2D(); _rayCast2D.CollisionMask = PhysicsLayer.Wall; - //_rayCast2D.Position = Master.MountPoint.Position; AddChild(_rayCast2D); Master.WeaponPack.ChangeActiveItemEvent += OnChangeWeapon; @@ -32,8 +33,38 @@ public override void OnDisable() { + _enableSubLine = false; _line2D.Visible = false; _rayCast2D.Enabled = false; + if (_cid > 0) + { + StopCoroutine(_cid); + } + } + + public void SetColor(Color color) + { + _line2D.DefaultColor = color; + } + + public void PlayWarnAnimation(float time) + { + if (_cid > 0) + { + StopCoroutine(_cid); + } + + _cid = StartCoroutine(RunWarnAnimation(time)); + } + + private IEnumerator RunWarnAnimation(float time) + { + var now = 0f; + while (now < time) + { + now += GetProcessDeltaTime(); + yield return null; + } } //切换武器 @@ -50,6 +81,10 @@ else { _enableSubLine = true; + if (_cid > 0) + { + StopCoroutine(_cid); + } _range = Utils.GetConfigRangeEnd(weapon.Attribute.BulletDistanceRange); } } @@ -71,6 +106,8 @@ public override void OnDestroy() { + _line2D.QueueFree(); + _rayCast2D.QueueFree(); Master.WeaponPack.ChangeActiveItemEvent -= OnChangeWeapon; } diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs index f0da104..684d124 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs @@ -178,6 +178,15 @@ { SubLine.Enable = true; } + + if (weapon.GetAiLockRemainderTime() > 0.4f) + { + SubLine.SetColor(Colors.Orange); + } + else + { + SubLine.SetColor(Colors.Red); + } } else if (SubLine != null) { @@ -196,11 +205,6 @@ //拾起武器操作 EnemyPickUpWeapon(); - // //更新瞄准辅助线 - // if (SubLine != null && SubLine.Visible && WeaponPack.ActiveItem != null) - // { - // UpdateSubLine(); - // } } protected override void OnHit(int damage, bool realHarm) @@ -324,7 +328,7 @@ return false; } - + /// /// Ai触发的攻击 /// @@ -468,7 +472,7 @@ /// /// 获取锁定目标的时间 /// - public float GetLockTargetTime() + public float GetLockTime() { return _lockTargetTime; } diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index aadd48b..9ff921a 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -164,7 +164,7 @@ private bool _triggerFlag = false; //扳机计时器 - private float _triggerTimer = 0; + public float _triggerTimer = 0; //开火前延时时间 private float _delayedTime = 0; @@ -176,7 +176,7 @@ private float _fireAngle = 0; //攻击冷却计时 - private float _attackTimer = 0; + public float _attackTimer = 0; //攻击状态 private bool _attackFlag = false; @@ -1965,7 +1965,7 @@ else { var enemy = (Enemy)Master; - if (enemy.GetLockTargetTime() >= Attribute.AiAttackAttr.LockingTime) //正常射击 + if (enemy.GetLockTime() >= Attribute.AiAttackAttr.LockingTime) //正常射击 { if (GetDelayedAttackTime() > 0) { @@ -2024,7 +2024,10 @@ else if (_beLoadedState == 0 || _beLoadedState == -1) //需要上膛 { flag = AiAttackState.AttackInterval; - Master.Attack(); + if (_attackTimer <= 0) + { + Master.Attack(); + } } else if (_beLoadedState == 1) //上膛中 { @@ -2041,7 +2044,7 @@ else { var enemy = (Enemy)Master; - if (enemy.GetLockTargetTime() >= Attribute.AiAttackAttr.LockingTime) //正常射击 + if (enemy.GetLockTime() >= Attribute.AiAttackAttr.LockingTime) //正常射击 { if (GetDelayedAttackTime() > 0) { @@ -2083,6 +2086,15 @@ return flag; } + /// + /// 获取Ai锁定目标的剩余时间 + /// + /// + public float GetAiLockRemainderTime() + { + return Attribute.AiAttackAttr.LockingTime - ((Enemy)Master).GetLockTime(); + } + // /// // /// 获取 Ai 对于该武器的评分, 评分越高, 代表 Ai 会越优先选择该武器, 如果为 -1, 则表示 Ai 不会使用该武器 // ///