我已经有一个碰撞代码,但它检查了我并不真正需要的获胜者和 ontouch 方法,因为我的位图正在自行移动,我只是希望它们在重叠时发生碰撞。
private boolean checkCollision(Grafika first, Grafika second) {
boolean retValue = false;
int width = first.getBitmap().getWidth();
int height = first.getBitmap().getHeight();
int x1start = first.getCoordinates().getX();
int x1end = x1start + width;
int y1start = first.getCoordinates().getY();
int y1end = y1start + height;
int x2start = second.getCoordinates().getX();
int x2end = x2start + width;
int y2start = second.getCoordinates().getY();
int y2end = y2start + height;
if ((x2start >= x1start && x2start <= x1end) || (x2end >= x1start && x2end <= x1end)) {
if ((y2start >= y1start && y2start <= y1end) || (y2end >= y1start && y2end <= y1end)) {
retValue = true;
}
}
return retValue;
}