2010-09-10 89 views
1

所以我目前正在尝试让一个类的游戏Asteroids。问题是,自从我上一次上课以来,我一年四分之三没做过任何编码,并且几乎忘记了我学到的所有东西。我需要使用推力/加速度来移动船舶,但也需要加压,并且有摩擦力,以便当推力停止时,船只减速而不是立即停止。我有下面的基本数学来旋转和加速船。我很清楚,编程将问题分解成简单的步骤,问题来了,我不知道下一步该怎么去。任何帮助将非常感激。在C中制作小行星游戏#

// 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

::发牢骚::在小行星船*不*放慢我们你关闭引擎。获得物理学*正确*是它的魅力之一。然后下车我的草坪! – dmckee 2010-09-11 14:55:42

+0

顺便说一句 - 这个问题可能会被视为“不真实”。或多或少,因为你没有**问题,而是整个项目,并不知道从哪里开始。你应该设定一些小目标,并对它们进行研究。然后当你遇到困难时,在这里询问*特定的问题。可能的目标:+在屏幕上打开一个窗口+在船上绘制“船”,并在窗口中居中+在任意位置和方向绘制船舶+清除船舶并在更新位置和方向上重绘+使船跟踪控件。 .. – dmckee 2010-09-11 15:00:09

回答