这是我正在使用的课程
public class Spot {
private static final int IMAGE_HEIGHT = 500;
private static final int IMAGE_WIDTH = 500;
private static final int DOT_HEIGHT = 20;
private static final int DOT_WIDTH = 20;
private static final Color DOT_COLOR = Color.RED;
private Random ran = new Random();
private int x = this.ran.nextInt(IMAGE_WIDTH);
private int y = this.ran.nextInt(IMAGE_HEIGHT);
/**
* Draws spot onto given playfield object
*
* @param playfield
*/
public void drawSpot(Playfield playfield) {
playfield.getGraphicsContext2D().setFill(DOT_COLOR);
playfield.getGraphicsContext2D().fillOval(x, y, DOT_WIDTH, DOT_HEIGHT);
this.drawSpot(playfield);
}
我试图找出一种方法来编写一个方法来确定给定的x和y坐标是否在边界框内。
public boolean isINSpot(int x, int y){
if (x > this.x && x < this.x + DOT_WIDTH && y > this.y && y < this.y + DOT_HEIGHT) {
return false;
} else {
return true;
}
}
}
}
答案 0 :(得分:0)
这可能有所帮助:
return x > boxX && x < boxX + boxWidth && y > boxY && y < boxY + boxHeight;
如果没有,我搞砸了。