diff --git a/src/main/java/PingPong/Ball.java b/src/main/java/PingPong/Ball.java index 8c17da9..1e75d0c 100644 --- a/src/main/java/PingPong/Ball.java +++ b/src/main/java/PingPong/Ball.java @@ -1,10 +1,28 @@ package PingPong; import java.awt.*; +import java.util.Random; public class Ball extends Rectangle { + int xVelocity; int yVelocity; +int ballSpeed = 3; +Random random; + + Ball(int x, int y , int width, int height){ + super(x,y,width,height); + random =new Random(); + int randomXDirection = random.nextInt(2); + if (randomXDirection == 0) + randomXDirection--; + setXDirection(randomXDirection * ballSpeed); + + int randomYDirection = random.nextInt(2); + if (randomYDirection == 0) + randomYDirection--; + setYDirection(randomYDirection * ballSpeed); + } public void setXDirection (int randomXDirection){ xVelocity = randomXDirection; } diff --git a/target/classes/PingPong/Ball.class b/target/classes/PingPong/Ball.class index df86139..533736e 100644 Binary files a/target/classes/PingPong/Ball.class and b/target/classes/PingPong/Ball.class differ