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 rightUp;
|
||||||
public boolean rightDown;
|
public boolean rightDown;
|
||||||
|
|
||||||
private boolean ballUp;
|
public boolean ballUp;
|
||||||
private boolean ballDown;
|
public boolean ballDown;
|
||||||
private boolean ballRight;
|
public boolean ballRight;
|
||||||
private boolean ballLeft;
|
public boolean ballLeft;
|
||||||
|
|
||||||
Random rand;
|
Random rand;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
// 120
|
||||||
public class Game {
|
public class Game {
|
||||||
|
|
||||||
Ball ball;
|
Ball ball;
|
||||||
|
@ -42,6 +42,15 @@ public class Game {
|
||||||
|
|
||||||
ball.setLocation(ball.getPos('x', dt), ball.getPos('y', dt));
|
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.leftPlayer.setLocation(10, 700);
|
||||||
// ball.xPos++;
|
// ball.xPos++;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue