diff --git a/bin/de/bricked/ui/LevelGUI.fxml b/bin/de/bricked/ui/LevelGUI.fxml index 853d5fb349939d1d396f2d71a2f815f9b911a7f1..5f50361fb02cf496a0cd9cd29132c71d470fd7a5 100644 --- a/bin/de/bricked/ui/LevelGUI.fxml +++ b/bin/de/bricked/ui/LevelGUI.fxml @@ -11,7 +11,7 @@ <AnchorPane fx:id="anchorPane" prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.bricked.ui.LevelController"> <children> <AnchorPane fx:id="anchorPaneGame" layoutX="22.0" layoutY="125.0" minHeight="650.0" minWidth="700.0" prefHeight="650.0" prefWidth="700.0" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="22.0" AnchorPane.rightAnchor="78.0" AnchorPane.topAnchor="125.0" /> - <VBox fx:id="vboxPowerUps" layoutX="745.0" layoutY="125.0" minHeight="454.0" minWidth="40.0" prefHeight="454.0" prefWidth="40.0" AnchorPane.bottomAnchor="221.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="125.0" /> + <VBox fx:id="vboxPowerUps" layoutX="745.0" layoutY="125.0" minHeight="338.0" minWidth="40.0" prefHeight="402.0" prefWidth="40.0" AnchorPane.bottomAnchor="273.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="125.0" /> <HBox alignment="CENTER" layoutX="34.0" layoutY="23.0" prefHeight="100.0" prefWidth="275.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> <children> <Button fx:id="buttonBack" mnemonicParsing="false" onAction="#back" text="Back" /> @@ -63,5 +63,10 @@ <Font name="System Bold" size="16.0" /> </font> </Label> + <Label fx:id="labelMultiplicator" alignment="CENTER_RIGHT" layoutX="736.0" layoutY="543.0" prefHeight="30.0" prefWidth="49.0" text="x0" textAlignment="JUSTIFY" AnchorPane.rightAnchor="18.0" AnchorPane.topAnchor="543.0"> + <font> + <Font name="System Bold" size="20.0" /> + </font> + </Label> </children> </AnchorPane> diff --git a/src/de/bricked/game/Game.java b/src/de/bricked/game/Game.java index 92b87fa5c5c91e2ab493bd2f577ff613760f69e8..55c5166f23ae4a7cc73461441696b5d1e7c932a9 100644 --- a/src/de/bricked/game/Game.java +++ b/src/de/bricked/game/Game.java @@ -18,10 +18,11 @@ public class Game private Ball ball; private boolean collision = false; private boolean wallCollision = false; - private int points; + private int totalPoints; private Board board; private final double speedIncreasePerPaddleHitFactor = 1.05; - private final double maxTotalSpeed = 8.0; + private int pointsSinceLastMultiplicatorReset; + private int multiplicator; public Game() { @@ -30,8 +31,10 @@ public class Game this.level = null; this.livesRemaining = 0; this.ball = null; - this.points = 0; + this.totalPoints = 0; this.board = null; + this.multiplicator = 1; + this.pointsSinceLastMultiplicatorReset = 0; } public Settings getSettings() @@ -84,14 +87,14 @@ public class Game this.ball = ball; } - public int getPoints() + public int getTotalPoints() { - return points; + return totalPoints; } - public void setPoints(int points) + public void setTotalPoints(int totalPoints) { - this.points = points; + this.totalPoints = totalPoints; } public Board getBoard() @@ -102,6 +105,42 @@ public class Game public void setBoard(Board board) { this.board = board; + } + + public int getMultiplicator() + { + return multiplicator; + } + + public void increaseMultiplicator() + { + this.multiplicator++; + } + + public void resetMultiplicator() + { + this.multiplicator = 1; + } + + public int getPointsSinceLastMultiplicatorReset() + { + return pointsSinceLastMultiplicatorReset; + } + + public void increasePointsSinceLastMultiplicatorReset(int points) + { + this.pointsSinceLastMultiplicatorReset += points; + } + + public void resetPointsSinceLastMultiplicatorReset() + { + pointsSinceLastMultiplicatorReset = 0; + } + + public void applyMultiplicator() + { + totalPoints += pointsSinceLastMultiplicatorReset * multiplicator; + System.out.println(pointsSinceLastMultiplicatorReset + " x" + multiplicator + " = " + totalPoints); } public Point2D reflectBall(HitLocation hitLocation, Point2D direction) @@ -134,9 +173,10 @@ public class Game double totalSpeed = Math.sqrt(direction.getX() * direction.getX() + direction.getY() * direction.getY()); totalSpeed = totalSpeed * speedIncreasePerPaddleHitFactor; - if(totalSpeed > maxTotalSpeed) + if(totalSpeed > ball.getType().getMaxTotalSpeed()) { - totalSpeed = maxTotalSpeed; + + totalSpeed = ball.getType().getMaxTotalSpeed(); } double newXSpeed = totalSpeed * factor * influenceX; double newYSpeed = Math.sqrt(totalSpeed * totalSpeed - newXSpeed * newXSpeed); diff --git a/src/de/bricked/game/balls/BallType.java b/src/de/bricked/game/balls/BallType.java index e4458a741cab36ec05f27f2be64f6ed8f608903f..aafcc02ee2ebaa072afa06f0427acebf52a122c7 100644 --- a/src/de/bricked/game/balls/BallType.java +++ b/src/de/bricked/game/balls/BallType.java @@ -2,21 +2,23 @@ package de.bricked.game.balls; public enum BallType { - NORMAL("N", "#9CD8FF", 10, 4), - EXPLOSIVE("A","#CC2E2E", 10, 6), - NO_COLLISION("S","#2828CC", 10, 8); + NORMAL("N", "#9CD8FF", 10, 4, 7), + EXPLOSIVE("A","#CC2E2E", 10, 6, 7), + NO_COLLISION("S","#2828CC", 10, 8, 8); private String ID; private String color; private double radius; private double speedFactor; + private double maxTotalSpeed; - private BallType(String ID, String color, double radius, double speedFactor) + private BallType(String ID, String color, double radius, double speedFactor, double maxTotalSpeed) { this.ID = ID; this.color = color; this.radius = radius; this.speedFactor = speedFactor; + this.maxTotalSpeed = maxTotalSpeed; } public String getID() @@ -39,4 +41,8 @@ public enum BallType return speedFactor; } + public double getMaxTotalSpeed() + { + return maxTotalSpeed; + } } \ No newline at end of file diff --git a/src/de/bricked/game/board/Board.java b/src/de/bricked/game/board/Board.java index 33d5a2cec06994df43b169d59b524fd9a1fe9c14..d03a66b6fcee3cd69d086f8c1acde4ee8c509acf 100644 --- a/src/de/bricked/game/board/Board.java +++ b/src/de/bricked/game/board/Board.java @@ -2,10 +2,10 @@ package de.bricked.game.board; import java.util.ArrayList; +import de.bricked.game.Game; import de.bricked.game.balls.Ball; import de.bricked.game.bricks.Brick; import de.bricked.game.bricks.BrickType; -import de.bricked.game.levels.Level; import de.bricked.ui.LevelController; public class Board @@ -15,11 +15,14 @@ public class Board public static final double WIDTH = 18.0; public static final double HEIGHT = 26.0; private int points = 0; + private Game game; - public Board(Level level) + public Board(Game game) { + this.game = game; + init(); - String boardString = level.getBoard(); + String boardString = game.getLevel().getBoard(); // parse board -> create bricks String[] bricksAndPowerArray = boardString.split(" "); ArrayList<Brick> loadedBricks = new ArrayList<>(); @@ -207,6 +210,7 @@ public class Board points += hittedBrick.getType().getPoints(); + game.increaseMultiplicator(); LevelController.redrawBrick(col, row, bricks.get(row).get(col), true); } else diff --git a/src/de/bricked/ui/LevelController.java b/src/de/bricked/ui/LevelController.java index 132c825e221a7bd367975a0769093f7c46eb8b1a..7b64d937de0f6eb903b388835f58962eb36bae75 100644 --- a/src/de/bricked/ui/LevelController.java +++ b/src/de/bricked/ui/LevelController.java @@ -65,13 +65,14 @@ public class LevelController @FXML private VBox vboxPowerUps; @FXML private VBox vboxLives; @FXML private Label labelFPS; + @FXML private Label labelMultiplicator; public Stage stage; public Image icon = new Image("de/bricked/resources/icon.png"); public final ResourceBundle bundle = ResourceBundle.getBundle("de/bricked/main/", Locale.GERMANY); private LevelSelectController levelSelectController; private Game game; - private static GridPane grid; + private static GridPane grid; private AnimationTimer timer; private double gamePaneWidth; private double gamePaneHeight; @@ -94,7 +95,7 @@ public class LevelController this.stage = stage; this.levelSelectController = levelSelectController; this.game = game; - game.setBoard(new Board(game.getLevel())); + game.setBoard(new Board(game)); anchorPane.setOnKeyReleased(new EventHandler<KeyEvent>() { @@ -287,6 +288,8 @@ public class LevelController showLabelFPS(levelSelectController.controller.controller.getCommandLine().getBundle().isShowFPS()); labelFPS.setStyle("-fx-text-fill: #FF0000"); + resetMultiplicator(); + gameState = GameState.WAITING; } @@ -343,6 +346,8 @@ public class LevelController // if ball collides with border then brick collisions are irrelevant if(hitLocation != null) { + resetMultiplicator(); + if(hitLocation.equals(HitLocation.LIFE_LOST)) { game.setLivesRemaining(game.getLivesRemaining() - 1); @@ -373,7 +378,7 @@ public class LevelController // reset paddle and ball initPaddle(); - initBall(); + initBall(); } } else @@ -421,37 +426,38 @@ public class LevelController // ball doesn't collide with border --> check collision with paddle else { - hitLocation = game.collides(ballPosition, paddlePosition, paddle.getWidth(), paddle.getHeight(), true); - // hitLocation = game.collides(game.getBall().getDirection(), stackPaneBall.getBoundsInParent(), labelPaddle.getBoundsInParent(), true); + hitLocation = game.collides(ballPosition, paddlePosition, paddle.getWidth(), paddle.getHeight(), true); if(hitLocation != null && (hitLocation.equals(HitLocation.PADDLE) || hitLocation.equals(HitLocation.CORNER))) - { + { game.getBall().setDirection(game.reflectOnPaddle(game.getBall().getDirection(), game.getDistanceToPaddleCenter(ballPosition, paddlePosition, paddle.getWidth()))); correctBallPosition(hitLocation, ballPosition, paddlePosition, paddle.getWidth(), paddle.getHeight()); + + resetMultiplicator(); } // ball doesn't collide with paddle --> check collision with bricks else { - // if(game.getBall().getDirection().getX() > 0) - // { - // for(int i = 0; i < Board.HEIGHT; i++) - // { - // for(int k = 0; k < Board.WIDTH; k++) - // { - // brickCollisionDetection(i, k, ballPosition); - // } - // } - // } - // else - // { - for(int i = (int)Board.HEIGHT - 1; i >= 0; i--) + if(game.getBall().getDirection().getX() > 0) + { + for(int i = 0; i < Board.HEIGHT; i++) + { + for(int k = 0; k < Board.WIDTH; k++) + { + brickCollisionDetection(i, k, ballPosition); + } + } + } + else { - for(int k = (int)Board.WIDTH - 1; k >= 0; k--) + for(int i = (int)Board.HEIGHT - 1; i >= 0; i--) { - brickCollisionDetection(i, k, ballPosition); + for(int k = (int)Board.WIDTH - 1; k >= 0; k--) + { + brickCollisionDetection(i, k, ballPosition); + } } } - // } } } @@ -528,9 +534,9 @@ public class LevelController int id = row * (int)Board.WIDTH + column; Label labelBrick = brickLabels.get(id); - + if(fade) - { + { FadeTransition ft = new FadeTransition(Duration.millis(BRICK_FADE_DURATION), labelBrick); ft.setFromValue(1.0); ft.setToValue(0.0); @@ -541,11 +547,11 @@ public class LevelController @Override public void handle(ActionEvent event) { - labelBrick.setStyle("-fx-background-image: url(\"de/bricked/resources/textures/bricks/" + brick.getCurrentTextureID() + ".png\");" + "-fx-background-position: center center;" + "-fx-background-repeat: no-repeat;" + "-fx-background-size: cover"); - } + labelBrick.setStyle("-fx-background-image: url(\"de/bricked/resources/textures/bricks/" + brick.getCurrentTextureID() + ".png\");" + "-fx-background-position: center center;" + "-fx-background-repeat: no-repeat;" + "-fx-background-size: cover"); + } }); ft.play(); - + } else { @@ -594,8 +600,8 @@ public class LevelController { anchorPaneGame.getChildren().remove(labelPaddle); - paddle = new Paddle(game.getLevel().getInitPadSize(), gamePaneHeight / Board.HEIGHT, gamePaneWidth); - labelPaddle = new ImageView(new Image("de/bricked/resources/textures/paddle/" + paddle.getPaddleSize().getTextureID() + ".png")); + paddle = new Paddle(game.getLevel().getInitPadSize(), gamePaneHeight / Board.HEIGHT, gamePaneWidth); + labelPaddle = new ImageView(new Image("de/bricked/resources/textures/paddle/" + paddle.getPaddleSize().getTextureID() + ".png")); labelPaddle.setFitWidth(paddle.getWidth()); labelPaddle.setFitHeight(paddle.getHeight()); labelPaddle.setTranslateX(gamePaneWidth / 2 - paddle.getWidth() / 2); @@ -607,7 +613,7 @@ public class LevelController { anchorPaneGame.getChildren().remove(stackPaneBall); - game.setBall(new Ball(BallType.NO_COLLISION)); + game.setBall(new Ball(BallType.NORMAL)); // create circle for ball final Circle circle = new Circle(game.getBall().getBallRadius(), Color.web(game.getBall().getType().getColor())); @@ -621,6 +627,21 @@ public class LevelController initTimer(); } + private void resetMultiplicator() + { + game.applyMultiplicator(); + game.resetMultiplicator(); + game.resetPointsSinceLastMultiplicatorReset(); + labelMultiplicator.setText("x0"); + } + + private void increaseMultiplicator(int points) + { + game.increaseMultiplicator(); + game.increasePointsSinceLastMultiplicatorReset(points); + labelMultiplicator.setText("x" + (game.getMultiplicator() - 1)); + } + private void movePaddleLeft() { if(labelPaddle.getLayoutX() + labelPaddle.getTranslateX() - paddle.getSpeed() > 0) @@ -662,11 +683,17 @@ public class LevelController game.getBall().setDirection(game.reflectBall(hitLocation, game.getBall().getDirection())); correctBallPosition(hitLocation, ballPosition, brickPosition, stackPaneBrick.getWidth(), stackPaneBrick.getHeight()); - } - - game.setPoints(game.getPoints() + game.getBoard().hitBrick(i, k, game.getBall())); - labelPoints.setText(String.valueOf(game.getPoints())); - labelBlocksRemaining.setText(game.getBoard().getNumberOfRemainingBricks() + " Bricks remaining"); + } + + int points = game.getBoard().hitBrick(i, k, game.getBall()); + //brick has been destroyed + if(points > 0) + { + increaseMultiplicator(points); + game.setTotalPoints(game.getTotalPoints() + points); + labelPoints.setText(String.valueOf(game.getTotalPoints())); + labelBlocksRemaining.setText(game.getBoard().getNumberOfRemainingBricks() + " Bricks remaining"); + } if(game.getBoard().getNumberOfRemainingBricks() == 0) { @@ -678,7 +705,7 @@ public class LevelController Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Congratulations!"); alert.setHeaderText(""); - alert.setContentText("You finished Level \"" + game.getLevel().getName() + "\" with " + game.getPoints() + " Points"); + alert.setContentText("You finished Level \"" + game.getLevel().getName() + "\" with " + game.getTotalPoints() + " Points"); Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); dialogStage.getIcons().add(icon); dialogStage.centerOnScreen(); @@ -715,7 +742,9 @@ public class LevelController } stage.close(); levelSelectController.stage.show(); - game.setPoints(0); + game.setTotalPoints(0); + game.resetMultiplicator(); + game.resetPointsSinceLastMultiplicatorReset(); anchorPaneGame.requestFocus(); } diff --git a/src/de/bricked/ui/LevelGUI.fxml b/src/de/bricked/ui/LevelGUI.fxml index 853d5fb349939d1d396f2d71a2f815f9b911a7f1..5f50361fb02cf496a0cd9cd29132c71d470fd7a5 100644 --- a/src/de/bricked/ui/LevelGUI.fxml +++ b/src/de/bricked/ui/LevelGUI.fxml @@ -11,7 +11,7 @@ <AnchorPane fx:id="anchorPane" prefHeight="800.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.bricked.ui.LevelController"> <children> <AnchorPane fx:id="anchorPaneGame" layoutX="22.0" layoutY="125.0" minHeight="650.0" minWidth="700.0" prefHeight="650.0" prefWidth="700.0" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="22.0" AnchorPane.rightAnchor="78.0" AnchorPane.topAnchor="125.0" /> - <VBox fx:id="vboxPowerUps" layoutX="745.0" layoutY="125.0" minHeight="454.0" minWidth="40.0" prefHeight="454.0" prefWidth="40.0" AnchorPane.bottomAnchor="221.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="125.0" /> + <VBox fx:id="vboxPowerUps" layoutX="745.0" layoutY="125.0" minHeight="338.0" minWidth="40.0" prefHeight="402.0" prefWidth="40.0" AnchorPane.bottomAnchor="273.0" AnchorPane.rightAnchor="15.0" AnchorPane.topAnchor="125.0" /> <HBox alignment="CENTER" layoutX="34.0" layoutY="23.0" prefHeight="100.0" prefWidth="275.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> <children> <Button fx:id="buttonBack" mnemonicParsing="false" onAction="#back" text="Back" /> @@ -63,5 +63,10 @@ <Font name="System Bold" size="16.0" /> </font> </Label> + <Label fx:id="labelMultiplicator" alignment="CENTER_RIGHT" layoutX="736.0" layoutY="543.0" prefHeight="30.0" prefWidth="49.0" text="x0" textAlignment="JUSTIFY" AnchorPane.rightAnchor="18.0" AnchorPane.topAnchor="543.0"> + <font> + <Font name="System Bold" size="20.0" /> + </font> + </Label> </children> </AnchorPane>