diff --git a/src/de/bricked/game/Game.java b/src/de/bricked/game/Game.java index 55c5166f23ae4a7cc73461441696b5d1e7c932a9..a578cfbb89ffaefb1aba35dc9525ec2be01ec140 100644 --- a/src/de/bricked/game/Game.java +++ b/src/de/bricked/game/Game.java @@ -5,6 +5,7 @@ import de.bricked.game.board.Board; import de.bricked.game.levels.Level; import de.bricked.game.levels.LevelPack; import de.bricked.game.settings.Settings; +import de.bricked.ui.LevelController; import javafx.geometry.Point2D; import logger.LogLevel; import logger.Logger; @@ -23,6 +24,7 @@ public class Game private final double speedIncreasePerPaddleHitFactor = 1.05; private int pointsSinceLastMultiplicatorReset; private int multiplicator; + private LevelController levelController; public Game() { @@ -35,6 +37,7 @@ public class Game this.board = null; this.multiplicator = 1; this.pointsSinceLastMultiplicatorReset = 0; + this.levelController = null; } public Settings getSettings() @@ -140,7 +143,17 @@ public class Game public void applyMultiplicator() { totalPoints += pointsSinceLastMultiplicatorReset * multiplicator; - System.out.println(pointsSinceLastMultiplicatorReset + " x" + multiplicator + " = " + totalPoints); + Logger.log(LogLevel.DEBUG, "Applied multiplicator: " + pointsSinceLastMultiplicatorReset + " x" + multiplicator + " = " + totalPoints); + } + + public LevelController getLevelController() + { + return levelController; + } + + public void setLevelController(LevelController levelController) + { + this.levelController = levelController; } public Point2D reflectBall(HitLocation hitLocation, Point2D direction) diff --git a/src/de/bricked/game/board/Board.java b/src/de/bricked/game/board/Board.java index d03a66b6fcee3cd69d086f8c1acde4ee8c509acf..8a7767880ebff3d0eb98cd5b4a4ef9856a1c0a22 100644 --- a/src/de/bricked/game/board/Board.java +++ b/src/de/bricked/game/board/Board.java @@ -210,6 +210,7 @@ public class Board points += hittedBrick.getType().getPoints(); + game.getLevelController().showAnimatedPoints(row, col, hittedBrick.getType().getPoints()); game.increaseMultiplicator(); LevelController.redrawBrick(col, row, bricks.get(row).get(col), true); } diff --git a/src/de/bricked/ui/LevelController.java b/src/de/bricked/ui/LevelController.java index 7b64d937de0f6eb903b388835f58962eb36bae75..ab93716ee0549c708ab414b6530f1ca907ba9770 100644 --- a/src/de/bricked/ui/LevelController.java +++ b/src/de/bricked/ui/LevelController.java @@ -19,6 +19,8 @@ import fontAwesome.FontIcon; import fontAwesome.FontIconType; import javafx.animation.AnimationTimer; import javafx.animation.FadeTransition; +import javafx.animation.ParallelTransition; +import javafx.animation.TranslateTransition; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; @@ -96,6 +98,7 @@ public class LevelController this.levelSelectController = levelSelectController; this.game = game; game.setBoard(new Board(game)); + game.setLevelController(this); anchorPane.setOnKeyReleased(new EventHandler<KeyEvent>() { @@ -549,9 +552,8 @@ public class LevelController { 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(); - + }); + ft.play(); } else { @@ -563,7 +565,7 @@ public class LevelController { vboxLives.getChildren().clear(); - for(int i = 0; i < MAX_LIVES - game.getLivesRemaining(); i++) + for(int i = 0; i < MAX_LIVES - game.getLivesRemaining() + 1; i++) { ImageView iv = new ImageView(new Image("de/bricked/resources/textures/bricks/empty.png")); iv.setFitWidth(30); @@ -575,7 +577,7 @@ public class LevelController } } - for(int i = 0; i < game.getLivesRemaining(); i++) + for(int i = 0; i < game.getLivesRemaining() - 1; i++) { ImageView iv = new ImageView(new Image("de/bricked/resources/textures/paddle/paddle-extra-small.png")); iv.setFitWidth(30); @@ -715,6 +717,46 @@ public class LevelController } } } + + public void showAnimatedPoints(int row, int col, int points) + { + double xPosition = (gamePaneWidth / Board.WIDTH) * (col); + double yPosition = (gamePaneHeight / Board.HEIGHT) * (row); + + Label labelNotification = new Label("+" + points); + labelNotification.setTranslateX(xPosition); + labelNotification.setTranslateY(yPosition); + labelNotification.setStyle("-fx-font-weight: bold; -fx-font-size: 15; "); + labelNotification.setAlignment(Pos.CENTER); + labelNotification.setPrefWidth(gamePaneWidth / Board.WIDTH); + labelNotification.setPrefHeight(gamePaneHeight / Board.HEIGHT); + anchorPaneGame.getChildren().add(labelNotification); + + FadeTransition fadeTransition = new FadeTransition(Duration.millis(1200), labelNotification); + fadeTransition.setFromValue(1.0); + fadeTransition.setToValue(0.0); + fadeTransition.setCycleCount(1); + fadeTransition.setAutoReverse(false); + TranslateTransition translateTransition = new TranslateTransition(Duration.millis(1200), labelNotification); + translateTransition.setFromY(yPosition); + translateTransition.setToY(yPosition - (gamePaneHeight / Board.HEIGHT)); + translateTransition.setCycleCount(1); + translateTransition.setAutoReverse(false); + + ParallelTransition parallelTransition = new ParallelTransition(); + parallelTransition.getChildren().addAll(fadeTransition, translateTransition); + parallelTransition.setCycleCount(1); + parallelTransition.setOnFinished(new EventHandler<ActionEvent>() + { + @Override + public void handle(ActionEvent event) + { + anchorPaneGame.getChildren().remove(labelNotification); + } + }); + + parallelTransition.play(); + } public void showLabelFPS(boolean value) { @@ -745,6 +787,8 @@ public class LevelController game.setTotalPoints(0); game.resetMultiplicator(); game.resetPointsSinceLastMultiplicatorReset(); + game.setBoard(null); + game.setLevelController(null); anchorPaneGame.requestFocus(); }