我正在制作游戏,我需要检查对象的坐标是否符合要求(目的地坐标)与允许的差值。检查对象坐标是否符合要求
例子:
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