我正在製作遊戲,我需要檢查對象的座標是否符合要求(目的地座標)與允許的差值。檢查對象座標是否符合要求
例子:
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;
}
這聽起來像最簡單的方式,但也許有更好的?將不勝感激的一些提示。
其他,還有什麼可以做什麼? – 2013-02-18 21:00:20