Add a tracking spell.

加入跟踪法术。
This commit is contained in:
Cold-Mint 2024-10-12 14:49:21 +08:00
parent 35cb1296c7
commit 8bd7113153
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
16 changed files with 141 additions and 25 deletions

View File

@ -19,4 +19,8 @@
- id: magic_missile
scene_path: res://prefab/magics/magicMissile.tscn
icon_path: res://sprites/projectile/magicMissile.png
max_stack_value: 1
- id: tracking_spell
scene_path: res://prefab/magics/trackingSpell.tscn
icon_path: res://sprites/projectile/trackingSpell.png
max_stack_value: 1

View File

@ -16,4 +16,6 @@ item_curse_desc,杀死敌人后在生成死灵敌人。,Spawn Undead enemies aft
item_beginner_staff,初学者法杖,Beginner's staff,初心者用の杖です
item_beginner_staff_desc,送给初来乍到的冒险家。,For new adventurers.,初心者の冒険家に贈ります。
item_magic_missile,魔法飞弹,Magic missile,魔法のミサイルです
item_magic_missile_desc,魔法飞弹,Magic missile,魔法のミサイルです
item_magic_missile_desc,轻快的法术。,A light spell.,軽快な術です。
item_tracking_spell,追踪法术,Tracking spell,追跡術です
item_tracking_spell_desc,使发射的子弹追踪敌人,Let the fired bullets track the enemy,発射した弾丸で敵を追跡させます
1 id zh en ja
16 item_beginner_staff 初学者法杖 Beginner's staff 初心者用の杖です
17 item_beginner_staff_desc 送给初来乍到的冒险家。 For new adventurers. 初心者の冒険家に贈ります。
18 item_magic_missile 魔法飞弹 Magic missile 魔法のミサイルです
19 item_magic_missile_desc 魔法飞弹 轻快的法术。 Magic missile A light spell. 魔法のミサイルです 軽快な術です。
20 item_tracking_spell 追踪法术 Tracking spell 追跡術です
21 item_tracking_spell_desc 使发射的子弹追踪敌人 Let the fired bullets track the enemy 発射した弾丸で敵を追跡させます

View File

@ -0,0 +1,36 @@
[gd_scene load_steps=5 format=3 uid="uid://cg75t3fw5c6er"]
[ext_resource type="Script" path="res://scripts/spell/TrackingSpell.cs" id="1_vhnwx"]
[ext_resource type="AudioStream" uid="uid://cak6chjjsu7wo" path="res://sounds/fire.wav" id="2_3fbv3"]
[ext_resource type="Texture2D" uid="uid://dhgbij2ifphar" path="res://sprites/projectile/trackingSpell.png" id="2_i33g0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_i3lbq"]
size = Vector2(30, 31)
[node name="trackingSpell" type="RigidBody2D"]
collision_layer = 8
collision_mask = 34
angular_damp = -1.0
script = ExtResource("1_vhnwx")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -0.5)
shape = SubResource("RectangleShape2D_i3lbq")
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(65, 0)
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="Marker2D"]
stream = ExtResource("2_3fbv3")
bus = &"SoundEffect"
[node name="TipLabel" type="Label" parent="."]
offset_left = -19.0
offset_top = 23.0
offset_right = 21.0
offset_bottom = 48.0
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]
[node name="TrackingSpell" type="Sprite2D" parent="."]
texture = ExtResource("2_i33g0")

View File

@ -14,7 +14,6 @@ angular_damp = -1.0
script = ExtResource("1_cnhod")
RandomAngle = true
UnitRadian = 0.07
_projectilePath = null
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -0.5)

View File

@ -14,11 +14,7 @@ _durability = 1.0
_maxDamage = 7
_minDamage = 3
_damageType = 2
Speed = 500.0
_enableBounce = null
_ignoreWall = null
_enableTracking = null
_targetDiesDestroyProjectile = true
Speed = 10.0
_repelStrength = 2.5
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]

View File

@ -15,8 +15,7 @@ _durability = 1.0
_maxDamage = 7
_minDamage = 3
_damageType = 2
Speed = 500.0
_targetDiesDestroyProjectile = true
Speed = 15.0
_repelStrength = 2.5
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View File

@ -90,15 +90,23 @@ texture = ExtResource("6_dbg76")
[node name="RigidBody2D" parent="." instance=ExtResource("5_0kep0")]
position = Vector2(227, 283)
_initialDurability = 0
_maxDurability = 0
[node name="WoodenBox" parent="." instance=ExtResource("7_jybe6")]
position = Vector2(715, 244)
_initialDurability = 0
_furnitureName = ""
[node name="WoodenBox2" parent="." instance=ExtResource("7_jybe6")]
position = Vector2(715, 200)
_initialDurability = 0
_furnitureName = ""
[node name="WoodenBox3" parent="." instance=ExtResource("7_jybe6")]
position = Vector2(715, 162)
_initialDurability = 0
_furnitureName = ""
[node name="AutoSpawn" type="Node2D" parent="."]
@ -112,6 +120,11 @@ position = Vector2(100, 250)
script = ExtResource("4_6ihp7")
_itemIdList = PackedStringArray("magic_missile")
[node name="tracking_spell" type="Marker2D" parent="AutoSpawn"]
position = Vector2(156, 245)
script = ExtResource("4_6ihp7")
_itemIdList = PackedStringArray("tracking_spell")
[node name="RoomArea" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="RoomArea"]

View File

@ -13,9 +13,8 @@ collision_layer = 8
collision_mask = 34
script = ExtResource("1_w4b6p")
_numberSlots = 5
_spellList = null
_fireSequentially = true
FiringIntervalAsMillisecond = 300
FiringIntervalAsMillisecond = 280
_recoilStrength = 5
UniqueIcon = ExtResource("2_ip8xd")

