diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 0f23d5f..7abea5b 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -103,6 +103,9 @@ } _prevAnimation = anim; + ShadowSprite.Scale = AnimatedSprite.Scale; + ShadowSprite.Rotation = AnimatedSprite.Rotation; + ShadowSprite.Position = AnimatedSprite.Position + new Vector2(0, Thickness); ShadowSprite.Visible = true; } @@ -192,14 +195,49 @@ } - public void PickUp() + /// + /// 拾起一个 node 节点 + /// + public void Pickup() { - + var parent = GetParent(); + if (parent != null) + { + if (IsThrowing) + { + StopThrow(); + } + parent.RemoveChild(this); + } } - public void PickDown() + /// + /// 将一个节点扔到地上, 并设置显示的阴影 + /// + public void PutDown() { + var parent = GetParent(); + if (parent != RoomManager.Current.ObjectRoot) + { + if (parent != null) + { + parent.RemoveChild(this); + } + RoomManager.Current.ObjectRoot.AddChild(this); + } + + ShowShadowSprite(); + } + + /// + /// 将一个节点扔到地上, 并设置显示的阴影 + /// + /// 放置的位置 + public void PutDown(Vector2 position) + { + PutDown(); + Position = position; } /// @@ -471,7 +509,6 @@ //显示阴影 ShowShadowSprite(); - ShadowSprite.Scale = AnimatedSprite.Scale; } /// diff --git a/DungeonShooting_Godot/src/game/common/NodeExtend.cs b/DungeonShooting_Godot/src/game/common/NodeExtend.cs index b42605f..bd54eee 100644 --- a/DungeonShooting_Godot/src/game/common/NodeExtend.cs +++ b/DungeonShooting_Godot/src/game/common/NodeExtend.cs @@ -6,67 +6,6 @@ /// public static class NodeExtend { - - public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) - { - return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate); - } - - public static T StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) where T : ThrowNode - { - return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, null); - } - - public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) - { - return StartThrow(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, shadowTarget); - } - - public static T StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) where T : ThrowNode - { - ThrowNode throwNode = node.GetParentOrNull(); - T inst; - if (throwNode == null) - { - inst = Activator.CreateInstance(); - } - else if (throwNode is T) - { - inst = throwNode as T; - } - else - { - throwNode.StopThrow(); - inst = Activator.CreateInstance(); - } - inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node, shadowTarget); - return inst; - } - - /// - /// 将一个节点扔到地上, 并设置显示的阴影, 函数返回根据该节点创建的 ThrowNode 节点 - /// - public static ThrowNode PutDown(this ActivityObject node) - { - //return StartThrow(node, Vector2.Zero, node.Position, 0, 0, 0, 0, 0, shadowTarget); - RoomManager.Current.ObjectRoot.AddChild(node); - return null; - } - - /// - /// 拾起一个 node 节点, 返回是否拾起成功 - /// - public static bool Pickup(this Node2D node) - { - ThrowNode parent = node.GetParentOrNull(); - if (parent != null) - { - parent.StopThrow(); - return true; - } - return false; - } - /// /// 尝试将一个node2d节点转换成一个 ActivityObject 类 /// diff --git a/DungeonShooting_Godot/src/game/item/ThrowNode.cs b/DungeonShooting_Godot/src/game/item/ThrowNode.cs deleted file mode 100644 index a5ebe35..0000000 --- a/DungeonShooting_Godot/src/game/item/ThrowNode.cs +++ /dev/null @@ -1,265 +0,0 @@ -using Godot; - -/// -/// 模拟抛出的物体, 使用时将对象挂载到该节点上即可 -/// -public class ThrowNode : KinematicBody2D -{ - /// - /// 是否已经结束 - /// - public bool IsOver { get; protected set; } = true; - /// - /// 物体大小 - /// - public Vector2 Size { get; protected set; } - /// - /// 起始坐标 - /// - public Vector2 StartPosition { get; protected set; } - /// - /// 移动方向, 0 - 360 - /// - public float Direction { get; protected set; } - /// - /// x速度, 也就是水平速度 - /// - public float XSpeed { get; protected set; } - /// - /// y轴速度, 也就是竖直速度 - /// - public float YSpeed { get; protected set; } - /// - /// 初始x轴组队 - /// - public float StartXSpeed { get; protected set; } - /// - /// 初始y轴速度 - /// - public float StartYSpeed { get; protected set; } - /// - /// 旋转速度 - /// - public float RotateSpeed { get; protected set; } - /// - /// 挂载的对象 - /// - public Node2D Mount { get; protected set; } - /// - /// 碰撞组件 - /// - public CollisionShape2D CollisionShape { get; protected set; } - /// - /// 绘制阴影的精灵 - /// - public Sprite ShadowSprite { get; protected set; } - - protected Sprite ShadowTarget { get; set; } - - private bool inversionX = false; - - public ThrowNode() - { - Name = "ThrowNode"; - } - - public override void _Ready() - { - //只与墙壁碰撞 - CollisionMask = 1; - CollisionLayer = 0; - //创建碰撞器 - if (Size != Vector2.Zero) - { - CollisionShape = new CollisionShape2D(); - CollisionShape.Name = "Collision"; - var shape = new RectangleShape2D(); - shape.Extents = Size * 0.5f; - CollisionShape.Shape = shape; - AddChild(CollisionShape); - } - } - - /// - /// 初始化该抛物线对象的基础数据 - /// - /// 抛射的物体所占大小, 用于碰撞检测 - /// 起始点 - /// 起始高度 - /// 角度, 0 - 360 - /// 横轴速度 - /// 纵轴速度 - /// 旋转速度 - /// 需要挂载的节点 - /// 抛射的节点显示的纹理, 用于渲染阴影用 - public virtual void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Node2D mount) - { - if (CollisionShape != null) - { - CollisionShape.Disabled = false; - } - - IsOver = false; - Size = size; - GlobalPosition = StartPosition = start; - Direction = direction; - XSpeed = xSpeed; - YSpeed = ySpeed; - StartXSpeed = xSpeed; - StartYSpeed = ySpeed; - RotateSpeed = rotate; - - if (mount != null) - { - Mount = mount; - var mountParent = mount.GetParent(); - if (mountParent == null) - { - AddChild(mount); - } - else if (mountParent != this) - { - mountParent.RemoveChild(mount); - AddChild(mount); - } - mount.Position = new Vector2(0, -startHeight); - } - var parent = GetParent(); - if (parent == null) - { - RoomManager.Current.SortRoot.AddChild(this); - } - else if (parent == RoomManager.Current.SortRoot) - { - parent.RemoveChild(this); - RoomManager.Current.SortRoot.AddChild(this); - } - } - - /// - /// 初始化该抛物线对象的基础数据, 并且渲染阴影 - /// - /// 抛射的物体所占大小, 用于碰撞检测 - /// 起始点 - /// 起始高度 - /// 角度, 0 - 360 - /// 横轴速度 - /// 纵轴速度 - /// 旋转速度 - /// 需要挂载的节点 - /// 抛射的节点显示的纹理, 用于渲染阴影用 - public virtual void StartThrow(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, - float ySpeed, float rotate, Node2D mount, Sprite shadowTarget) - { - StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, mount); - ShadowTarget = shadowTarget; - if (shadowTarget != null) - { - if (ShadowSprite == null) - { - //阴影 - ShadowSprite = new Sprite(); - ShadowSprite.Name = "Shadow"; - ShadowSprite.ZIndex = -5; - ShadowSprite.Material = ResourceManager.ShadowMaterial; - AddChild(ShadowSprite); - } - - inversionX = mount.Scale.y < 0 ? true : false; - if (inversionX) - { - ShadowSprite.Scale = shadowTarget.Scale * new Vector2(1, -1); - } - else - { - ShadowSprite.Scale = shadowTarget.Scale; - } - - ShadowSprite.Texture = shadowTarget.Texture; - } - else if (ShadowSprite != null) - { - ShadowSprite.Texture = null; - } - } - - /// - /// 停止投抛运动 - /// - public Node2D StopThrow() - { - var mount = Mount; - var parent = GetParent(); - if (parent != null && mount != null) - { - var gp = mount.GlobalPosition; - var gr = mount.GlobalRotation; - IsOver = true; - Mount = null; - RemoveChild(mount); - parent.AddChild(mount); - mount.GlobalPosition = gp; - mount.GlobalRotation = gr; - } - QueueFree(); - return mount; - } - - /// - /// 达到最高点时调用 - /// - protected virtual void OnMaxHeight(float height) - { - - } - - /// - /// 结束的调用 - /// - protected virtual void OnOver() - { - GetParent().RemoveChild(this); - RoomManager.Current.ObjectRoot.AddChild(this); - if (CollisionShape != null) - { - CollisionShape.Disabled = true; - } - } - - public override void _Process(float delta) - { - if (!IsOver) - { - if (Mount == null) - { - QueueFree(); - return; - } - MoveAndSlide(new Vector2(XSpeed, 0).Rotated(Direction * Mathf.Pi / 180)); - Mount.Position = new Vector2(0, Mount.Position.y - YSpeed * delta); - var rotate = Mount.GlobalRotationDegrees + RotateSpeed * delta; - Mount.GlobalRotationDegrees = rotate; - if (ShadowSprite != null) - { - ShadowSprite.GlobalRotationDegrees = rotate; - // ShadowSprite.GlobalRotationDegrees = rotate + (inversionX ? 180 : 0); - ShadowSprite.GlobalPosition = ShadowTarget.GlobalPosition + new Vector2(0, 1 - Mount.Position.y); - } - var ysp = YSpeed; - YSpeed -= GameConfig.G * delta; - //达到最高点 - if (ysp * YSpeed < 0) - { - OnMaxHeight(-Mount.Position.y); - } - //落地判断 - if (Mount.Position.y >= 0) - { - Mount.Position = new Vector2(0, 0); - IsOver = true; - OnOver(); - } - } - } - -} \ 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 e76045b..4daf016 100644 --- a/DungeonShooting_Godot/src/game/item/package/Holster.cs +++ b/DungeonShooting_Godot/src/game/item/package/Holster.cs @@ -158,7 +158,7 @@ ActiveWeapon = null; } } - weapon._ThrowOutWeapon(); + weapon._Remove(); return weapon; } diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index 6d94c5c..1db9219 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -184,9 +184,9 @@ protected abstract void OnPickUp(Role master); /// - /// 当武器从武器袋中扔掉时调用 + /// 当武器从武器袋中移除时调用 /// - protected abstract void OnThrowOut(); + protected abstract void OnRemove(); /// /// 当武器被激活时调用, 也就是使用当武器是调用 @@ -475,7 +475,7 @@ /// 拾起的弹药数量, 如果到达容量上限, 则返回拾取完毕后剩余的弹药数量 /// /// 弹药数量 - public int PickUpAmmo(int count) + private int PickUpAmmo(int count) { var num = ResidueAmmo; ResidueAmmo = Mathf.Min(ResidueAmmo + count, Attribute.MaxAmmoCapacity - CurrAmmo); @@ -719,14 +719,14 @@ } /// - /// 触发抛出 + /// 触发移除 /// a - public void _ThrowOutWeapon() + public void _Remove() { Master = null; AnimatedSprite.Position = Attribute.CenterPosition; AnimationPlayer.Play("Floodlight"); - OnThrowOut(); + OnRemove(); } /// diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs index 59d7abb..476990e 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs @@ -138,7 +138,7 @@ } - protected override void OnThrowOut() + protected override void OnRemove() { } diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs index 42e9e93..608704e 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs @@ -108,7 +108,7 @@ } - protected override void OnThrowOut() + protected override void OnRemove() { } diff --git a/DungeonShooting_Godot/src/game/item/weapon/shell/ThrowShell.cs b/DungeonShooting_Godot/src/game/item/weapon/shell/ThrowShell.cs deleted file mode 100644 index 914ee5d..0000000 --- a/DungeonShooting_Godot/src/game/item/weapon/shell/ThrowShell.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Godot; - -/// -/// 弹壳 -/// -public class ThrowShell : ThrowNode -{ - - public override void _Ready() - { - base._Ready(); - ZIndex = 2; - } - - protected override void OnOver() - { - //如果落地高度不够低, 再抛一次 - if (StartYSpeed > 1) - { - StartThrow(Size, GlobalPosition, 0, Direction, XSpeed * 0.8f, StartYSpeed * 0.5f, RotateSpeed * 0.5f, null); - } - else - { - base.OnOver(); - //等待被销毁 - AwaitDestroy(); - } - } - - private async void AwaitDestroy() - { - CollisionShape.Disabled = true; - //60秒后销毁 - await ToSignal(GetTree().CreateTimer(60), "timeout"); - QueueFree(); - } - - protected override void OnMaxHeight(float height) - { - ZIndex = 0; - } -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 0105d8f..53df77d 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -50,20 +50,18 @@ //播放bgm SoundManager.PlayeMusic("intro.ogg", this, -17f); var gun1 = WeaponManager.GetGun("1001"); - gun1.Position = new Vector2(80, 80); - gun1.PutDown(); + gun1.PutDown(new Vector2(80, 80)); var gun2 = WeaponManager.GetGun("1002"); - gun2.Position = new Vector2(80, 120); - gun2.PutDown(); + gun2.PutDown(new Vector2(80, 120)); var gun3 = WeaponManager.GetGun("1003"); - gun3.Position = new Vector2(120, 80); - gun3.PutDown(); - // var gun4 = WeaponManager.GetGun4(); - // gun4.Position = new Vector2(120, 120); - // gun4.PutDown(gun4.WeaponSprite); - // var gun5 = WeaponManager.GetGun5(); - // gun5.Position = new Vector2(160, 160); - // gun5.PutDown(gun5.WeaponSprite); + gun3.PutDown(new Vector2(120, 80)); + + var gun4 = WeaponManager.GetGun("1003"); + gun4.PutDown(new Vector2(180, 80)); + var gun5 = WeaponManager.GetGun("1003"); + gun5.PutDown(new Vector2(180, 180)); + var gun6 = WeaponManager.GetGun("1002"); + gun6.PutDown(new Vector2(180, 120)); } public override void _Process(float delta)