Game Development Reference
In-Depth Information
//Determines if two rectangles overlap, returns true if the
//overlapped area is larger than the given threshold.
//Parameters:
//
x1 - x position of the left side of rectangle#1
//
y1 - y position of the top side of rectangle#1
//
w1 - the width of rectangle#1
//
h1 - the height of rectangel#1
//
x2 - x position of the left side of rectangle#2
//
y2 - y position of the top side of rectangle#2
//
w2 - the width of rectangle#2
//
h2 - the height of rectangel#2
//
overlap - the given threshold
public boolean
isOverlapped(
int
x1,
int
y1,
int
w1,
int
h1,
int
x2,
int
y2,
int
w2,
int
h2,
float
overlap){
int
xb = 0;
//big x
int
yb = 0;
//big y
int
xs = 0;
//small x
int
ys = 0;
//small y
int
width = 0;
int
height = 0;
boolean
xFlag =
true
;
boolean
yFlag =
true
;
if
(x1 >= x2){
xb = x1;
xs = x2;
xFlag =
false
;
}
else
{
xb = x2;
xs = x1;
xFlag =
true
;
}
Search WWH ::
Custom Search