Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dev.bleidorb.Main;
- import javafx.animation.AnimationTimer;
- import javafx.application.Application;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- public class dywoMain extends Application{
- private int WIDTH_s = 1080;
- private int HEIGHT_s = 720;
- public String GAMENAME = "PingPong!";
- public double xBallpos = 550;
- public double yBallpos = 300;
- public double BallRad = 20;
- public double xSpeedBall = 5;
- public int LeftScore = 0;
- public int RightScore = 0;
- public static void main(String [] args) {
- launch(args);
- }
- @Override
- public void start(Stage Main_stage) throws Exception {
- final Group root = new Group();
- final Scene scene = new Scene(root, WIDTH_s, HEIGHT_s, Color.BLACK);
- Circle circle_1blue = new Circle(xBallpos, yBallpos, BallRad);
- circle_1blue.setFill(Color.GREEN);
- root.getChildren().add(circle_1blue);
- Text textScoreL = new Text(100, 100, "" + LeftScore);
- textScoreL.setFill(Color.RED);
- textScoreL.setFont(Font.font(100));
- root.getChildren().add(textScoreL);
- Text textScoreR = new Text(900, 100, "" + RightScore);
- textScoreR.setFill(Color.BLUE);
- textScoreR.setFont(Font.font(100));
- root.getChildren().add(textScoreR);
- Main_stage.setScene(scene);
- Main_stage.setTitle(GAMENAME);
- Main_stage.show();
- AnimationTimer animator_gameloop = new AnimationTimer() {
- @Override
- public void handle(long arg0) {
- //update
- xBallpos += xSpeedBall;
- if (xBallpos + BallRad > WIDTH_s) {
- RightScore++;
- xBallpos = 550;
- xSpeedBall *= -1;
- System.out.println("Right Score is: " + RightScore);
- }
- if (xBallpos - BallRad < 0) {
- LeftScore++;
- xBallpos = 550;
- xSpeedBall *= -1;
- System.out.println("Left Score is: " + LeftScore);
- }
- //render
- circle_1blue.setCenterX(xBallpos);
- }
- };
- animator_gameloop.start();
- }
- }
Add Comment
Please, Sign In to add comment