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 9c8b490df483b17ae295a4ecfe3f275f4c34990e..3882c1e0910fa85dfd653a439af08406de48d0ce 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Controller/GameSceneController.java @@ -4,6 +4,7 @@ import de.hdm_stuttgart.battlearena.Model.Entity.EntityFactory; import de.hdm_stuttgart.battlearena.Model.Entity.EntityType; import de.hdm_stuttgart.battlearena.Model.Entity.IEntity; import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler; +import de.hdm_stuttgart.battlearena.Model.Map.TileManager; import javafx.animation.AnimationTimer; import javafx.fxml.FXML; @@ -31,14 +32,42 @@ public class GameSceneController implements Initializable { IEntity player; IEntity enemy; + TileManager tileManager; + + //map data + String mapString = "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 " + + "4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 " + + "4 2 1 1 1 1 1 2 2 2 1 1 1 1 2 1 1 3 " + + "4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 2 3 " + + "4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 1 2 3 " + + "4 1 1 1 2 2 4 1 3 3 3 1 1 1 3 2 2 3 " + + "4 1 1 1 2 2 4 1 1 1 1 1 1 1 3 2 1 3 " + + "4 1 1 1 2 2 4 3 3 1 4 3 3 3 3 2 1 3 " + + "4 1 1 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 " + + "4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 1 3 " + + "4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 1 1 3 " + + "4 1 1 1 1 2 4 3 3 1 3 3 3 3 3 2 2 3 " + + "4 1 1 1 1 1 4 3 3 1 3 3 3 3 3 1 2 3 " + + "4 1 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 3 " + + "4 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 3 " + + "4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 " + + "4 1 1 1 2 2 4 3 3 1 3 3 3 3 3 2 2 3 " + + "4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3"; + int horizontalTileCount = 18; + int verticalTileCount = 18; + int diffTileCount = 5; + @Override public void initialize(URL url, ResourceBundle resourceBundle) { graphicsContext2D = canvas2D.getGraphicsContext2D(); + graphicsContext2D.setImageSmoothing(false); player = EntityFactory.createEntity(EntityType.PLAYER, graphicsContext2D, inputHandler); enemy = EntityFactory.createEntity(EntityType.ENEMY_PLAYER, graphicsContext2D, inputHandler); + tileManager = new TileManager(graphicsContext2D, diffTileCount, horizontalTileCount, verticalTileCount, mapString); + AnimationTimer gameLoop = new AnimationTimer() { @Override public void handle(long l) { @@ -58,6 +87,7 @@ public class GameSceneController implements Initializable { } private void renderContent(GraphicsContext graphicsContext) { + tileManager.renderMap(); player.renderEntity(graphicsContext); enemy.renderEntity(graphicsContext); } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java index 838affe1b64f8a582f9b722e102c15b6cf735f92..f3242a2dc72b074b55fe35869a4941d36d141ce2 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Entity/Player.java @@ -61,7 +61,7 @@ class Player implements IEntity { mapPosX = 10; mapPosY = 10; boxCollider = new BoundingBox(mapPosX+15,mapPosY+10, playerWidth, playerHeight); - playerSpeed = 3; + playerSpeed = 5; playerDirection = EntityDirection.DOWN; } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java index 885d23082071f17dea32bac8ec2efcd8eaffefc7..cc320b3a4319b544d2348a7d2cf9ae4b844a6ba1 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/Map/TileManager.java @@ -16,9 +16,14 @@ public class TileManager { private final ITile[] tileSet; private final int[][] tileMap; + private final int horizontalTileCount; + private final int verticalTileCount; + public TileManager(GraphicsContext graphicsContext2D, int diffTileCount, int horizontalTileCount, int verticalTileCount, String mapString) { this.graphicsContext2D = graphicsContext2D; + this.horizontalTileCount = horizontalTileCount; + this.verticalTileCount = verticalTileCount; tileSet = new BackgroundTile[diffTileCount]; tileMap = new int[horizontalTileCount][verticalTileCount]; @@ -30,9 +35,15 @@ public class TileManager { private void createTiles() { try { tileSet[0] = TileFactory.createTile(TileType.WALKABLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/mapPlaceholder.png")))); - tileSet[1] = TileFactory.createTile(TileType.NON_WALKABLE, - new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/stoneExampleTexture.png")))); + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass01.png")))); + tileSet[1] = TileFactory.createTile(TileType.WALKABLE, + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass02.png")))); + tileSet[2] = TileFactory.createTile(TileType.WALKABLE, + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass04.png")))); + tileSet[3] = TileFactory.createTile(TileType.NON_WALKABLE, + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone01.png")))); + tileSet[4] = TileFactory.createTile(TileType.NON_WALKABLE, + new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Stone02.png")))); } catch (Exception e) { log.error(e); } @@ -51,7 +62,7 @@ public class TileManager { } } - public void renderMap(int horizontalTileCount, int verticalTileCount) { + public void renderMap() { int currentTile; int scaledTileSize = 48; //todo: later replace "48" with value from gameScene. int tilePosX; diff --git a/src/main/resources/fxml/GameScene.fxml b/src/main/resources/fxml/GameScene.fxml index f6f5b8cd737838ead77cba00d573bf5bf630dca6..f046db58280a8ea339f035b1879ac8e6e73b8115 100644 --- a/src/main/resources/fxml/GameScene.fxml +++ b/src/main/resources/fxml/GameScene.fxml @@ -4,12 +4,11 @@ <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.StackPane?> - -<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.GameSceneController"> +<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"> <children> - <Canvas fx:id="canvas2D" height="400.0" width="600.0" /> + <Canvas fx:id="canvas2D" height="864.0" width="864.0" /> </children> </StackPane> </children> diff --git a/src/main/resources/textures/map/Grass01.png b/src/main/resources/textures/map/Grass01.png new file mode 100644 index 0000000000000000000000000000000000000000..e835d4676d2f80105626ece4d99b485a30b289fe Binary files /dev/null and b/src/main/resources/textures/map/Grass01.png differ diff --git a/src/main/resources/textures/map/Grass02.png b/src/main/resources/textures/map/Grass02.png new file mode 100644 index 0000000000000000000000000000000000000000..144fad81f75b681454b58768081394cb40aaeead Binary files /dev/null and b/src/main/resources/textures/map/Grass02.png differ diff --git a/src/main/resources/textures/map/Grass04.png b/src/main/resources/textures/map/Grass04.png new file mode 100644 index 0000000000000000000000000000000000000000..4ce012b5eac6c41488efe96c5f66eb43c28c98ce Binary files /dev/null and b/src/main/resources/textures/map/Grass04.png differ diff --git a/src/main/resources/textures/map/Stone01.png b/src/main/resources/textures/map/Stone01.png new file mode 100644 index 0000000000000000000000000000000000000000..b6cf13f66633060803264739b889f64c32877a0e Binary files /dev/null and b/src/main/resources/textures/map/Stone01.png differ diff --git a/src/main/resources/textures/map/Stone02.png b/src/main/resources/textures/map/Stone02.png new file mode 100644 index 0000000000000000000000000000000000000000..2ac41bee77062960aa2d8cfc921f66e45de629ba Binary files /dev/null and b/src/main/resources/textures/map/Stone02.png differ diff --git a/src/main/resources/textures/map/mapPlaceholder.png b/src/main/resources/textures/map/mapPlaceholder.png deleted file mode 100644 index ca3f707dff2cf59fbcf284b896a786fafa5e9180..0000000000000000000000000000000000000000 Binary files a/src/main/resources/textures/map/mapPlaceholder.png and /dev/null differ diff --git a/src/main/resources/textures/map/stoneExampleTexture.png b/src/main/resources/textures/map/stoneExampleTexture.png deleted file mode 100644 index 29dfde5c4e557cfd2b1e4dc536f774faabea40a0..0000000000000000000000000000000000000000 Binary files a/src/main/resources/textures/map/stoneExampleTexture.png and /dev/null differ