我一直在尝试制作一个塔防游戏,其中暴徒被赋予以给定速度移动的目的地,而现在它的设置方式发生了一些奇怪的事情,我不确定 updateAngle() 方法.
// Destination is represented by Coordinates[index]
public void Update(GameTime time)
{
Position.Y -= (float)(time.ElapsedGameTime.TotalSeconds * velocity * Math.Cos(angle));
Position.X += (float)(time.ElapsedGameTime.TotalSeconds * velocity * Math.Sin(angle));
float remainingX = Math.Abs(Destination.X - Position.Y);
float remainingY = Math.Abs(Destination.Y - Position.Y);
if (remainingX < 2 && remainingY < 2)
{
index++;
if (index == Coordinates.Count - 1)
{
End = true;
}
else
{
updateAngle();
}
}
}
private void updateAngle()
{
angle = (float)Math.Atan((Position.Y - Destination.Y) / (Position.X - Destination.X));
}