publicvoidcollisions(){//定义碰撞borderCollision();//定义碰撞边界holesCollision();//定义碰撞球洞ballsCollision();//定义碰撞球}publicvoidcalculateNext(longmillis){doublese...
public void collisions() { //定义碰撞
borderCollision(); //定义碰撞边界
holesCollision(); //定义碰撞球洞
ballsCollision(); //定义碰撞球
}
public void calculateNext(long millis) {
double segs = millis / 1000.0;
for (int i=0; i
nextX[i] = x[i] + vx[i] * segs;
nextY[i] = y[i] + vy[i] * segs;
vx[i] *= 0.99;
vy[i] *= 0.99;
if (Math.abs(Math.hypot(vx[i], vy[i]))<2) {
vx[i] = 0;
vy[i] = 0;
}
}
}
public void holesCollision() {
for (int ball = 0; ball < nballs; ++ball) if (onTable[ball]) {
for (int iHX=0; iHX<3; ++iHX) {
for (int iHY=0; iHY<2; ++iHY) {
if (Math.hypot(holesX[iHX]-x[ball], holesY[iHY]-y[ball])
onTable[ball] = false;
if (ball!=0)--nBallsOn;
vx[ball] = 0;
vy[ball] = 0;
}
}
这是其中的一部分程序,我看不懂这部分啊。
能详细点吗?我是初学。
展开