Хорошо, у меня есть этот корабль, который пользователь управляет клавишами со стрелками.
if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
mAngle -= 0.1f;
else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
mAngle += 0.1f;
if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
{
// mSpeed.Y = SHIP_SPEED;
// mDirection.Y = MOVE_UP;
velocity.X = (float)Math.Cos(mAngle) * SHIP_SPEED;
velocity.Y = (float)Math.Sin(mAngle) * SHIP_SPEED;
}
else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
{
mSpeed.Y = SHIP_SPEED;
mDirection.Y = MOVE_DOWN;
}
Следующие 2 метода находятся в другом классе.
//Update the Sprite and change it's position based on the passed in speed, direction and elapsed time.
public void Update(GameTime theGameTime, Vector2 velocity, float theAngle)
{
Position += velocity * (float)theGameTime.ElapsedGameTime.TotalSeconds;
shipRotation = theAngle;
}
//Draw the sprite to the screen
public void Draw(SpriteBatch theSpriteBatch)
{
Vector2 Origin = new Vector2(mSpriteTexture.Width / 2, mSpriteTexture.Height / 2);
theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height),
Color.White, shipRotation, Origin, Scale, SpriteEffects.None, 0);
}
Проблема в том, что программа думает, что передняя часть корабля - это одно из боковых крыльев, поэтому, когда я нажимаю вверх, она отклоняется в сторону Я не знаю, почему это так.
Предложения