Browse Source

update

main
fdai4616 2 years ago
parent
commit
c0e35d950b
  1. 18
      src/main/java/PingPong/Ball.java
  2. BIN
      target/classes/PingPong/Ball.class

18
src/main/java/PingPong/Ball.java

@ -1,10 +1,28 @@
package PingPong; package PingPong;
import java.awt.*; import java.awt.*;
import java.util.Random;
public class Ball extends Rectangle { public class Ball extends Rectangle {
int xVelocity; int xVelocity;
int yVelocity; 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){ public void setXDirection (int randomXDirection){
xVelocity = randomXDirection; xVelocity = randomXDirection;
} }

BIN
target/classes/PingPong/Ball.class

Loading…
Cancel
Save