View File

@ -15,10 +15,6 @@ collision_layer = 8
collision_mask = 34
angular_damp = -1.0
script = ExtResource("1_snmy1")
_maxDamage = null
_minDamage = null
FiringIntervalAsMillisecond = null
_recoilStrength = null
[node name="StaffOfTheUndead2" type="Sprite2D" parent="."]
position = Vector2(30, 0)

View File

@ -12,10 +12,10 @@ size = Vector2(49, 5.25)
collision_layer = 8
collision_mask = 34
script = ExtResource("1_w8hhv")
_numberSlots = 5
_numberSlots = 1
_spellList = PackedStringArray("necromancy")
_fireSequentially = true
FiringIntervalAsMillisecond = 300
FiringIntervalAsMillisecond = 350
_recoilStrength = 5
UniqueIcon = ExtResource("3_31iau")

View File

@ -15,6 +15,7 @@ public static class LogCat
/// <para>默认的日志标签</para>
/// </summary>
public const string Default = "Default";
public const string Debug = "Debug";
/// <summary>
/// <para>LookForWeaponProcessor</para>

View File

@ -39,7 +39,28 @@ public partial class Projectile : CharacterBody2D
/// </summary>
private DateTime? _destructionTime;
[Export] public float Speed;
private float _actualSpeed;
/// <summary>
/// <para>The speed of the bullet</para>
/// <para>子弹的飞行速度</para>
/// </summary>
/// <remarks>
///<para>Indicates the number of units moved per second</para>
///<para>表示每秒移动的单位格数</para>
/// </remarks>
[Export]
public float Speed
{
get => _actualSpeed / Config.CellSize;
private set => _actualSpeed = value * Config.CellSize;
}
/// <summary>
/// <para>Get actual speed</para>
/// <para>获取实际速度</para>
/// </summary>
public float ActualSpeed => _actualSpeed;
/// <summary>
/// <para>Whether it bounces back after hitting an enemy or a wall</para>
@ -57,13 +78,13 @@ public partial class Projectile : CharacterBody2D
/// <para>Enable the tracking of the enemy</para>
/// <para>启用追踪敌人的功能</para>
/// </summary>
[Export] private bool _enableTracking;
[Export] public bool EnableTracking;
/// <summary>
/// <para>The target dies and destroys the projectile at the same time</para>
/// <para>在目标死亡后销毁抛射体</para>
/// </summary>
[Export] private bool _targetDiesDestroyProjectile;
[Export] public bool TargetDiesDestroyProjectile;
/// <summary>
/// <para>The target</para>
@ -95,6 +116,7 @@ public partial class Projectile : CharacterBody2D
/// </summary>
public new Node2D? Owner { get; set; }
public override void _Ready()
{
if (!_ignoreWall)
@ -129,7 +151,7 @@ public partial class Projectile : CharacterBody2D
//Clear the trace when the target is destroyed.
//在目标被销毁的时候清空跟踪。
TargetNode = null;
if (_targetDiesDestroyProjectile)
if (TargetDiesDestroyProjectile)
{
OnTimeOut();
}
@ -265,7 +287,8 @@ public partial class Projectile : CharacterBody2D
pickAbleTemplate.ApplyImpulse(new Vector2(normalized.X * _repelStrength * Config.CellSize,
normalized.Y * _repelStrength * Config.CellSize));
}
}else if (target is Furniture furniture)
}
else if (target is Furniture furniture)
{
var damage = new Damage
{
@ -315,6 +338,7 @@ public partial class Projectile : CharacterBody2D
{
OnTimeOut();
}
LookAt(GlobalPosition + Velocity);
}
public override void _PhysicsProcess(double delta)
@ -324,7 +348,7 @@ public partial class Projectile : CharacterBody2D
{
//No collision.
//没有撞到任何东西。
if (_enableTracking && TargetNode != null)
if (EnableTracking && TargetNode != null)
{
//Track the target
//追踪目标
@ -340,7 +364,7 @@ public partial class Projectile : CharacterBody2D
}
}
var actualDesiredVelocity = desiredVelocity.Normalized() * Speed;
var actualDesiredVelocity = desiredVelocity.Normalized() * _actualSpeed;
//The weight is smaller, the circle is larger.
//weight越小子弹绕的圈越大。
Velocity = Velocity.Lerp(actualDesiredVelocity, 0.1f);

View File

@ -0,0 +1,13 @@
using ColdMint.scripts.projectile;
using Godot;
namespace ColdMint.scripts.spell;
public partial class TrackingSpell : SpellPickAble
{
public override void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity)
{
base.ModifyProjectile(index, projectile, ref velocity);
projectile.EnableTracking = true;
}
}

View File

@ -263,7 +263,7 @@ public partial class ProjectileWeapon : WeaponTemplate
RestoreWeapon(spellScope);
return false;
}
var velocity = _marker2D.GlobalPosition.DirectionTo(enemyGlobalPosition) * projectile.Speed;
var velocity = _marker2D.GlobalPosition.DirectionTo(enemyGlobalPosition) * projectile.ActualSpeed;
for (var s = spellScope[0]; s <= spellScope[1]; s++)
{
var spell = _spells[s];

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dhgbij2ifphar"
path="res://.godot/imported/trackingSpell.png-69b7e63e484daf64f35dd6da8947c87b.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/projectile/trackingSpell.png"
dest_files=["res://.godot/imported/trackingSpell.png-69b7e63e484daf64f35dd6da8947c87b.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1