diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index 25ff66f..cfc566b 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -16,4 +16,4 @@ material = SubResource( 1 ) [node name="AnimatedSprite" parent="." index="2"] -frame = 3 +frame = 2 diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index 7b06e6f..0f97dd9 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -91,7 +91,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" -frame = 3 +frame = 1 playing = true [node name="Collision" type="CollisionShape2D" parent="."] diff --git a/DungeonShooting_Godot/resource/materlal/Shadow.tres b/DungeonShooting_Godot/resource/materlal/Shadow.tres index df4a9bf..5b36159 100644 --- a/DungeonShooting_Godot/resource/materlal/Shadow.tres +++ b/DungeonShooting_Godot/resource/materlal/Shadow.tres @@ -5,5 +5,5 @@ [resource] resource_local_to_scene = true shader = ExtResource( 1 ) -shader_param/shadowColor = Color( 0, 0, 0, 0.8 ) +shader_param/shadowColor = Color( 0, 0, 0, 0.470588 ) shader_param/schedule = 1.0 diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 7abea5b..0d2588f 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -35,13 +35,14 @@ public bool IsThrowing => _throwData != null && !_throwData.IsOver; /// - /// 物体厚度, 影响阴影偏移 + /// 阴影偏移 /// - public int Thickness { get; protected set; } = 2; - + public Vector2 ShadowOffset { get; protected set; } = new Vector2(0, 2); + private List> _components = new List>(); private bool initShadow; private string _prevAnimation; + private int _prevAnimationFrame; //存储投抛该物体时所产生的数据 private ObjectThrowData _throwData; @@ -96,16 +97,16 @@ } var anim = AnimatedSprite.Animation; - if (_prevAnimation != anim) + var frame = AnimatedSprite.Frame; + if (_prevAnimation != anim || _prevAnimationFrame != frame) { //切换阴影动画 - ShadowSprite.Texture = AnimatedSprite.Frames.GetFrame(anim, AnimatedSprite.Frame); + ShadowSprite.Texture = AnimatedSprite.Frames.GetFrame(anim, frame); } - _prevAnimation = anim; - ShadowSprite.Scale = AnimatedSprite.Scale; - ShadowSprite.Rotation = AnimatedSprite.Rotation; - ShadowSprite.Position = AnimatedSprite.Position + new Vector2(0, Thickness); + _prevAnimationFrame = frame; + + CalcShadow(); ShadowSprite.Visible = true; } @@ -160,7 +161,7 @@ /// 触发者 public virtual void Interactive(ActivityObject master) { - + } /// @@ -194,7 +195,7 @@ { } - + /// /// 拾起一个 node 节点 /// @@ -207,6 +208,7 @@ { StopThrow(); } + parent.RemoveChild(this); } } @@ -226,10 +228,10 @@ RoomManager.Current.ObjectRoot.AddChild(this); } - + ShowShadowSprite(); } - + /// /// 将一个节点扔到地上, 并设置显示的阴影 /// @@ -380,9 +382,8 @@ //落地判断 if (_throwData.Y <= 0) { - ShadowSprite.GlobalPosition = pos + new Vector2(0, Thickness); Collision.GlobalPosition = pos; - + _throwData.IsOver = true; //第一次接触地面 @@ -416,24 +417,48 @@ } else { - //计算阴影位置 - ShadowSprite.GlobalPosition = pos + new Vector2(0, Thickness + _throwData.Y); //碰撞器位置 Collision.GlobalPosition = pos + new Vector2(0, _throwData.Y); } } - //更新阴影贴图, 使其和动画一致 if (ShadowSprite.Visible) { + //更新阴影贴图, 使其和动画一致 var anim = AnimatedSprite.Animation; - if (_prevAnimation != anim) + var frame = AnimatedSprite.Frame; + if (_prevAnimation != anim || _prevAnimationFrame != frame) { //切换阴影动画 ShadowSprite.Texture = AnimatedSprite.Frames.GetFrame(anim, AnimatedSprite.Frame); } - _prevAnimation = anim; + _prevAnimationFrame = frame; + + //计算阴影 + CalcShadow(); + } + + } + + /// + /// 重新计算物体阴影的位置和旋转信息, 无论是否显示阴影 + /// + public void CalcShadow() + { + //缩放 + ShadowSprite.Scale = AnimatedSprite.Scale; + //阴影角度 + ShadowSprite.GlobalRotationDegrees = GlobalRotationDegrees; + //阴影位置计算 + var pos = AnimatedSprite.GlobalPosition; + if (_throwData != null && !_throwData.IsOver) + { + ShadowSprite.GlobalPosition = new Vector2(pos.x + ShadowOffset.x, pos.y + ShadowOffset.y + _throwData.Y); + } + else + { + ShadowSprite.GlobalPosition = pos + ShadowOffset; } } @@ -510,7 +535,7 @@ //显示阴影 ShowShadowSprite(); } - + /// /// 设置投抛状态下的碰撞器 /// @@ -581,7 +606,7 @@ GetParent().RemoveChild(this); RoomManager.Current.ObjectRoot.AddChild(this); RestoreCollision(); - + OnThrowOver(); } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/package/Holster.cs b/DungeonShooting_Godot/src/game/item/package/Holster.cs index 4daf016..f26c086 100644 --- a/DungeonShooting_Godot/src/game/item/package/Holster.cs +++ b/DungeonShooting_Godot/src/game/item/package/Holster.cs @@ -121,8 +121,8 @@ { weapon.Pickup(); item.Weapon = weapon; - ExchangeByIndex(i); weapon._PickUpWeapon(Master); + ExchangeByIndex(i); return i; } } diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 1db9219..3ee09af 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -680,6 +680,9 @@ /// 触发扔掉该武器的的角色 public void TriggerThrowWeapon(Role master) { + //阴影偏移 + ShadowOffset = new Vector2(0, 2); + if (master.Face == FaceDirection.Left) { Scale *= new Vector2(1, -1); @@ -734,6 +737,8 @@ /// public void _Active() { + ShadowOffset = new Vector2(0, Master.GlobalPosition.y - GlobalPosition.y); + ShowShadowSprite(); OnActive(); } @@ -742,6 +747,7 @@ /// public void _Conceal() { + HideShadowSprite(); OnConceal(); } diff --git a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs index 22f22e4..4a7fdff 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs @@ -1,9 +1,11 @@  +using Godot; + public class ShellCase : ActivityObject { public ShellCase() : base("res://prefab/weapon/shell/ShellCase.tscn") { - Thickness = 1; + ShadowOffset = new Vector2(0, 1); } public override void OnThrowOver() diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 53df77d..d0a656c 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -42,7 +42,8 @@ var player = new Player(); player.Position = new Vector2(100, 100); player.Name = "Player"; - SortRoot.AddChild(player); + //SortRoot.AddChild(player); + player.PutDown(); } public override void _Ready()