diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs index 1f1ba31..5c2948c 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs @@ -9,6 +9,12 @@ public class ActivityObjectTemplate : Node { /// + /// 是否放入 ySort 节点下 + /// + [Export] + public bool UseYSort; + + /// /// 当前物体所属物理层 /// [Export(PropertyHint.Layers2dPhysics)] diff --git a/DungeonShooting_Godot/prefab/role/Enemy.tscn b/DungeonShooting_Godot/prefab/role/Enemy.tscn index ab2568d..98ed763 100644 --- a/DungeonShooting_Godot/prefab/role/Enemy.tscn +++ b/DungeonShooting_Godot/prefab/role/Enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] [ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=2] @@ -9,6 +9,12 @@ shader_param/shadowColor = Color( 0, 0, 0, 0.470588 ) shader_param/schedule = 1.0 +[sub_resource type="ShaderMaterial" id=2] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/shadowColor = Color( 1, 1, 1, 1 ) +shader_param/schedule = 0.0 + [node name="Enemy" instance=ExtResource( 1 )] CollisionLayer = 16 @@ -16,4 +22,5 @@ material = SubResource( 1 ) [node name="AnimatedSprite" parent="." index="2"] -frame = 1 +material = SubResource( 2 ) +frame = 2 diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index b8da7fd..9bf6662 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] [ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=2] @@ -9,8 +9,18 @@ shader_param/shadowColor = Color( 0, 0, 0, 0.8 ) shader_param/schedule = 1.0 +[sub_resource type="ShaderMaterial" id=2] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/shadowColor = Color( 1, 1, 1, 1 ) +shader_param/schedule = 0.0 + [node name="Player" instance=ExtResource( 1 )] CollisionLayer = 8 [node name="ShadowSprite" parent="." index="0"] material = SubResource( 1 ) + +[node name="AnimatedSprite" parent="." index="2"] +material = SubResource( 2 ) +frame = 0 diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index 3f695f1..4fd8304 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -115,8 +115,8 @@ [node name="Role" type="Node"] script = ExtResource( 2 ) +UseYSort = true CollisionMask = 1 -ZIndex = 1 [node name="ShadowSprite" type="Sprite" parent="."] material = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn index 8b7d59f..3046379 100644 --- a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn +++ b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn @@ -113,3 +113,4 @@ [node name="InteractiveTipBar" parent="ViewNode" instance=ExtResource( 10 )] [node name="ReloadBar" parent="ViewNode" instance=ExtResource( 3 )] +z_index = 15 diff --git a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn index 7acefc4..ffdb65c 100644 --- a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn +++ b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn @@ -61,8 +61,6 @@ collision_mask = 0 [node name="AnimationPlayer" type="AnimationPlayer" parent="WeaponBody"] -autoplay = "Floodlight" -playback_process_mode = 0 anims/Floodlight = SubResource( 3 ) anims/RESET = SubResource( 4 ) diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index c8d5dbc..9a98941 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -15,6 +15,11 @@ public string ItemId { get; internal set; } /// + /// 是否放入 ySort 节点下 + /// + public bool UseYSort { get; } + + /// /// 当前物体显示的精灵图像, 节点名称必须叫 "AnimatedSprite", 类型为 AnimatedSprite /// public AnimatedSprite AnimatedSprite { get; } @@ -65,6 +70,7 @@ ZIndex = tempNode.ZIndex; CollisionLayer = tempNode.CollisionLayer; CollisionMask = tempNode.CollisionMask; + UseYSort = tempNode.UseYSort; //移动子节点 var count = tempNode.GetChildCount(); @@ -215,10 +221,10 @@ /// /// 将一个节点扔到地上, 并设置显示的阴影 /// - public void PutDown() + public virtual void PutDown() { var parent = GetParent(); - var root = GameApplication.Instance.Room.ObjectRoot; + var root = GameApplication.Instance.Room.GetRoot(UseYSort); if (parent != root) { if (parent != null) @@ -528,15 +534,17 @@ private void Throw() { var parent = GetParent(); - var room = GameApplication.Instance.Room; + //投抛时必须要加入 sortRoot 节点下 + var root = GameApplication.Instance.Room.GetRoot(false); + var sortRoot = GameApplication.Instance.Room.GetRoot(true); if (parent == null) { - room.SortRoot.AddChild(this); + sortRoot.AddChild(this); } - else if (parent == room.ObjectRoot) + else if (parent == root) { parent.RemoveChild(this); - room.SortRoot.AddChild(this); + sortRoot.AddChild(this); } GlobalPosition = _throwData.StartPosition + new Vector2(0, -_throwData.Y); @@ -573,7 +581,8 @@ //Collision.Position = Vector2.Zero; Collision.Rotation = 0; Collision.Scale = Vector2.One; - ZIndex = 2; + ZIndex = 0; + //ZIndex = 2; Collision.Disabled = false; Collision.Position = Vector2.Zero; Collision.Rotation = 0; @@ -613,7 +622,7 @@ private void ThrowOver() { GetParent().RemoveChild(this); - GameApplication.Instance.Room.ObjectRoot.AddChild(this); + GameApplication.Instance.Room.GetRoot(UseYSort).AddChild(this); RestoreCollision(); OnThrowOver(); diff --git a/DungeonShooting_Godot/src/game/item/package/Holster.cs b/DungeonShooting_Godot/src/game/item/package/Holster.cs index bd1f243..606b519 100644 --- a/DungeonShooting_Godot/src/game/item/package/Holster.cs +++ b/DungeonShooting_Godot/src/game/item/package/Holster.cs @@ -114,6 +114,11 @@ /// 武器对象 public int PickupWeapon(Weapon weapon) { + //已经被拾起了 + if (weapon.Master != null) + { + return -1; + } for (int i = 0; i < SlotList.Length; i++) { var item = SlotList[i]; diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index eeb710d..25130c3 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -750,6 +750,13 @@ { //启用碰撞 CollisionShape2D.Disabled = false; + AnimationPlayer.Play("Floodlight"); + } + + public override void PutDown() + { + base.PutDown(); + AnimationPlayer.Play("Floodlight"); } /// @@ -778,7 +785,6 @@ { Master = null; AnimatedSprite.Position = Attribute.CenterPosition; - AnimationPlayer.Play("Floodlight"); OnRemove(); } @@ -826,7 +832,7 @@ bullet.GlobalRotation = globalRotation; if (parent == null) { - GameApplication.Instance.Room.SortRoot.AddChild(bullet); + GameApplication.Instance.Room.GetRoot(true).AddChild(bullet); } else { diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs index 2f51ecb..3560555 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs @@ -85,7 +85,7 @@ Node2D hit = Hit.Instance(); hit.RotationDegrees = MathUtils.RandRangeInt(0, 360); hit.GlobalPosition = pos; - GameApplication.Instance.Room.SortRoot.AddChild(hit); + GameApplication.Instance.Room.GetRoot(true).AddChild(hit); QueueFree(); } else //没有碰到, 继续移动 diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index cdb4a49..04e874d 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -6,8 +6,8 @@ public class RoomManager : Node2D { public Player Player { get; private set; } - public Node2D ObjectRoot { get; private set; } - public YSort SortRoot { get; private set; } + private Node2D ObjectRoot; + private YSort SortRoot; private Enemy _enemy; @@ -31,9 +31,8 @@ Player.PutDown(); _enemy = new Enemy(); + _enemy.Name = "Enemy"; _enemy.PutDown(new Vector2(150, 150)); - - } public override void _Ready() @@ -57,4 +56,14 @@ { } + + /// + /// 获取房间根节点 + /// + /// + /// + public Node2D GetRoot(bool useYSort) + { + return useYSort ? SortRoot : ObjectRoot; + } } \ No newline at end of file