From c0e35d950b163f5df329ccce2dda7786207c39a9 Mon Sep 17 00:00:00 2001 From: fdai4616 Date: Tue, 7 Feb 2023 21:54:08 +0100 Subject: [PATCH] update --- src/main/java/PingPong/Ball.java | 18 ++++++++++++++++++ target/classes/PingPong/Ball.class | Bin 409 -> 968 bytes 2 files changed, 18 insertions(+) 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 df86139f7104a743db174b51390e9ca210496641..533736eca023d51258f45a744ebbc5b3d0b8c337 100644 GIT binary patch literal 968 zcmZ`%?M@R>5Iwi;?$Wx@QYeTmAbyrrsiN`+CC0DNq#8n-Mt*MFO?$QMlClW=_bGe} z6M;k%AHZia;+bu!O7tdo@9fOnGw00Q??1nM1MnCRQ-~pMAz{OSsgQl^zIRLRepuS{ znxX5ryPksiNc%cmQ?QC0E*|-2(VRS?L?Tx^1m!7)au0pcGqq^gHEd^D! zFs6`+aQ8ypEp57fE7(q96d5Txt`INwAt!81BFB2YD1~e)=dZ2Gy=fa4F+)1OcMz8S zP$5w)FP2kemA6sAEGg}J;hX2WM-e*k`w4YPn748HEMaSyAcC&gxGHLr2X(I-GzWp_N??odspum4Z}1J`fHlvoYj=DSz!&Y(`J8tnC&-b*b^k}`=U=^hrS zBF14SxG9idh@|M`_@a|-=NaebD}cgHK#>?MdTLI-Fq=!9Ksn|SEaxjmw@#2gLe}|= ztZ|H~6(eVSg!#cZb#exsR_7R(hCwrDO3-A`90cb+Mb(P@E=LT;kVFb&NMi;WvK&Vd zS=_<|R>5IZH1X<BwX1w*za06j0O2A7McR#7GjPE#5pK3lXuYe%6qf d85I;PzPo>6T|198N38k(U-sDS+O7)CD-P{a3K$3}pk%5(g4M_3=dHO&aB*&_?oq=&9 zSeg$=f~0|h4E#Wn2g(*;5CrlV8H5;wfh0(?9ndf)AkC&Fy_JC-p_>aV$^q2R2{u8D YK_0A(0b&HmcoDF%j0~bc?Mw_}0HYKe&;S4c