我在画布上绘制了多个不同大小和位置的圆圈,但我需要检测它们之间的碰撞。
public void run() {
while(Run){
if(!sHold.getSurface().isValid())
continue;
c[0][cnum].r++;
canvas = sHold.lockCanvas();
canvas.drawRGB(02, 02, 150);
Paint white = new Paint();
white.setColor(Color.WHITE);
if(c[0][cnum].x != 0 && c[0][cnum].y != 0)
canvas.drawCircle(c[0][cnum].x, c[0][cnum].y, c[0][cnum].r, white);
if(cnum!=0)
for(int i=0; i<cnum; i++)
canvas.drawCircle(c[1][i].x, c[1][i].y, c[1][i].r, white);
sHold.unlockCanvasAndPost(canvas);
if(((c[0][cnum].x - c[0][cnum].r)<0)||((c[0][cnum].y-c[0][cnum].r)<0)||((c[0][cnum].y+c[0][cnum].r)>height)||((c[0][cnum].x+c[0][cnum].r>width))){
c[1][cnum].x = c[0][cnum].x;
c[1][cnum].y = c[0][cnum].y;
c[1][cnum].r = c[0][cnum].r;
broken = true;
break;
}
}
}