diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java index 233aabb39effe29f652048b7d4d2add1e075523f..2fa308c092e50f98a701267a53a53cf59b0eeb30 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java @@ -1,5 +1,7 @@ package de.hdm_stuttgart.battlearena.Controller; +import de.hdm_stuttgart.battlearena.Controller.Utilities.ScreenClasses; +import de.hdm_stuttgart.battlearena.Controller.Utilities.ScreenDimensionCalculator; import de.hdm_stuttgart.battlearena.Controller.Enum.GameMode; import de.hdm_stuttgart.battlearena.Controller.Enum.GameState; import de.hdm_stuttgart.battlearena.Controller.Enum.PlayerMode; @@ -14,11 +16,22 @@ import de.hdm_stuttgart.battlearena.Model.Map.Biom; import de.hdm_stuttgart.battlearena.Model.Map.TileManager; import javafx.animation.AnimationTimer; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.geometry.Insets; +import javafx.geometry.Rectangle2D; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; +import javafx.scene.control.Label; +import javafx.scene.control.Slider; +import javafx.scene.layout.*; +import javafx.scene.shape.Rectangle; +import javafx.scene.text.Font; +import javafx.scene.text.Text; +import javafx.stage.Screen; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -33,6 +46,20 @@ public class GameSceneController implements Initializable { @FXML private Canvas canvas2D; + @FXML + private Slider slider, slider2; + @FXML + private Rectangle playerHealth, enemyHealth; + @FXML + private Pane playerPane, enemyPane; + @FXML + private Label playerHp, enemyHp, time, round; + @FXML + private StackPane stackPane; + Screen screen = Screen.getPrimary(); + Rectangle2D visualBounds = screen.getVisualBounds(); + final private double healthBarWidth = screen.getBounds().getWidth() / 5; + ScreenDimensionCalculator screenCalculator = new ScreenDimensionCalculator(); private GraphicsContext graphicsContext2D; @@ -99,6 +126,51 @@ public class GameSceneController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { + double diagonalInches = screenCalculator.calculateDiagonalInches(visualBounds.getWidth(), + visualBounds.getHeight(), screen.getDpi()); +// for some reason scene builder overwrites css fonts bruh + playerHp.setFont(Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 55)); + enemyHp.setFont(Font.loadFont(getClass().getResourceAsStream("/fonts/StarshipShadow.ttf"), 55)); + playerHp.setText("100%"); + playerHp.setMinWidth(120); + playerHp.setMaxWidth(120); + enemyHp.setText("100%"); + enemyHp.setMinWidth(120); + +// stopping the VBox from shrinking when health bar gets smaller + playerPane.setMinWidth(healthBarWidth); + playerPane.setMaxWidth(healthBarWidth); + enemyPane.setMinWidth(healthBarWidth); + enemyPane.setMaxWidth(healthBarWidth); + + playerHealth.setWidth(healthBarWidth); + enemyHealth.setWidth(healthBarWidth); + +// make it responsive + stackPane.heightProperty().addListener((observableValue, oldValue, newValue) -> { + canvas2D.setScaleY(newValue.doubleValue() / 870); + canvas2D.setScaleX(newValue.doubleValue() / 870); + }); + + System.out.println(stackPane.heightProperty()); + System.out.println("dpi: " + screen.getDpi()); + +// testing hp bar + slider.valueProperty().addListener((observableValue, oldValue, newValue) -> { + System.out.println(stackPane.widthProperty().doubleValue()); + System.out.println(stackPane.heightProperty().doubleValue()); + double newWidth = healthBarWidth * (newValue.doubleValue() / 100); + playerHealth.setWidth(newWidth); + playerHp.setText(newValue.intValue() + "%"); + }); + slider2.valueProperty().addListener((observableValue, oldValue, newValue) -> { + double newWidth = healthBarWidth * (newValue.doubleValue() / 100); + enemyHealth.setWidth(newWidth); + enemyHp.setText(newValue.intValue() + "%"); + }); + + System.out.println("inches: " + diagonalInches); + graphicsContext2D = canvas2D.getGraphicsContext2D(); graphicsContext2D.setImageSmoothing(false); diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java index 9e27cab1e0a87b52e01a1ea63b84ba6cf6b46006..5276d92651d747ed1ad42b757b0d3c3fde9c241a 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/SkinSelectionController.java @@ -54,8 +54,6 @@ public class SkinSelectionController implements Initializable { @FXML private void gameScene() { - - parent.getChildren().clear(); parent.getChildren().add(new SceneLoader().loadScene("MapSelection")); } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Main/Driver.java b/src/main/java/de/hdm_stuttgart/battlearena/Main/Driver.java index 66f93ada9d0e18cccb86262356517c4f79d881e3..3c296f75fcc5cbe62f220a50248ce70474712ac5 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Main/Driver.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Main/Driver.java @@ -38,7 +38,7 @@ public class Driver extends Application { Font.loadFont(getClass().getResourceAsStream("/fonts/Arthemis-mLA22.ttf"), 50); Font.loadFont(getClass().getResourceAsStream("/fonts/ShadowsIntoLight-Regular.ttf"), 50); - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/LoadingScreen.fxml"))); + Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/Intro.fxml"))); Scene scene = new Scene(root); diff --git a/src/main/resources/fxml/GameScene.fxml b/src/main/resources/fxml/GameScene.fxml index f046db58280a8ea339f035b1879ac8e6e73b8115..6d70dc666e6853e4ab00cbc6f775eed560ad16dc 100644 --- a/src/main/resources/fxml/GameScene.fxml +++ b/src/main/resources/fxml/GameScene.fxml @@ -1,15 +1,84 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> <?import javafx.scene.canvas.Canvas?> -<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.Slider?> +<?import javafx.scene.layout.BorderPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.StackPane?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.shape.Rectangle?> -<AnchorPane prefHeight="864.0" prefWidth="864.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.GameSceneController"> - <children> - <StackPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> +<BorderPane fx:id="gameScene" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.GameSceneController"> + <center> + <StackPane fx:id="stackPane" prefHeight="400.0" prefWidth="600.0" BorderPane.alignment="CENTER"> <children> <Canvas fx:id="canvas2D" height="864.0" width="864.0" /> </children> + <BorderPane.margin> + <Insets /> + </BorderPane.margin> </StackPane> - </children> -</AnchorPane> + </center> + <top> + <VBox BorderPane.alignment="CENTER"> + <children> + <Pane prefHeight="50.0" VBox.vgrow="ALWAYS" /> + <HBox alignment="CENTER" spacing="30.0"> + <children> + <HBox alignment="CENTER_RIGHT" fillHeight="false" spacing="10.0"> + <children> + <Label text="Player HP" /> + <Pane fx:id="playerPane" nodeOrientation="RIGHT_TO_LEFT"> + <children> + <Rectangle fx:id="playerHealth" arcHeight="5.0" arcWidth="5.0" fill="#c92c1a" height="50.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="900.0" /> + </children> + </Pane> + <Label fx:id="playerHp" alignment="CENTER_RIGHT" /> + </children> + </HBox> + <HBox alignment="CENTER_LEFT" fillHeight="false" spacing="10.0"> + <children> + <Label fx:id="enemyHp" /> + <Pane fx:id="enemyPane" HBox.hgrow="ALWAYS"> + <children> + <Rectangle fx:id="enemyHealth" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="50.0" stroke="BLACK" strokeType="INSIDE" strokeWidth="0.0" width="900.0" /> + </children> + </Pane> + <Label text="Enemy HP" /> + </children> + </HBox> + </children> + </HBox> + </children> + </VBox> + </top> + <left> + <VBox alignment="CENTER" prefHeight="200.0" prefWidth="300.0" BorderPane.alignment="CENTER"> + <children> + <Slider fx:id="slider" orientation="VERTICAL" value="100.0" /> + <Slider fx:id="slider2" orientation="VERTICAL" value="100.0" /> + </children> + </VBox> + </left> + <right> + <HBox BorderPane.alignment="CENTER"> + <children> + <VBox prefHeight="200.0"> + <children> + <Pane VBox.vgrow="ALWAYS" /> + <Label text="Time:" /> + <Label fx:id="time" text="00:30" /> + <Pane VBox.vgrow="ALWAYS" /> + <Label text="Round:" /> + <Label fx:id="round" text="1/3" /> + <Pane VBox.vgrow="ALWAYS" /> + </children> + </VBox> + <Pane prefWidth="200.0" HBox.hgrow="ALWAYS" /> + </children> + </HBox> + </right> +</BorderPane> diff --git a/src/main/resources/styles/style.css b/src/main/resources/styles/style.css index 0389e5bbbcc594716ff89c2a3d73e0dfd7fc61a3..c6d0d1c3446bc10e5bdcf9c19cc7c6d94fb33bce 100644 --- a/src/main/resources/styles/style.css +++ b/src/main/resources/styles/style.css @@ -43,6 +43,11 @@ -fx-font-family: "Starship Shadow"; } +#gameScene { + -fx-background-image: url("../textures/images/game_scene_backgorund.jpg"); + -fx-background-size: cover; +} + .button { -fx-text-fill: -fx-brown; -fx-background-color: none; diff --git a/src/main/resources/textures/images/game_scene_backgorund.jpg b/src/main/resources/textures/images/game_scene_backgorund.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4582a8a16813744f793a6f78424321548071ca01 Binary files /dev/null and b/src/main/resources/textures/images/game_scene_backgorund.jpg differ diff --git a/src/main/resources/textures/images/test.jpg b/src/main/resources/textures/images/test.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0618af6c2edbd72fc986c19759f2a3c102dabcc5 Binary files /dev/null and b/src/main/resources/textures/images/test.jpg differ