c# - 在 C# 中制作小行星游戏

标签 c# graphics trigonometry

<分区>

所以我目前正在尝试为一个类(class)制作游戏 Asteroids。问题是,自从上次上课以来,我已经有大约 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"*/

编辑:我忘了说,这是我唯一的代码。所以我基本上只能用一个引擎来移动一些东西,但没有什么可移动的。

最佳答案

有一个 tutorial for building an asteroids game在 MSDN 上的 XNA 中。

关于c# - 在 C# 中制作小行星游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3687300/

相关文章:

c - 点奇怪地旋转,我的计算有什么问题?

java - 获取一点与另一点之间的角度(三角函数)

Java 图形绘制自定义圆形

c# - 如何创建可以放置、移动和连接项目的示意图?

c# - 用于单元测试的模拟周期性计时器

c# - Winforms 文本框掩码

java - 将对象添加到面板,而不需要重新开始?

c - 用 C 语言生成带噪声的正弦波阵列

c# - 打印出数组平均结果时出现问题

c# - 简单的 C# 计算 - 数据类型