Tuesday, May 07, 2013

矩形的碰撞检测


public class Rectangle {
public final Vector2 lowerLeft;
public float width, height;
public Rectangle(float x, float y, float width, float height) {
this.lowerLeft = new Vector2(x,y);
this.width = width;
this.height = height;
}
}




public boolean overlapRectangles(Rectangle r1, Rectangle r2) {
if(r1.lowerLeft.x < r2.lowerLeft.x + r2.width &&
r1.lowerLeft.x + r1.width > r2.lowerLeft.x &&
r1.lowerLeft.y < r2.lowerLeft.y + r2.height &&
r1.lowerLeft.y + r1.height > r2.lowerLeft.y)
return true;
else
return false;
}

No comments:

Search This Blog

Followers