我的目標是在Door靠近時返回true(一個Door是Game Object的一個子類,而allObjectsInWorld是一個ArrayList,其中包含世界上所有的遊戲對象,包括這個門) 當我靠近門時,我會返回假。 得到的是如果對象是一個門使用Point2D中的距離來比較變量與數組
GameObject.position是的Point2D門點返回true
public boolean isDoorNear(GameObject user) {
boolean tempBoo = false;
for(int i = 0; i < allObjectsInWorld.size();i++) {
GameObject a = (GameObject) allObjectsInWorld.get(i); //checks to see if something is there
if(user.position.distance(a.position) <= 2.0 && a.isDoor) {
tempBoo = true;
}
else {
tempBoo = false;
}
}
return tempBoo;
}
什麼課?遊戲對象?門? – StanislavL