daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package dev.bleidorb.Main;
  2.  
  3. import javafx.animation.AnimationTimer;
  4. import javafx.application.Application;
  5. import javafx.scene.Group;
  6. import javafx.scene.Scene;
  7. import javafx.scene.paint.Color;
  8. import javafx.scene.shape.Circle;
  9. import javafx.scene.text.Font;
  10. import javafx.scene.text.Text;
  11. import javafx.stage.Stage;
  12.  
  13. public class dywoMain extends Application{
  14.    
  15.     private int WIDTH_s = 1080;
  16.     private int HEIGHT_s = 720;
  17.     public String GAMENAME = "PingPong!";
  18.     public double xBallpos = 550;
  19.     public double yBallpos = 300;
  20.     public double BallRad = 20;
  21.     public double xSpeedBall = 5;
  22.     public int LeftScore = 0;
  23.     public int RightScore = 0;
  24.    
  25.     public static void main(String [] args) {
  26.         launch(args);
  27.     }
  28.    
  29.     @Override
  30.     public void start(Stage Main_stage) throws Exception {
  31.        
  32.         final Group root = new Group();
  33.         final Scene scene = new Scene(root, WIDTH_s, HEIGHT_s, Color.BLACK);
  34.        
  35.         Circle circle_1blue = new Circle(xBallpos, yBallpos, BallRad);
  36.         circle_1blue.setFill(Color.GREEN);
  37.         root.getChildren().add(circle_1blue);
  38.        
  39.         Text textScoreL = new Text(100, 100, "" + LeftScore);
  40.         textScoreL.setFill(Color.RED);
  41.         textScoreL.setFont(Font.font(100));
  42.         root.getChildren().add(textScoreL);
  43.         Text textScoreR = new Text(900, 100, "" + RightScore);
  44.         textScoreR.setFill(Color.BLUE);
  45.         textScoreR.setFont(Font.font(100));
  46.         root.getChildren().add(textScoreR);
  47.        
  48.         Main_stage.setScene(scene);
  49.         Main_stage.setTitle(GAMENAME);
  50.         Main_stage.show();
  51.        
  52.         AnimationTimer animator_gameloop = new AnimationTimer() {
  53.  
  54.             @Override
  55.             public void handle(long arg0) {
  56.                
  57.                 //update
  58.                 xBallpos += xSpeedBall;
  59.                 if (xBallpos + BallRad > WIDTH_s) {
  60.                     RightScore++;
  61.                     xBallpos = 550;
  62.                     xSpeedBall *= -1;
  63.                     System.out.println("Right Score is: " + RightScore);
  64.                 }
  65.                 if (xBallpos - BallRad < 0) {
  66.                     LeftScore++;
  67.                     xBallpos = 550;
  68.                     xSpeedBall *= -1;
  69.                     System.out.println("Left Score is: " + LeftScore);
  70.                 }
  71.                
  72.                 //render
  73.                 circle_1blue.setCenterX(xBallpos);
  74.             }
  75.         };
  76.        
  77.         animator_gameloop.start();
  78.     }
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top