The ball is now bouncing off the edges of the monitor

master
Lenz Wiechers 2020-02-16 01:24:09 +01:00
parent 6212745dcd
commit 687536a6ba
4 changed files with 16 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@ -21,10 +21,10 @@ public class Ball extends JFrame implements KeyListener {
public boolean rightUp;
public boolean rightDown;
private boolean ballUp;
private boolean ballDown;
private boolean ballRight;
private boolean ballLeft;
public boolean ballUp;
public boolean ballDown;
public boolean ballRight;
public boolean ballLeft;
Random rand;

View File

@ -1,4 +1,4 @@
// 120
public class Game {
Ball ball;
@ -16,14 +16,14 @@ public class Game {
leftPlayer = new Player();
rightPlayer = new Player();
ball = new Ball();
ball.setSize(ball.xSize, ball.ySize);
leftPlayer.setSize(0, leftPlayer.ySize);
leftPlayer.setTitle("left Player");
rightPlayer.setSize(0, rightPlayer.ySize);
rightPlayer.setTitle("right Player");
@ -42,6 +42,15 @@ public class Game {
ball.setLocation(ball.getPos('x', dt), ball.getPos('y', dt));
if (ball.getPos('x', 0) < 0 || ball.getPos('x', 0) > 1785) {
ball.ballLeft = !ball.ballLeft;
ball.ballRight = !ball.ballRight;
}
if(ball.getPos('y', 0) < 0 || ball.getPos('y', 0) > 950) {
ball.ballUp = !ball.ballUp;
ball.ballDown = !ball.ballDown;
}
// ball.leftPlayer.setLocation(10, 700);
// ball.xPos++;