Add bullet arc and number of bullets generated.

加入子弹弧度和产生子弹的数量
This commit is contained in:
Cold-Mint 2024-08-13 23:07:05 +08:00
parent 3b2ba7440c
commit 451d6d0849
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
2 changed files with 50 additions and 13 deletions

View File

@ -16,7 +16,10 @@ size = Vector2(49, 5.25)
[node name="StaffOfTheUndead" type="RigidBody2D"] [node name="StaffOfTheUndead" type="RigidBody2D"]
collision_layer = 8 collision_layer = 8
collision_mask = 34 collision_mask = 34
angular_damp = -1.0
script = ExtResource("1_w8hhv") script = ExtResource("1_w8hhv")
OffsetAngle = 0.523
NumberOfProjectiles = 15.0
ProjectileScenes = [ExtResource("2_34250"), ExtResource("3_hk5nr")] ProjectileScenes = [ExtResource("2_34250"), ExtResource("3_hk5nr")]
Sequentially = true Sequentially = true
FiringIntervalAsMillisecond = 300 FiringIntervalAsMillisecond = 300

View File

@ -22,6 +22,18 @@ public partial class ProjectileWeapon : WeaponTemplate
/// </summary> /// </summary>
private Marker2D? _marker2D; private Marker2D? _marker2D;
/// <summary>
/// <para>Scattering radians</para>
/// <para>散射弧度</para>
/// </summary>
[Export] protected float OffsetAngle;
/// <summary>
/// <para>The number of projectiles fired at once</para>
/// <para>一次可以发射多少个子弹</para>
/// </summary>
[Export] protected float NumberOfProjectiles = 1;
[Export] protected PackedScene[] ProjectileScenes { get; set; } = []; [Export] protected PackedScene[] ProjectileScenes { get; set; } = [];
/// <summary> /// <summary>
@ -57,6 +69,24 @@ public partial class ProjectileWeapon : WeaponTemplate
} }
} }
/// <summary>
/// <para>GetRandomAngle</para>
/// <para>获取随机的偏移弧度</para>
/// </summary>
/// <returns></returns>
private float GetRandomAngle()
{
if (OffsetAngle == 0)
{
//If the offset angle is 0, then return 0
//弧度为0,不用偏移。
return 0;
}
var min = -OffsetAngle / 2;
return min + RandomUtils.Instance.NextSingle() * OffsetAngle;
}
protected override void DoFire(Node2D? owner, Vector2 enemyGlobalPosition) protected override void DoFire(Node2D? owner, Vector2 enemyGlobalPosition)
{ {
@ -89,6 +119,8 @@ public partial class ProjectileWeapon : WeaponTemplate
//Get the first projectile //Get the first projectile
//获取第一个抛射体 //获取第一个抛射体
var projectileScene = GetNextProjectileScene(); var projectileScene = GetNextProjectileScene();
for (int i = 0; i < NumberOfProjectiles; i++)
{
var projectile = NodeUtils.InstantiatePackedScene<Projectile>(projectileScene); var projectile = NodeUtils.InstantiatePackedScene<Projectile>(projectileScene);
if (projectile == null) return; if (projectile == null) return;
if (Config.IsDebug()) if (Config.IsDebug())
@ -103,7 +135,9 @@ public partial class ProjectileWeapon : WeaponTemplate
NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile); NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile);
projectile.Owner = owner; projectile.Owner = owner;
projectile.Velocity = (enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed; projectile.Velocity =
((enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed).Rotated(GetRandomAngle());
projectile.Position = _marker2D.GlobalPosition; projectile.Position = _marker2D.GlobalPosition;
} }
} }
}