This is really a silly question, but I've been staring at this problem for way too long and I just cant figure out what the problem is:
/**
* public boolean overlap(int targetX, int targetY) {
* Returns true if the target position is sufficient close to this ghost
* If target position is 16 pixels or less in the x direction
* and similarly in y direction, return true. Otherwise return false
*
* @param targetX
* @param targetY
* @return
*/
public boolean overlap(int targetX, int targetY){
double x=this.getX();
double y=this.getY();
double deltaX=targetX-x;
double deltaY=targetY-y;
if(deltaX<=16 && deltaX>=0 && deltaY<=16 && deltaY>=0)
return true;
else
return false;
}
This should work right? But it doesnt. If I run this test, it fails the assertTrue. (g1.x=100 and g1.y=1000)
double theta = 2 * Math.PI * Math.random();
int x = 100 + (int) (16 * Math.cos(theta));
int y = 1000 + (int) (16 * Math.sin(theta));
assertTrue(g1.overlap(x, y));
Does anyone see something I dont?