C# 我需要什么来为这个游戏创建这个控件?(如管道)
这是我在这个部分的第一篇文章(XNA和游戏开发)。我正试图从下图中得到一些东西。正如你所看到的,有一条高速公路,在它里面,会有一些物体在移动(毫秒)。我猜斯特雷思的行为就像一条管道。当高速公路装载一个物体时,它会出现在高速公路的另一个极端,并且它会在高速软件中移动,直到它到达高速公路的另一个极端 我的主要问题是,我怎样才能只在高速公路内移动几个物体C# 我需要什么来为这个游戏创建这个控件?(如管道),c#,windows-phone-7,xna,xna-4.0,C#,Windows Phone 7,Xna,Xna 4.0,这是我在这个部分的第一篇文章(XNA和游戏开发)。我正试图从下图中得到一些东西。正如你所看到的,有一条高速公路,在它里面,会有一些物体在移动(毫秒)。我猜斯特雷思的行为就像一条管道。当高速公路装载一个物体时,它会出现在高速公路的另一个极端,并且它会在高速软件中移动,直到它到达高速公路的另一个极端 我的主要问题是,我怎样才能只在高速公路内移动几个物体 提前感谢。您需要一份点数列表和精灵列表 class Path { List<Vector2> Points; float
提前感谢。您需要一份点数列表和精灵列表
class Path
{
List<Vector2> Points;
float[] Lengths;
Vector2[] Directions;
void Build()
{
Lengths = new float[Points.Count-1];
Directions = new float[Points.Count-1];
for (int i=0; i<Points.Count-1;i++)
{
Directions[i] = Points[i+1] - Points[i];
Lengths[i] = Directions[i].Length();
Directions[i].Normalize();
}
}
}
class Sprite
{
Vector2 Position;
float StagePos;
int StageIndex;
Path Path;
float Speed;
void Update(float Seconds)
{
if (StageIndex!=Path.Points.Count-1)
{
StagePos += Speed * Seconds;
while (StagePos>Path.Lengths[StageIndex])
{
StagePos -= Path.Lengths[StageIndex];
StageIndex++;
if (StageIndex == Path.Points.Count-1)
{
Position = Path.Points[StageIndex];
return;
}
}
Position = Path.Points[StageIndex] + Directions[StageIndex] * StagePos;
}
}
}
类路径
{
列出要点;
浮动[]长度;
向量2[]方向;
void Build()
{
长度=新浮点数[Points.Count-1];
方向=新浮点数[Points.Count-1];
对于(整数i=0;iPath.Length[StageIndex])
{
StagePos-=路径长度[StageIndex];
StageIndex++;
if(StageIndex==Path.Points.Count-1)
{
位置=路径点[StageIndex];
返回;
}
}
位置=路径点[StageIndex]+方向[StageIndex]*StagePos;
}
}
}
您需要点列表和精灵列表
class Path
{
List<Vector2> Points;
float[] Lengths;
Vector2[] Directions;
void Build()
{
Lengths = new float[Points.Count-1];
Directions = new float[Points.Count-1];
for (int i=0; i<Points.Count-1;i++)
{
Directions[i] = Points[i+1] - Points[i];
Lengths[i] = Directions[i].Length();
Directions[i].Normalize();
}
}
}
class Sprite
{
Vector2 Position;
float StagePos;
int StageIndex;
Path Path;
float Speed;
void Update(float Seconds)
{
if (StageIndex!=Path.Points.Count-1)
{
StagePos += Speed * Seconds;
while (StagePos>Path.Lengths[StageIndex])
{
StagePos -= Path.Lengths[StageIndex];
StageIndex++;
if (StageIndex == Path.Points.Count-1)
{
Position = Path.Points[StageIndex];
return;
}
}
Position = Path.Points[StageIndex] + Directions[StageIndex] * StagePos;
}
}
}
类路径
{
列出要点;
浮动[]长度;
向量2[]方向;
void Build()
{
长度=新浮点数[Points.Count-1];
方向=新浮点数[Points.Count-1];
对于(整数i=0;iPath.Length[StageIndex])
{
StagePos-=路径长度[StageIndex];
StageIndex++;
if(StageIndex==Path.Points.Count-1)
{
位置=路径点[StageIndex];
返回;
}
}
位置=路径点[StageIndex]+方向[StageIndex]*StagePos;
}
}
}