diff --git a/prefab/role/Role.tscn b/prefab/role/Role.tscn index 92fec16..5c6d122 100644 --- a/prefab/role/Role.tscn +++ b/prefab/role/Role.tscn @@ -85,7 +85,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" -frame = 2 +frame = 3 playing = true [node name="HitArea" type="Area2D" parent="."] diff --git a/prefab/weapon/Gun.tscn b/prefab/weapon/Gun.tscn index 9e1161b..b0d38ca 100644 --- a/prefab/weapon/Gun.tscn +++ b/prefab/weapon/Gun.tscn @@ -1,15 +1,22 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://src/weapon/gun/OrdinaryGun.cs" type="Script" id=1] +[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2] [ext_resource path="res://resource/sprite/gun/gun1.png" type="Texture" id=3] +[sub_resource type="ShaderMaterial" id=2] +shader = ExtResource( 2 ) +shader_param/shadowColor = Color( 1, 1, 1, 1 ) +shader_param/schedule = 0.0 + [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 9.5, 3.5 ) +extents = Vector2( 7.8, 3.5 ) [node name="Gun" type="Node2D"] script = ExtResource( 1 ) [node name="GunSprite" type="Sprite" parent="."] +material = SubResource( 2 ) position = Vector2( 4, -3 ) scale = Vector2( 0.8, 0.8 ) texture = ExtResource( 3 ) @@ -24,6 +31,7 @@ position = Vector2( 11, -1.5 ) [node name="Area" type="Area2D" parent="."] +visible = false collision_layer = 4 collision_mask = 0 diff --git a/project.godot b/project.godot index cf7aefc..be00f17 100644 --- a/project.godot +++ b/project.godot @@ -132,6 +132,11 @@ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } +throw={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":71,"physical_scancode":0,"unicode":0,"echo":false,"script":null) + ] +} [layer_names] diff --git a/resource/materlal/Shadow.gdshader b/resource/materlal/Shadow.gdshader index 1803dfd..b3ba457 100644 --- a/resource/materlal/Shadow.gdshader +++ b/resource/materlal/Shadow.gdshader @@ -1,11 +1,11 @@ shader_type canvas_item; uniform vec4 shadowColor : hint_color = vec4(0.0, 0.0, 0.0, 0.8); - +uniform float schedule = 1.0; //将贴图渲染为阴影 void fragment() { - float a = texture(TEXTURE, UV).a; - - COLOR = mix(vec4(0.0, 0.0, 0.0, 0.0), shadowColor, a); + vec4 textureColor = texture(TEXTURE, UV); + vec4 col = mix(textureColor, shadowColor, schedule); + COLOR = mix(vec4(0.0, 0.0, 0.0, 0.0), col, textureColor.a); } diff --git a/resource/materlal/Shadow.tres b/resource/materlal/Shadow.tres index 4110580..c102048 100644 --- a/resource/materlal/Shadow.tres +++ b/resource/materlal/Shadow.tres @@ -5,3 +5,4 @@ [resource] shader = ExtResource( 1 ) shader_param/shadowColor = Color( 0, 0, 0, 0.8 ) +shader_param/schedule = 1.0 diff --git a/resource/sprite/gun/gun1.png b/resource/sprite/gun/gun1.png index d1fa987..fc6c2ce 100644 --- a/resource/sprite/gun/gun1.png +++ b/resource/sprite/gun/gun1.png Binary files differ diff --git a/resource/sprite/gun/gun2.png b/resource/sprite/gun/gun2.png index 1c20002..8889f01 100644 --- a/resource/sprite/gun/gun2.png +++ b/resource/sprite/gun/gun2.png Binary files differ diff --git a/resource/sprite/gun/gun3.png b/resource/sprite/gun/gun3.png index b008379..ebccd94 100644 --- a/resource/sprite/gun/gun3.png +++ b/resource/sprite/gun/gun3.png Binary files differ diff --git a/resource/sprite/gun/gun4.png b/resource/sprite/gun/gun4.png index 5c86aab..d3643d2 100644 --- a/resource/sprite/gun/gun4.png +++ b/resource/sprite/gun/gun4.png Binary files differ diff --git a/resource/sprite/gun/gun5.png b/resource/sprite/gun/gun5.png index eca007d..9845085 100644 --- a/resource/sprite/gun/gun5.png +++ b/resource/sprite/gun/gun5.png Binary files differ diff --git a/resource/sprite/gun/gun6.png b/resource/sprite/gun/gun6.png index 4f51038..b4948f3 100644 --- a/resource/sprite/gun/gun6.png +++ b/resource/sprite/gun/gun6.png Binary files differ diff --git a/resource/sprite/gun/gun7.png b/resource/sprite/gun/gun7.png index f6fdd30..a4d1cea 100644 --- a/resource/sprite/gun/gun7.png +++ b/resource/sprite/gun/gun7.png Binary files differ diff --git a/resource/sprite/gun/gun8.png b/resource/sprite/gun/gun8.png index 21c0366..6186597 100644 --- a/resource/sprite/gun/gun8.png +++ b/resource/sprite/gun/gun8.png Binary files differ diff --git a/scene/Room.tscn b/scene/Room.tscn index 64eb6c2..23e17e9 100644 --- a/scene/Room.tscn +++ b/scene/Room.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://prefab/role/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://resource/map/dungeon_test.tmx" type="PackedScene" id=2] [ext_resource path="res://src/room/RoomManager.cs" type="Script" id=3] [ext_resource path="res://prefab/ui/Cursor.tscn" type="PackedScene" id=4] +[ext_resource path="res://prefab/weapon/Gun.tscn" type="PackedScene" id=5] [node name="Room" type="Node2D"] script = ExtResource( 3 ) @@ -29,3 +30,7 @@ [node name="RemoteTransform2D" type="RemoteTransform2D" parent="YSort/Player"] remote_path = NodePath("../../../Camera2D") + +[node name="Gun" parent="YSort" instance=ExtResource( 5 )] +position = Vector2( 125, 132 ) +z_index = -1 diff --git a/src/package/Holster.cs b/src/package/Holster.cs index f2b1297..e201dba 100644 --- a/src/package/Holster.cs +++ b/src/package/Holster.cs @@ -110,7 +110,8 @@ /// </summary> public bool ExchangeByIndex(int index) { - if (index > SlotList.Length) return false; + if (index == ActiveIndex && ActiveGun != null) return true; + if (index < 0 || index > SlotList.Length) return false; var slot = SlotList[index]; if (slot == null || slot.Gun == null) return false; @@ -127,6 +128,7 @@ } else if (ActiveIndex == 1) { + ActiveGun.Position = new Vector2(0, 0); ActiveGun.RotationDegrees = 120; ActiveGun.Scale = new Vector2(1, -1); } @@ -138,10 +140,11 @@ } else if (ActiveIndex == 3) { + ActiveGun.Position = new Vector2(0, 0); ActiveGun.RotationDegrees = 60; ActiveGun.Scale = new Vector2(1, 1); } - + ActiveGun._Conceal(); } //更改父节点 @@ -161,6 +164,7 @@ slot.Gun.RotationDegrees = 0; ActiveGun = slot.Gun; ActiveIndex = index; + ActiveGun._Active(); return true; } } diff --git a/src/role/Role.cs b/src/role/Role.cs index b845f07..4a6b36c 100644 --- a/src/role/Role.cs +++ b/src/role/Role.cs @@ -83,7 +83,7 @@ public void PickUpGun(Gun gun) { var index = Holster.PickupGun(gun); - SetActiveGun(index); + Holster.ExchangeByIndex(index); } public void ExchangeNext() @@ -91,11 +91,6 @@ Holster.ExchangeNext(); } - private void SetActiveGun(int index) - { - Holster.ExchangeByIndex(index); - } - private void SetFace(FaceDirection face) { if (_face != face) diff --git a/src/weapon/gun/Gun.cs b/src/weapon/gun/Gun.cs index ad5529a..b00c87a 100644 --- a/src/weapon/gun/Gun.cs +++ b/src/weapon/gun/Gun.cs @@ -60,7 +60,6 @@ /// </summary> public float CurrScatteringRange { get; private set; } = 0; - //是否按下 private bool triggerFlag = false; //扳机计时器 @@ -83,73 +82,102 @@ private float continuousCount = 0; private bool continuousShootFlag = false; + private float floodlightTimer = -1; + public override void _Process(float delta) { - if (Master == null || Master.Holster.ActiveGun != this) - { - return; - } - if (triggerFlag) - { - if (upTimer > 0) //第一帧按下扳机 - { - upTimer = 0; - DownTrigger(); - } - downTimer += delta; - } - else - { - if (downTimer > 0) //第一帧松开扳机 - { - downTimer = 0; - UpTriggern(); - } - upTimer += delta; - } - // 攻击的计时器 - if (attackTimer > 0) + if (Master == null) //这把武器被扔在地上 { - attackTimer -= delta; - if (attackTimer < 0) + if (floodlightTimer < 0) { - delayedTime += attackTimer; - attackTimer = 0; + floodlightTimer = 3f; } - } - else if (delayedTime > 0) //攻击延时 - { - delayedTime -= delta; - if (attackTimer < 0) + else { - delayedTime = 0; + if (floodlightTimer >= 2.5f) { + // Mathf.Lerp(); + } + else if (floodlightTimer >= 2f) { + + } + floodlightTimer -= delta; } - } - //连发判断 - if (continuousCount > 0 && delayedTime <= 0 && attackTimer <= 0) - { - TriggernFire(); } + else if (Master.Holster.ActiveGun != this) //当前武器没有被使用 + { + triggerTimer = triggerTimer > 0 ? triggerTimer - delta : 0; + triggerFlag = false; + attackFlag = false; + attackTimer = attackTimer > 0 ? attackTimer - delta : 0; + continuousCount = 0; + delayedTime = 0; + } + else //正在使用中 + { + if (triggerFlag) + { + if (upTimer > 0) //第一帧按下扳机 + { + upTimer = 0; + DownTrigger(); + } + downTimer += delta; + } + else + { + if (downTimer > 0) //第一帧松开扳机 + { + downTimer = 0; + UpTriggern(); + } + upTimer += delta; + } - if (!attackFlag && attackTimer <= 0) - { - CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange); - } - triggerTimer = triggerTimer > 0 ? triggerTimer - delta : 0; - triggerFlag = false; - attackFlag = false; + // 攻击的计时器 + if (attackTimer > 0) + { + attackTimer -= delta; + if (attackTimer < 0) + { + delayedTime += attackTimer; + attackTimer = 0; + } + } + else if (delayedTime > 0) //攻击延时 + { + delayedTime -= delta; + if (attackTimer < 0) + { + delayedTime = 0; + } + } - //枪身回归 - Position = Position.MoveToward(Vector2.Zero, 35 * delta); - if (fireInterval == 0) - { - RotationDegrees = 0; - } - else - { - RotationDegrees = Mathf.Lerp(0, fireAngle, attackTimer / fireInterval); + //连发判断 + if (continuousCount > 0 && delayedTime <= 0 && attackTimer <= 0) + { + TriggernFire(); + } + + if (!attackFlag && attackTimer <= 0) + { + CurrScatteringRange = Mathf.Max(CurrScatteringRange - Attribute.ScatteringRangeBackSpeed * delta, Attribute.StartScatteringRange); + } + triggerTimer = triggerTimer > 0 ? triggerTimer - delta : 0; + triggerFlag = false; + attackFlag = false; + + //枪身回归 + Position = Position.MoveToward(Vector2.Zero, 35 * delta); + if (fireInterval == 0) + { + RotationDegrees = 0; + } + else + { + RotationDegrees = Mathf.Lerp(0, fireAngle, attackTimer / fireInterval); + } } } @@ -325,6 +353,16 @@ /// </summary> protected abstract void OnThrowOut(); + /// <summary> + /// 当武器被激活时调用, 也就是使用当武器是调用 + /// </summary> + protected abstract void OnActive(); + + /// <summary> + /// 当武器被收起时调用 + /// </summary> + protected abstract void OnConceal(); + public void _PickUpGun(Role master) { Master = master; @@ -337,6 +375,16 @@ OnThrowOut(); } + public void _Active() + { + OnActive(); + } + + public void _Conceal() + { + OnConceal(); + } + /// <summary> /// 实例化并返回子弹对象 /// </summary> diff --git a/src/weapon/gun/GunAttribute.cs b/src/weapon/gun/GunAttribute.cs index b69c394..5e5147b 100644 --- a/src/weapon/gun/GunAttribute.cs +++ b/src/weapon/gun/GunAttribute.cs @@ -6,6 +6,14 @@ public class GunAttribute { /// <summary> + /// 武器的唯一id + /// </summary> + public string Id = "1"; + /// <summary> + /// 武器显示的名称 + /// </summary> + public string Name = "Gun1"; + /// <summary> /// 主武器 /// </summary> public GunWeightType WeightType = GunWeightType.MainWeapon; diff --git a/src/weapon/gun/GunManager.cs b/src/weapon/gun/GunManager.cs index 826b956..761b3b1 100644 --- a/src/weapon/gun/GunManager.cs +++ b/src/weapon/gun/GunManager.cs @@ -10,6 +10,8 @@ var gun = ResourceManager.LoadGunAndInstance("res://prefab/weapon/Gun.tscn"); //设置基础属性 var attr = new GunAttribute(); + attr.Id = "1"; + attr.Name = "Gun1"; attr.StartFiringSpeed = 480; attr.StartScatteringRange = 30; attr.FinalScatteringRange = 90; @@ -47,6 +49,8 @@ var gun = ResourceManager.LoadGunAndInstance("res://prefab/weapon/Gun.tscn"); //设置基础属性 var attr = new GunAttribute(); + attr.Id = "2"; + attr.Name = "Gun2"; attr.WeightType = GunWeightType.DeputyWeapon; attr.StartFiringSpeed = 600; attr.StartScatteringRange = 5; diff --git a/src/weapon/gun/OrdinaryGun.cs b/src/weapon/gun/OrdinaryGun.cs index 3ced390..1934940 100644 --- a/src/weapon/gun/OrdinaryGun.cs +++ b/src/weapon/gun/OrdinaryGun.cs @@ -43,4 +43,14 @@ } + protected override void OnActive() + { + + } + + protected override void OnConceal() + { + + } + } \ No newline at end of file