gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:17:44 25 4
gpt4 key购买 nike

<分区>

所以我目前正在尝试为一个类(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"*/

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com