所以我现在正在尝试为小班制作游戏小行星。问题是,自从我上次上课以来几乎没有做过任何编码,大约每年的3/4,并且几乎忘记了我所学到的一切。我需要使用推力/加速度来移动船,但也要盖上它,并且有摩擦力,这样当推力停止时,船会减速而不是立即停止。我有下面的基本数学用于旋转和加速船。我非常清楚编程正在将问题分解为简单的步骤,问题出现在这里,我不知道下一步该去哪里。任何帮助将不胜感激。
// Ship's starting position
static double positionX = 500.0;
static double positionY = 500.0;
// Calculate ship heading vectors based on current orientation in Radians
static double orientationInRadians;
static double xVector = Math.Sin(orientationInRadians);
static double yVector = Math.Cos(orientationInRadians);
/*Use Left and Right arrows to rotate
Once vector is found,
calculate position of ship 10 units away from current position along heading vector
scale vector to a unit (length of 1) vector*/
static double magnitude = Math.Sqrt(xVector * xVector + yVector * yVector);
static double unitVectorX = xVector / magnitude;
static double unitVectorY = yVector / magnitude;
/*Now that the vector is one unit long
but still points in the ships current orientation
move ship with positionX and positionY as its current coordinates*/
static double distanceToTravel = 10.0;
double newPositionX = positionX + unitVectorX * distanceToTravel;
double newPositionY = positionY + unitVectorY * distanceToTravel;
/*Remember to track the ship's current position with a double or float
and make distanceToTravel non-constant for acceleration instead of "jumps"*/
编辑:我忘了提及,这是我唯一的代码。所以我基本上坚持使用引擎来移动没有任何动静的东西。
答案 0 :(得分:4)
嗯,你真的没有走得太远但是你可以在codeproject.com上学习很多完整的C#实现:
C# Asteroids without DirectX
How to build an asteroids inspired Silverlight game
C# Asteroids
答案 1 :(得分:4)
MSDN上的XNA中有tutorial for building an asteroids game。