我正在製作apong遊戲,在Paddle類的布爾方法中,我想確定球是否觸及任何兩個槳,我正在努力尋找適當的邏輯......球接觸了其中一個槳嗎?
這裏是變量:
// instance variables
private Screen theScreen;
private MyroRectangle theRectangle;
private int topLeftX;
private int topLeftY;
// constants
private final int HEIGHT = 100; //the paddle's fixed height
private final int WIDTH = 5; //the paddle's fixed width
private final int PIXELS_PER_MOVE = 20; //the number of pixels a paddle can move either up or down in one timestep
這裏是方法:*,此方法只確定球接觸或不它不會做任何與彈跳球回
public boolean isTouching(Ball b)
{
boolean t = false;
if ((theScreen.getWidth()-(b.getX() + b.getRadius())) >= theScreen.getWidth()-theRectangle.getCenterX())
{
t= true;
}
return t;
也是我想:
if ((b.getX() > theRectangle.getCenterX()/2) && (b.getY() < theRectangle.getCenterY()/2))
========== **,可能需要球類的方法:
getX()
getY()
getRadius()
============= =
** Rectangle類:
getCenterX()
getCenterY()
===============
**屏幕類:
getWidth()
getHeight()
我只是想確定至少的條件,然後我可以找出其餘的人。