Added paddle boundary

This commit is contained in:
BlueNutterfly 2018-11-11 11:47:21 +04:00
parent 74b96990c5
commit ace35e1a2c

View File

@ -28,12 +28,18 @@ public class Paddle extends Entity {
public void update(float dt) { public void update(float dt) {
Ball ball = getBrickBuster().getBall(); Ball ball = getBrickBuster().getBall();
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
if (getX() - 5 - PADDLE_WIDTH/2 < 0) {
return;
}
setX(getX() - 5); setX(getX() - 5);
if (!getBrickBuster().isPlaying()) { if (!getBrickBuster().isPlaying()) {
ball.setX(ball.getX() - 5); ball.setX(ball.getX() - 5);
} }
} }
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
if (getX() + 5 + PADDLE_WIDTH/2 > BrickBuster.WIDTH) {
return;
}
setX(getX() + 5); setX(getX() + 5);
if (!getBrickBuster().isPlaying()) { if (!getBrickBuster().isPlaying()) {
ball.setX(ball.getX() + 5); ball.setX(ball.getX() + 5);