Bullets can now track enemies.
子弹可以跟踪敌人了。
This commit is contained in:
parent
451d6d0849
commit
5d9643476f
|
@ -15,14 +15,15 @@ slide_on_ceiling = false
|
||||||
platform_floor_layers = 4294967042
|
platform_floor_layers = 4294967042
|
||||||
platform_wall_layers = 32
|
platform_wall_layers = 32
|
||||||
script = ExtResource("1_ib3qh")
|
script = ExtResource("1_ib3qh")
|
||||||
Life = 5000
|
Life = 30000
|
||||||
Durability = 3.0
|
Durability = 3.0
|
||||||
MaxDamage = 3
|
MaxDamage = 3
|
||||||
MinDamage = 10
|
MinDamage = 10
|
||||||
DamageType = 2
|
DamageType = 2
|
||||||
KnockbackForce = Vector2(2, -3)
|
KnockbackForce = Vector2(2, -3)
|
||||||
Speed = 300.0
|
Speed = 300.0
|
||||||
EnableBounce = true
|
IgnoreWall = true
|
||||||
|
EnableTracking = true
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource("CircleShape2D_dgro2")
|
shape = SubResource("CircleShape2D_dgro2")
|
||||||
|
|
|
@ -12,13 +12,14 @@ radius = 11.0
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
script = ExtResource("1_ib3qh")
|
script = ExtResource("1_ib3qh")
|
||||||
Life = 5000
|
Life = 30000
|
||||||
Durability = 1.0
|
Durability = 1.0
|
||||||
MaxDamage = 3
|
MaxDamage = 3
|
||||||
MinDamage = 10
|
MinDamage = 10
|
||||||
DamageType = 2
|
DamageType = 2
|
||||||
KnockbackForce = Vector2(2, -3)
|
KnockbackForce = Vector2(2, -3)
|
||||||
Speed = 500.0
|
Speed = 500.0
|
||||||
|
IgnoreWall = true
|
||||||
|
|
||||||
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]
|
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("1_k8el6")
|
texture = ExtResource("1_k8el6")
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
[gd_scene load_steps=9 format=3 uid="uid://dnnn2xyayiehk"]
|
[gd_scene load_steps=8 format=3 uid="uid://dnnn2xyayiehk"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://wt50kx6bup51" path="res://sprites/weapon/StaffNecromancy.png" id="1_ms3us"]
|
[ext_resource type="Texture2D" uid="uid://wt50kx6bup51" path="res://sprites/weapon/StaffNecromancy.png" id="1_ms3us"]
|
||||||
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
|
[ext_resource type="Script" path="res://scripts/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
|
||||||
[ext_resource type="PackedScene" uid="uid://c01av43yk1q71" path="res://prefab/projectile/curseOfTheUndead.tscn" id="2_34250"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://dg5vwprt66w4j" path="res://sprites/weapon/StaffNecromancy_Icon.png" id="3_31iau"]
|
[ext_resource type="Texture2D" uid="uid://dg5vwprt66w4j" path="res://sprites/weapon/StaffNecromancy_Icon.png" id="3_31iau"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bdxgx5vcof8em" path="res://prefab/projectile/Catapult.tscn" id="3_hk5nr"]
|
[ext_resource type="PackedScene" uid="uid://bdxgx5vcof8em" path="res://prefab/projectile/Catapult.tscn" id="3_hk5nr"]
|
||||||
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"]
|
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="4_ffr2k"]
|
||||||
|
@ -18,9 +17,8 @@ collision_layer = 8
|
||||||
collision_mask = 34
|
collision_mask = 34
|
||||||
angular_damp = -1.0
|
angular_damp = -1.0
|
||||||
script = ExtResource("1_w8hhv")
|
script = ExtResource("1_w8hhv")
|
||||||
OffsetAngle = 0.523
|
OffsetAngle = 0.087
|
||||||
NumberOfProjectiles = 15.0
|
ProjectileScenes = [ExtResource("3_hk5nr")]
|
||||||
ProjectileScenes = [ExtResource("2_34250"), ExtResource("3_hk5nr")]
|
|
||||||
Sequentially = true
|
Sequentially = true
|
||||||
FiringIntervalAsMillisecond = 300
|
FiringIntervalAsMillisecond = 300
|
||||||
UniqueIcon = ExtResource("3_31iau")
|
UniqueIcon = ExtResource("3_31iau")
|
||||||
|
|
|
@ -418,6 +418,30 @@ public static class Config
|
||||||
public const int VerticalVelocityOfDamageNumbers = 5;
|
public const int VerticalVelocityOfDamageNumbers = 5;
|
||||||
|
|
||||||
|
|
||||||
|
public static class OffsetAngleMode
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Random(Default)</para>
|
||||||
|
/// <para>随机的(默认)</para>
|
||||||
|
/// </summary>
|
||||||
|
public const int Random = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>AlwaysSame</para>
|
||||||
|
/// <para>永远不变的偏移角度</para>
|
||||||
|
/// </summary>
|
||||||
|
public const int AlwaysSame = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Cross</para>
|
||||||
|
/// <para>交叉变换</para>
|
||||||
|
/// </summary>
|
||||||
|
public const int Cross = 2;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Physical collision layer number</para>
|
/// <para>Physical collision layer number</para>
|
||||||
/// <para>物理碰撞层 序号</para>
|
/// <para>物理碰撞层 序号</para>
|
||||||
|
|
|
@ -341,7 +341,7 @@ public sealed partial class AiCharacter : CharacterTemplate
|
||||||
if (NavigationAgent2D != null && IsOnFloor())
|
if (NavigationAgent2D != null && IsOnFloor())
|
||||||
{
|
{
|
||||||
var nextPathPosition = NavigationAgent2D.GetNextPathPosition();
|
var nextPathPosition = NavigationAgent2D.GetNextPathPosition();
|
||||||
var direction = (nextPathPosition - GlobalPosition).Normalized();
|
var direction = GlobalPosition.DirectionTo(nextPathPosition);
|
||||||
velocity = direction * Config.CellSize * Speed * ProtectedSpeedScale;
|
velocity = direction * Config.CellSize * Speed * ProtectedSpeedScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,10 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
||||||
FriendInjury = true
|
FriendInjury = true
|
||||||
};
|
};
|
||||||
CampManager.SetDefaultCamp(defaultCamp);
|
CampManager.SetDefaultCamp(defaultCamp);
|
||||||
var mazoku = new Camp(Config.CampId.Mazoku);
|
var mazoku = new Camp(Config.CampId.Mazoku)
|
||||||
|
{
|
||||||
|
FriendInjury = true
|
||||||
|
};
|
||||||
CampManager.AddCamp(mazoku);
|
CampManager.AddCamp(mazoku);
|
||||||
var aborigines = new Camp(Config.CampId.Aborigines);
|
var aborigines = new Camp(Config.CampId.Aborigines);
|
||||||
CampManager.AddCamp(aborigines);
|
CampManager.AddCamp(aborigines);
|
||||||
|
|
|
@ -61,6 +61,18 @@ public partial class Projectile : CharacterBody2D
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export] public bool IgnoreWall;
|
[Export] public bool IgnoreWall;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Enable the tracking of the enemy</para>
|
||||||
|
/// <para>启用追踪敌人的功能</para>
|
||||||
|
/// </summary>
|
||||||
|
[Export] public bool EnableTracking;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>The target</para>
|
||||||
|
/// <para>设置目标</para>
|
||||||
|
/// </summary>
|
||||||
|
public Node2D? Target { get; set; }
|
||||||
|
|
||||||
private List<IProjectileDecorator>? _projectileDecorators;
|
private List<IProjectileDecorator>? _projectileDecorators;
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,7 +283,23 @@ public partial class Projectile : CharacterBody2D
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var collisionInfo = MoveAndCollide(Velocity * (float)delta);
|
var collisionInfo = MoveAndCollide(Velocity * (float)delta);
|
||||||
if (collisionInfo != null)
|
if (collisionInfo == null)
|
||||||
|
{
|
||||||
|
//No collision.
|
||||||
|
//没有撞到任何东西。
|
||||||
|
if (EnableTracking && Target != null)
|
||||||
|
{
|
||||||
|
//Track the target
|
||||||
|
//追踪目标
|
||||||
|
//Gets a vector of the projectile pointing at the enemy's position.
|
||||||
|
//得到抛射体指向敌人位置的向量。
|
||||||
|
var desiredVelocity = GlobalPosition.DirectionTo(Target.GlobalPosition) * Speed;
|
||||||
|
//The weight is smaller, the circle is larger.
|
||||||
|
//weight越小,子弹绕的圈越大。
|
||||||
|
Velocity = Velocity.Lerp(desiredVelocity, 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
//Bump into other objects.
|
//Bump into other objects.
|
||||||
//撞到其他对象。
|
//撞到其他对象。
|
||||||
|
|
|
@ -27,7 +27,19 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
/// <para>散射弧度</para>
|
/// <para>散射弧度</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Export] protected float OffsetAngle;
|
[Export] protected float OffsetAngle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Offset angle mode</para>
|
||||||
|
/// <para>偏移角度模式</para>
|
||||||
|
/// </summary>
|
||||||
|
[Export] protected int OffsetAngleMode = Config.OffsetAngleMode.Random;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Whether the last offset angle is positive</para>
|
||||||
|
/// <para>上次的偏移角度是否为正向的</para>
|
||||||
|
/// </summary>
|
||||||
|
private bool _positiveOffsetAngle = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>The number of projectiles fired at once</para>
|
/// <para>The number of projectiles fired at once</para>
|
||||||
/// <para>一次可以发射多少个子弹</para>
|
/// <para>一次可以发射多少个子弹</para>
|
||||||
|
@ -69,6 +81,7 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>GetRandomAngle</para>
|
/// <para>GetRandomAngle</para>
|
||||||
/// <para>获取随机的偏移弧度</para>
|
/// <para>获取随机的偏移弧度</para>
|
||||||
|
@ -83,6 +96,27 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OffsetAngleMode == Config.OffsetAngleMode.Cross)
|
||||||
|
{
|
||||||
|
float result;
|
||||||
|
if (_positiveOffsetAngle)
|
||||||
|
{
|
||||||
|
result = -OffsetAngle / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = OffsetAngle / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
_positiveOffsetAngle = !_positiveOffsetAngle;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OffsetAngleMode == Config.OffsetAngleMode.AlwaysSame)
|
||||||
|
{
|
||||||
|
return OffsetAngle;
|
||||||
|
}
|
||||||
|
|
||||||
var min = -OffsetAngle / 2;
|
var min = -OffsetAngle / 2;
|
||||||
return min + RandomUtils.Instance.NextSingle() * OffsetAngle;
|
return min + RandomUtils.Instance.NextSingle() * OffsetAngle;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +170,8 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile);
|
NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile);
|
||||||
projectile.Owner = owner;
|
projectile.Owner = owner;
|
||||||
projectile.Velocity =
|
projectile.Velocity =
|
||||||
((enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed).Rotated(GetRandomAngle());
|
(_marker2D.GlobalPosition.DirectionTo(enemyGlobalPosition) * projectile.Speed)
|
||||||
|
.Rotated(GetRandomAngle());
|
||||||
projectile.Position = _marker2D.GlobalPosition;
|
projectile.Position = _marker2D.GlobalPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user