【问题标题】:Making Asteroids Game In C# [closed]用 C# 制作小行星游戏 [关闭]
【发布时间】:2010-09-10 18:31:58
【问题描述】:

所以我目前正在尝试为一个班级制作游戏 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"*/

编辑:我忘了提,这是我唯一的代码。所以我基本上被困在一个可以移动什么东西的引擎上。

【问题讨论】:

  • ::grumble:: 在小行星中,船不会减速我们你关闭引擎。让物理正确是它的魅力之一。离开我的草坪!
  • 顺便说一句--这个问题很可能被关闭为“不真实”。或多或少是因为您没有a 问题,而是整个项目并且不知道从哪里开始。您可能应该设定一些小目标,并为之努力。然后在遇到困难时在这里提出具体问题。可能的目标: +在屏幕上打开一个窗口 +在窗口中直立并居中绘制“船” +在任何位置和方向上绘制船 +擦除船并在更新的位置和方向上重新绘制 +使船跟踪您的控制。 ..

标签: c# graphics trigonometry


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    好吧,您确实还没有走多远,但是您可以在 codeproject.com 上学习大量完整的 C# 实现:

    C# Asteroids without DirectX
    How to build an asteroids inspired Silverlight game
    C# Asteroids

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-01
      • 2014-01-31
      • 2014-02-10
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 2011-08-03
      相关资源
      最近更新 更多