daily update on 20230301 by nitload youmu, file struct cahnged and more vec func added
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
using StgSharp_Logic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp_Entity
|
||||
{
|
||||
|
||||
public unsafe 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* _x;
|
||||
|
||||
//xy坐标
|
||||
public float* X
|
||||
{
|
||||
get { return _x; }
|
||||
set { _x = value; }
|
||||
}
|
||||
|
||||
private float* _y;
|
||||
|
||||
public float* Y
|
||||
{
|
||||
get { return _y; }
|
||||
set { _y = value; }
|
||||
}
|
||||
|
||||
private uint _beginTick;
|
||||
|
||||
public uint BeginTick
|
||||
{
|
||||
get { return _beginTick; }
|
||||
set { _beginTick = value; }
|
||||
}
|
||||
|
||||
public Bullet()
|
||||
{
|
||||
}
|
||||
|
||||
//通过传入的时间刻计算位移并更新位置坐标
|
||||
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];
|
||||
*_x += deltaX;
|
||||
float deltaY = 0;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
deltaY += _yVelocity[i];
|
||||
deltaY *= deltaTick;
|
||||
}
|
||||
deltaY += _yVelocity[10];
|
||||
*_y += deltaY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改自身路径,修改条件由外部逻辑判断触发
|
||||
/// </summary>
|
||||
public void ChangeVelocity(float[] XSpeed,float[] YSpeed)
|
||||
{
|
||||
if (XSpeed != null)
|
||||
{
|
||||
if (XSpeed.Length == 10)
|
||||
{
|
||||
this._xVelocity = XSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("The amount of parameters should be 10!");
|
||||
}
|
||||
}
|
||||
if (YSpeed != null)
|
||||
{
|
||||
if (YSpeed.Length == 10)
|
||||
{
|
||||
this._yVelocity = YSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("The amount of parameters should be 10!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user