using StgSharp_Logic; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StgSharp_Entity { public class Bullet:LinkedTarget { //子弹的缩放比例 private float _size; public float Size { get { return _size; } set { if (value > 0) { _size = value; this.Radius = DefualtRadius * Size; } else { throw new ArgumentException("Size cannot be smaller than zero!"); } } } //该种类子弹的默认大小 private static float _defualtRadius; public static float DefualtRadius { get { return _defualtRadius; } set { _defualtRadius = value; } } //子弹的实际判定半径 private float _radius; public float Radius { get { return _radius; } set { _radius = value; } } //子弹x轴运动的函数表达 private float[] _xVelocity; public float[] XVelocity { get { return _xVelocity; } set { if (value.Length==10) { _xVelocity = value; } else { throw new ArgumentException("Too many or too few parameters!"); } } } //子弹y轴运动的函数表达 private float[] _yVelocity; public float[] YVelocity { get { return _yVelocity; } set { if (value.Length == 10) { _yVelocity = value; } else { throw new ArgumentException("Too many or too few parameters!"); } } } private float _xVertical; //xy坐标 public float XVertical { get { return _xVertical; } set { _xVertical = value; } } private float _yVertical; public float YVertical { get { return _yVertical; } set { _yVertical = value; } } private uint _beginTick; public uint BeginTick { get { return _beginTick; } set { _beginTick = value; } } //通过传入的时间刻计算位移并更新位置坐标 public void move(uint tick) { float deltaTick = tick - _beginTick; float deltaX = 0; for (int i = 0; i < 10; i++) { deltaX += _xVelocity[i]; deltaX *= deltaTick; } deltaX += _xVelocity[10]; _xVertical += deltaX; float deltaY = 0; for (int i = 0; i < 10; i++) { deltaY += _yVelocity[i]; deltaY *= deltaTick; } deltaY += _yVelocity[10]; _yVertical += deltaY; } public Bullet() { } /// /// 修改自身路径,修改条件由外部逻辑判断触发 /// public void ChangeVelocity(float[] newXSpeed,float[] newYSpeed) { if (newXSpeed != null) { if (newXSpeed.Length == 10) { this._xVelocity = newXSpeed; } else { throw new Exception("The amount of parameters should be 10!"); } } if (newYSpeed != null) { if (newYSpeed.Length == 10) { this._yVelocity = newYSpeed; } else { throw new Exception("The amount of parameters should be 10!"); } } } } }