diff --git a/DungeonShooting_Godot/scene/Room.tscn b/DungeonShooting_Godot/scene/Room.tscn index ca08ce2..aace2c2 100644 --- a/DungeonShooting_Godot/scene/Room.tscn +++ b/DungeonShooting_Godot/scene/Room.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=2] -[ext_resource path="res://resource/map/dungeon_1.tmx" type="PackedScene" id=1] +[ext_resource path="res://resource/map/dungeon_test.tmx" type="PackedScene" id=1] [ext_resource path="res://src/game/room/RoomManager.cs" type="Script" id=3] [ext_resource path="res://src/game/camera/GameCamera.cs" type="Script" id=5] @@ -11,7 +11,7 @@ [node name="Room" type="Navigation2D"] script = ExtResource( 3 ) ObjectRootPath = NodePath("ObjectRoot") -SortRootPath = NodePath("SortRoot") +YSortRootPath = NodePath("SortRoot") MapRootPath = NodePath("MapRoot") [node name="WorldEnvironment" type="WorldEnvironment" parent="."] @@ -20,7 +20,7 @@ [node name="MapRoot" type="Node2D" parent="."] z_index = -10 -[node name="dungeon_1" parent="MapRoot" instance=ExtResource( 1 )] +[node name="dungeon_test" parent="MapRoot" instance=ExtResource( 1 )] [node name="Camera2D" type="Camera2D" parent="."] position = Vector2( 253, 219 ) diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 33b637c..17f66f7 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -115,7 +115,7 @@ case "ShadowSprite": ShadowSprite = (Sprite)body; ShadowSprite.Visible = false; - ShadowSprite.ZIndex = -5; + //ShadowSprite.ZIndex = -5; break; case "Collision": Collision = (CollisionShape2D)body; @@ -456,24 +456,26 @@ { _throwData.LinearVelocity = MoveAndSlide(_throwData.LinearVelocity); GlobalRotationDegrees = GlobalRotationDegrees + _throwData.RotateSpeed * delta; - if (Scale.y < 0) - { - AnimatedSprite.GlobalPosition = GlobalPosition + new Vector2(0, -_throwData.Y) - _throwData.OriginSpritePosition.Rotated(Rotation) * Scale.Abs(); - } - else - { - AnimatedSprite.GlobalPosition = GlobalPosition + new Vector2(0, -_throwData.Y) + _throwData.OriginSpritePosition.Rotated(Rotation); - } + CalcThrowAnimatedPosition(); var ysp = _throwData.YSpeed; _throwData.Y += _throwData.YSpeed * delta; _throwData.YSpeed -= GameConfig.G * delta; + + //当高度大于16时, 显示在所有物体上 + if (_throwData.Y >= 16) + { + AnimatedSprite.ZIndex = 20; + } + else + { + AnimatedSprite.ZIndex = 0; + } //达到最高点 if (ysp * _throwData.YSpeed < 0) { - //ZIndex = 0; OnThrowMaxHeight(_throwData.Y); } @@ -623,6 +625,18 @@ ShadowSprite.GlobalPosition = pos + ShadowOffset; } } + + private void CalcThrowAnimatedPosition() + { + if (Scale.y < 0) + { + AnimatedSprite.GlobalPosition = GlobalPosition + new Vector2(0, -_throwData.Y) - _throwData.OriginSpritePosition.Rotated(Rotation) * Scale.Abs(); + } + else + { + AnimatedSprite.GlobalPosition = GlobalPosition + new Vector2(0, -_throwData.Y) + _throwData.OriginSpritePosition.Rotated(Rotation); + } + } /// <summary> @@ -675,20 +689,21 @@ { var parent = GetParent(); //投抛时必须要加入 sortRoot 节点下 - var root = GameApplication.Instance.Room.GetRoot(false); - var sortRoot = GameApplication.Instance.Room.GetRoot(true); + var root = GameApplication.Instance.Room.GetRoot(); + var throwRoot = GameApplication.Instance.Room.GetRoot(true); if (parent == null) { - sortRoot.AddChild(this); + throwRoot.AddChild(this); } else if (parent == root) { parent.RemoveChild(this); - sortRoot.AddChild(this); + throwRoot.AddChild(this); } GlobalPosition = _throwData.StartPosition; + CalcThrowAnimatedPosition(); //显示阴影 ShowShadowSprite(); } diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 09e3edb..44de124 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -289,7 +289,7 @@ base._EnterTree(); //收集落在地上的武器 - if (Master == null && GetParent() == GameApplication.Instance.Room.GetRoot(false)) + if (Master == null && GetParent() == GameApplication.Instance.Room.GetRoot()) { UnclaimedWeapons.Add(this); } diff --git a/DungeonShooting_Godot/src/game/role/PathSign.cs b/DungeonShooting_Godot/src/game/role/PathSign.cs index cf8f654..3b1d943 100644 --- a/DungeonShooting_Godot/src/game/role/PathSign.cs +++ b/DungeonShooting_Godot/src/game/role/PathSign.cs @@ -140,7 +140,7 @@ if (_isInRange && !_isCollision && Next == null) //如果上一帧就在视野内, 才能创建新的折点 { var distance = Mathf.Sqrt(distanceSquared); - Next = new PathSign(GameApplication.Instance.Room.GetRoot(false), _targetPos, ViewRadius - distance, Target, Index + 1); + Next = new PathSign(GameApplication.Instance.Room.GetRoot(), _targetPos, ViewRadius - distance, Target, Index + 1); Next._targetPos = nowTargetPos; Next.Enable = true; } diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 827fe5d..2a20736 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -9,7 +9,7 @@ public class RoomManager : Navigation2D { [Export] public NodePath ObjectRootPath; - [Export] public NodePath SortRootPath; + [Export] public NodePath YSortRootPath; [Export] public NodePath MapRootPath; /// <summary> @@ -27,7 +27,7 @@ //对象根节点, 带y轴排序功能 private YSort _sortRoot; - + private Node2D _mapRoot; //可行走区域的tileId @@ -46,7 +46,7 @@ //Engine.TimeScale = 0.2f; Input.MouseMode = Input.MouseModeEnum.Hidden; - _sortRoot = GetNode<YSort>(SortRootPath); + _sortRoot = GetNode<YSort>(YSortRootPath); _objectRoot = GetNode<Node2D>(ObjectRootPath); NavigationPolygon = new NavigationPolygonInstance();