オブジェクトの座標が要件 (目的地の座標) を満たしているかどうかを確認する必要があるゲームを作成しています。
例:
int x; //current object X coordinate
int y; //current object Y coordinate
int destinationX = 50; //example X destination value
int destinationY = 0; //example Y destination value
int permittedDiference = 5;
boolean xCorrect = false;
boolean yCorrect = false;
私はアルゴリズムを作成しようとしています、チェックしています
if (x == destinationX + permittedDifference || x == destinationX - permittedDifference)
{
xCorrect = true;
}
if (y == destinationY + permittedDifference || y == destinationY - permittedDifference)
{
yCorrect = true;
}
最も単純な方法のように聞こえますが、もっと良い方法があるのではないでしょうか? いくつかのヒントに感謝します。