diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 54f74f9..df9ff53 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -32,6 +32,9 @@ private List> _components = new List>(); private bool initShadow; private string _prevAnimation; + + //存储投抛该物体时所产生的数据 + private ObjectThrowData _throwData; public ActivityObject(string scenePath) { @@ -141,6 +144,44 @@ /// 触发者 public abstract void Interactive(ActivityObject master); + /// + /// 投抛该物体达到最高点时调用 + /// + public virtual void OnMaxHeight(float height) + { + + } + + public virtual void PickUp() + { + + } + + public virtual void PickDown() + { + + } + + public virtual void Throw(Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) + { + + } + + public virtual void StopThrow() + { + + } + + /// + /// 结束的调用 + /// + public virtual void OnOver() + { + GetParent().RemoveChild(this); + RoomManager.Current.ObjectRoot.AddChild(this); + Collision.Disabled = true; + } + public void AddComponent(Component component) { if (!ContainsComponent(component)) @@ -183,22 +224,56 @@ public override void _Process(float delta) { - var arr = _components.ToArray(); - for (int i = 0; i < arr.Length; i++) + //更新组件 + if (_components.Count > 0) { - if (IsDestroyed) return; - var temp = arr[i].Value; - if (temp != null && temp.ActivityObject == this && temp.Enable) + var arr = _components.ToArray(); + for (int i = 0; i < arr.Length; i++) { - if (!temp.IsStart) + if (IsDestroyed) return; + var temp = arr[i].Value; + if (temp != null && temp.ActivityObject == this && temp.Enable) { - temp.Start(); - } + if (!temp.IsStart) + { + temp.Start(); + } - temp.Update(delta); + temp.Update(delta); + } } } + + //投抛计算 + if (_throwData != null && !_throwData.IsOver) + { + MoveAndSlide(new Vector2(_throwData.XSpeed, 0).Rotated(_throwData.Direction * Mathf.Pi / 180)); + Position = new Vector2(0, Position.y - _throwData.YSpeed * delta); + var rotate = GlobalRotationDegrees + _throwData.RotateSpeed * delta; + GlobalRotationDegrees = rotate; + //计算阴影位置 + ShadowSprite.GlobalRotationDegrees = rotate; + // ShadowSprite.GlobalRotationDegrees = rotate + (inversionX ? 180 : 0); + ShadowSprite.GlobalPosition = AnimatedSprite.GlobalPosition + new Vector2(0, 2 - Position.y); + var ysp = _throwData.YSpeed; + _throwData.YSpeed -= GameConfig.G * delta; + //达到最高点 + if (ysp * _throwData.YSpeed < 0) + { + OnMaxHeight(-Position.y); + } + + //落地判断 + if (Position.y >= 0) + { + Position = new Vector2(0, 0); + _throwData.IsOver = true; + OnOver(); + } + } + + //更新阴影贴图, 使其和动画一致 if (ShadowSprite.Visible) { var anim = AnimatedSprite.Animation; diff --git a/DungeonShooting_Godot/src/framework/ObjectThrowData.cs b/DungeonShooting_Godot/src/framework/ObjectThrowData.cs new file mode 100644 index 0000000..5778f5e --- /dev/null +++ b/DungeonShooting_Godot/src/framework/ObjectThrowData.cs @@ -0,0 +1,54 @@ +using Godot; + +public class ObjectThrowData +{ + /// + /// 是否已经结束 + /// + public bool IsOver = true; + + /// + /// 物体大小 + /// + public Vector2 Size = Vector2.One; + + /// + /// 起始坐标 + /// + public Vector2 StartPosition; + + /// + /// 移动方向, 0 - 360 + /// + public float Direction; + + /// + /// x速度, 也就是水平速度 + /// + public float XSpeed; + + /// + /// y轴速度, 也就是竖直速度 + /// + public float YSpeed; + + /// + /// 初始x轴组队 + /// + public float StartXSpeed; + + /// + /// 初始y轴速度 + /// + public float StartYSpeed; + + /// + /// 旋转速度 + /// + public float RotateSpeed; + + /// + /// 碰撞器形状 + /// + public RectangleShape2D RectangleShape; +} \ No newline at end of file