好几个月没写博客了~~变懒了
提到弹幕类游戏,想到的最多的应该是《东方Project》系列了吧
酷炫的弹幕~~酷炫的弹幕~~我只记得酷炫。。。。
今天我们也来实现一个仿制版,阉割版~
关于弹幕类游戏,有篇文章写的不错。我也就不重复写了
今天首先来实现以下辅助库,因为这些作为游戏的基石,还是很重要的
由于C#没有原生的Vector类(XNA有,但这里不打算用XNA)所以我们自己实现一个
public struct Vector2
{
public static readonly Vector2 Zero = new Vector2(0, 0);
public float X;
public float Y;
public Vector2(float x, float y)
{
this.X = x;
this.Y = y;
}
public Vector2(Vector2 v)
{
this.X = v.X;
this.Y = v.Y;
}
public override string ToString()
{
return "(" + X.ToString() + "," + Y.ToString() + ")";
}
public override bool Equals(object obj)
{
if (object.Equals(obj, null))
{
return false;
}
Vector2 v = (Vector2)obj;
return this.X == v.X && this.Y == v.Y;
}
public override int GetHashCode()
{
return X.GetHashCode() + Y.GetHashCode();
}
public void Normalize()
{
float m = this.X * this.X + this.Y * this.Y;
if (m < 0.00001f)
{
m = 1;
}
m = 1.0f / (float)Math.Sqrt((double)m);
X = X * m;
Y = Y * m;
}
public void Reverse()
{
this.X = -this.X;
this.Y = -this.Y;
}
public float Length()
{
return (float)Math.Sqrt(X * X + Y * Y);
}
public float Angle()
{
return (float)Math.Atan2(Y, X);
}
public float Angle(Vector2 vec)
{
Vector2 s = this;
s.Normalize();
vec.Normalize();
return (float)Math.Acos(Vector2.Dot(s, vec));
}
public void Rotate(float angle)
{
float x = X;
float y = Y;
x = X * (float)Math.Cos(angle) - Y * (float)Math.Sin(angle);
y = X * (float)Math.Sin(angle) + Y * (float)Math.Cos(angle);