Package jbrickbreaker.model

Examples of jbrickbreaker.model.Pad


        this.gameView = gameView;
        lastDirection = Direction.UNDEF;
    }

    private void manageCumulativeSpeed(Direction dir) {
        Pad pad = Pad.getInstance();
        if (lastDirection == dir) {
            pad.increaseCumulativeSpeed();
        } else {
            pad.resetCumulativeSpeed();
            lastDirection = dir;
        }
    }
View Full Code Here


        }
    }

    @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);
        }
View Full Code Here

TOP

Related Classes of jbrickbreaker.model.Pad

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.