Java Reference
In-Depth Information
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage stage) {
pongAnimation = new Timeline(
new KeyFrame(new Duration(10.0), t -> {
checkForCollision();
int horzPixels = movingRight ? 1 : -1;
int vertPixels = movingDown ? 1 : -1;
centerX.setValue(centerX.getValue() + horzPixels);
centerY.setValue(centerY.getValue() + vertPixels);
})
);
pongAnimation.setCycleCount(Timeline.INDEFINITE);
ball = new Circle(0, 0, 5, Color.WHITE);
topWall = new Rectangle(0, 0, 500, 1);
leftWall = new Rectangle(0, 0, 1, 500);
rightWall = new Rectangle(500, 0, 1, 500);
bottomWall = new Rectangle(0, 500, 500, 1);
leftPaddle = new Rectangle(20, 0, 10, 30);
leftPaddle.setFill(Color.LIGHTBLUE);
leftPaddle.setCursor(Cursor.HAND);
leftPaddle.setOnMousePressed(me -> {
initLeftPaddleTranslateY = leftPaddle.getTranslateY();
leftPaddleDragAnchorY = me.getSceneY();
});
leftPaddle.setOnMouseDragged(me -> {
double dragY = me.getSceneY() - leftPaddleDragAnchorY;
leftPaddleY.setValue(initLeftPaddleTranslateY + dragY);
});
rightPaddle = new Rectangle(470, 0, 10, 30);
rightPaddle.setFill(Color.LIGHTBLUE);
rightPaddle.setCursor(Cursor.CLOSED_HAND);
rightPaddle.setOnMousePressed(me -> {
initRightPaddleTranslateY = rightPaddle.getTranslateY();
rightPaddleDragAnchorY = me.getSceneY();
});
rightPaddle.setOnMouseDragged(me -> {
double dragY = me.getSceneY() - rightPaddleDragAnchorY;
rightPaddleY.setValue(initRightPaddleTranslateY + dragY);
});
startButton = new Button("Start!");
startButton.setLayoutX(225);
startButton.setLayoutY(470);
startButton.setOnAction(e -> {
startVisible.set(false);
Search WWH ::




Custom Search