问题描述
这是检测碰撞的方法。卫星是圆形,船是矩形。
boolean hitSatellite(Ship ship,Satellite satellite) {
float left = ship.getXPos();
float right = ship.getXPos() + ship.getWidth();
float top = ship.getYPos();
float bottom = ship.getYPos() + ship.getHeight();
float satelliteLeft = abs(satellite.getXPos() - satellite.getDiameter()/2);
float satelliteRight = abs(satellite.getXPos() + satellite.getDiameter()/2);
float satellitetop = abs(satellite.getYPos() + satellite.getDiameter()/2);
float satelliteBottom = abs(satellite.getYPos() - satellite.getDiameter()/2);
if (!(left > satelliteRight || right < satelliteLeft || top < satelliteBottom || bottom > satellitetop)) {
return true;
}
return false;
}
boolean collection = hitSatellite(ship,satellite);
if (collection) {
println("You have collected" + count + " Satellite");
satellite.Start();
}
score++;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)