}
}
@Override
public void keyPressed(KeyEvent e) {
Pad pad = Pad.getInstance();
if (e.getKeyCode() == keyLeft && !gameView.isPaused()) {
if (game.getPadXPos() - game.getPadSpeedX() <= 0)
game.setPadXPos(0);
else {
game.addToPadXPos(-game.getPadSpeedX());
if (pad.isStuck()) {
for (Ball b : game.getBalls()) {
if (game.checkCollisionPad(b)) {
b.setX(b.x - game.getPadSpeedX());
}
}
}
}
manageCumulativeSpeed(Direction.LEFT);
gameView.repaint();
} else if (e.getKeyCode() == keyRight && !gameView.isPaused()) {
if ((game.getPadXPos() + Pad.getInstance().getWidth() + game
.getPadSpeedX()) >= gameView.getWidth())
game.setPadXPos(gameView.getWidth()
- Pad.getInstance().getWidth() - 2);
else {
game.addToPadXPos(game.getPadSpeedX());
if (pad.isStuck()) {
for (Ball b : game.getBalls()) {
if (game.checkCollisionPad(b)) {
b.setX(b.x + game.getPadSpeedX());
}
}
}
}
manageCumulativeSpeed(Direction.RIGHT);
gameView.repaint();
} else if (e.getKeyCode() == keyEject && !gameView.isPaused()) {
if (game.collision)
game.unstuckBalls();
if(gameView.isDisplayingStartHelp())
gameView.setDisplayStartHelp(false);
pad.resetCumulativeSpeed();
lastDirection = Direction.UNDEF;
} else if (e.getKeyCode() == keyPause) {
final boolean isPaused = gameView.isPaused();
gameView.setPaused(!isPaused);
}