The ball is now bouncing off the edges of the monitor
parent
6212745dcd
commit
687536a6ba
BIN
bin/Ball.class
BIN
bin/Ball.class
Binary file not shown.
BIN
bin/Game.class
BIN
bin/Game.class
Binary file not shown.
|
@ -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;
|
||||
|
||||
|
|
|
@ -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++;
|
||||
|
||||
|
|
Loading…
Reference in New Issue