diff --git a/prefab/Bullet.tscn b/prefab/Bullet.tscn deleted file mode 100644 index 19d9c8e..0000000 --- a/prefab/Bullet.tscn +++ /dev/null @@ -1,24 +0,0 @@ -[gd_scene load_steps=4 format=2] - -[ext_resource path="res://src/weapon/bullet/HighSpeedBullet.cs" type="Script" id=1] - -[sub_resource type="Curve" id=1] -_data = [ Vector2( 0, 0.781588 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ] - -[sub_resource type="Gradient" id=2] -colors = PoolColorArray( 1, 1, 1, 0.313726, 1, 1, 1, 0.784314 ) - -[node name="Bullet" type="Node2D"] -script = ExtResource( 1 ) - -[node name="Line" type="Line2D" parent="."] -points = PoolVector2Array( 0, 0, 0, 10 ) -width = 1.0 -width_curve = SubResource( 1 ) -default_color = Color( 1, 1, 1, 1 ) -gradient = SubResource( 2 ) -begin_cap_mode = 2 -end_cap_mode = 2 - -[node name="RayCast2D" type="RayCast2D" parent="."] -visible = false diff --git a/prefab/bullet/Bullet.tscn b/prefab/bullet/Bullet.tscn new file mode 100644 index 0000000..eb6d9ff --- /dev/null +++ b/prefab/bullet/Bullet.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://src/weapon/bullet/HighSpeedBullet.cs" type="Script" id=1] +[ext_resource path="res://prefab/effect/Hit.tscn" type="PackedScene" id=2] + +[sub_resource type="Curve" id=1] +_data = [ Vector2( 0, 0.781588 ), 0.0, 0.0, 0, 0, Vector2( 1, 1 ), 0.0, 0.0, 0, 0 ] + +[sub_resource type="Gradient" id=2] +colors = PoolColorArray( 1, 1, 1, 0.313726, 1, 1, 1, 0.784314 ) + +[node name="Bullet" type="Node2D"] +script = ExtResource( 1 ) +Hit = ExtResource( 2 ) + +[node name="Line" type="Line2D" parent="."] +modulate = Color( 1, 0.937255, 0.843137, 1 ) +points = PoolVector2Array( 0, 0, 0, 10 ) +width = 1.0 +width_curve = SubResource( 1 ) +default_color = Color( 1, 1, 1, 1 ) +gradient = SubResource( 2 ) +begin_cap_mode = 2 +end_cap_mode = 2 + +[node name="RayCast2D" type="RayCast2D" parent="."] +visible = false diff --git a/prefab/effect/Hit.tscn b/prefab/effect/Hit.tscn new file mode 100644 index 0000000..23b68c5 --- /dev/null +++ b/prefab/effect/Hit.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://resource/sprite/effect/hit/hit2.png" type="Texture" id=1] +[ext_resource path="res://resource/sprite/effect/hit/hit1.png" type="Texture" id=2] +[ext_resource path="res://resource/sprite/effect/hit/hit4.png" type="Texture" id=3] +[ext_resource path="res://resource/sprite/effect/hit/hit0.png" type="Texture" id=4] +[ext_resource path="res://resource/sprite/effect/hit/hit3.png" type="Texture" id=5] +[ext_resource path="res://src/effect/Hit.cs" type="Script" id=6] + +[sub_resource type="SpriteFrames" id=1] +animations = [ { +"frames": [ ExtResource( 4 ), ExtResource( 2 ), ExtResource( 1 ), ExtResource( 5 ), ExtResource( 3 ) ], +"loop": true, +"name": "Hit", +"speed": 20.0 +} ] + +[node name="Hit" type="AnimatedSprite"] +frames = SubResource( 1 ) +animation = "Hit" +playing = true +offset = Vector2( 1, 11 ) +script = ExtResource( 6 ) + +[connection signal="animation_finished" from="." to="." method="_on_Hit_animation_finished"] diff --git a/scene/Room.tscn b/scene/Room.tscn index 2941b91..c310d11 100644 --- a/scene/Room.tscn +++ b/scene/Room.tscn @@ -18,12 +18,8 @@ position = Vector2( 196, 128 ) current = true process_mode = 0 -drag_margin_h_enabled = true -drag_margin_v_enabled = true smoothing_enabled = true smoothing_speed = 8.0 -editor_draw_limits = true -editor_draw_drag_margin = true [node name="Player" parent="." instance=ExtResource( 1 )] position = Vector2( 196, 128 ) diff --git a/src/effect/Hit.cs b/src/effect/Hit.cs new file mode 100644 index 0000000..3bb55f5 --- /dev/null +++ b/src/effect/Hit.cs @@ -0,0 +1,12 @@ +using Godot; + +public class Hit : AnimatedSprite +{ + /// + /// 动画结束, 销毁 + /// + private void _on_Hit_animation_finished() + { + QueueFree(); + } +} \ No newline at end of file diff --git a/src/role/Player.cs b/src/role/Player.cs index 455f6e6..0433346 100644 --- a/src/role/Player.cs +++ b/src/role/Player.cs @@ -29,11 +29,11 @@ CurrGun = gun; var attr = new GunAttribute(); - attr.FiringSpeed = 600; - attr.StartScatteringRange = 0; - attr.FinalScatteringRange = 0; - attr.ScatteringRangeAddValue = 5; - attr.ScatteringRangeBackSpeed = 30; + attr.StartFiringSpeed = 600; + attr.StartScatteringRange = 5; + attr.FinalScatteringRange = 60; + attr.ScatteringRangeAddValue = 2f; + attr.ScatteringRangeBackSpeed = 40; //连发 attr.ContinuousShoot = true; //扳机检测间隔 @@ -42,7 +42,7 @@ attr.MinContinuousCount = 3; attr.MaxContinuousCount = 3; //开火前延时 - attr.DelayedTime = 0.5f; + attr.DelayedTime = 0f; //攻击距离 attr.MinDistance = 500; attr.MaxDistance = 600; diff --git a/src/weapon/bullet/HighSpeedBullet.cs b/src/weapon/bullet/HighSpeedBullet.cs index dcd7173..e71eeba 100644 --- a/src/weapon/bullet/HighSpeedBullet.cs +++ b/src/weapon/bullet/HighSpeedBullet.cs @@ -5,6 +5,7 @@ /// public class HighSpeedBullet : Bullet { + [Export] public PackedScene Hit; //射线检测节点 private RayCast2D RayCast2D; //最大飞行距离 @@ -24,9 +25,14 @@ // RayCast2D.CastTo = targetPos; RayCast2D.ForceRaycastUpdate(); - if (RayCast2D.IsColliding()) { + if (RayCast2D.IsColliding()) { //碰到物体 + Vector2 collPosition = RayCast2D.GetCollisionPoint(); + Node2D hit = Hit.Instance(); + hit.RotationDegrees = MathUtils.RandRangeInt(0, 360); + hit.GlobalPosition = collPosition; + GetTree().CurrentScene.AddChild(hit); //划线的点坐标 - Line.SetPointPosition(1, new Vector2(Line.GlobalPosition.DistanceTo(RayCast2D.GetCollisionPoint()), 0)); + Line.SetPointPosition(1, new Vector2(Line.GlobalPosition.DistanceTo(collPosition), 0)); } else { diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs index 3900e80..f32823c 100644 --- a/src/weapon/gun/Gun.cs +++ b/src/weapon/gun/Gun.cs @@ -252,7 +252,7 @@ private void TriggernFire() { continuousCount = continuousCount > 0 ? continuousCount - 1 : 0; - fireInterval = 60 / Attribute.FiringSpeed; + fireInterval = 60 / Attribute.StartFiringSpeed; attackTimer += fireInterval; //触发开火函数 diff --git a/src/weapon/gun/GunAttribute.cs b/src/weapon/gun/GunAttribute.cs index f3ebc4e..aaeab64 100644 --- a/src/weapon/gun/GunAttribute.cs +++ b/src/weapon/gun/GunAttribute.cs @@ -14,6 +14,10 @@ /// public bool ContinuousShoot = true; /// + /// 是否为松发开火, 也就是松开扳机才开火, 若要启用该属性, 必须将 'ContinuousShoot' 设置为 false + /// + public bool LooseShoot = false; + /// /// 连续发射最小次数, 仅当ContinuousShoot为false时生效 /// public int MinContinuousCount = 3; @@ -26,9 +30,21 @@ /// public float TriggerInterval = 0; /// - /// 射速, 每秒分钟能发射多少发子弹 + /// 初始射速, 初始每秒分钟能发射多少发子弹 /// - public float FiringSpeed = 300; + public float StartFiringSpeed = 300; + /// + /// 最终射速, 最终每秒分钟能发射多少发子弹 + /// + public float FinalFiringSpeed = 300; + /// + /// 按下扳机并开火后射速增加速率 + /// + public float FiringSpeedAddSpeed = 2; + /// + /// 松开扳机后射速消散速率 + /// + public float FiringSpeedBackSpeed = 10; /// /// 单次开火发射子弹最小数量 /// diff --git a/src/weapon/gun/OrdinaryGun.cs b/src/weapon/gun/OrdinaryGun.cs index a5960f0..047da0c 100644 --- a/src/weapon/gun/OrdinaryGun.cs +++ b/src/weapon/gun/OrdinaryGun.cs @@ -12,7 +12,7 @@ protected override void Init() { //子弹 - bulletPacked = ResourceLoader.Load("res://prefab/Bullet.tscn"); + bulletPacked = ResourceLoader.Load("res://prefab/bullet/Bullet.tscn"); } protected override void Fire()