Skip to content
Snippets Groups Projects
Commit 46acb063 authored by Scherbaum Maximilian's avatar Scherbaum Maximilian
Browse files

update: added test map in GameSceneController.java, add: textures, update:...

update: added test map in GameSceneController.java, add: textures, update: variables in TileManager.java #41 #39
parent 197d3088
No related branches found
No related tags found
3 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development
Showing with 48 additions and 8 deletions
...@@ -4,6 +4,7 @@ import de.hdm_stuttgart.battlearena.Model.Entity.EntityFactory; ...@@ -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.EntityType;
import de.hdm_stuttgart.battlearena.Model.Entity.IEntity; import de.hdm_stuttgart.battlearena.Model.Entity.IEntity;
import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler; import de.hdm_stuttgart.battlearena.Model.Inputs.InputHandler;
import de.hdm_stuttgart.battlearena.Model.Map.TileManager;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.fxml.FXML; import javafx.fxml.FXML;
...@@ -31,14 +32,42 @@ public class GameSceneController implements Initializable { ...@@ -31,14 +32,42 @@ public class GameSceneController implements Initializable {
IEntity player; IEntity player;
IEntity enemy; 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 @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
graphicsContext2D = canvas2D.getGraphicsContext2D(); graphicsContext2D = canvas2D.getGraphicsContext2D();
graphicsContext2D.setImageSmoothing(false);
player = EntityFactory.createEntity(EntityType.PLAYER, graphicsContext2D, inputHandler); player = EntityFactory.createEntity(EntityType.PLAYER, graphicsContext2D, inputHandler);
enemy = EntityFactory.createEntity(EntityType.ENEMY_PLAYER, graphicsContext2D, inputHandler); enemy = EntityFactory.createEntity(EntityType.ENEMY_PLAYER, graphicsContext2D, inputHandler);
tileManager = new TileManager(graphicsContext2D, diffTileCount, horizontalTileCount, verticalTileCount, mapString);
AnimationTimer gameLoop = new AnimationTimer() { AnimationTimer gameLoop = new AnimationTimer() {
@Override @Override
public void handle(long l) { public void handle(long l) {
...@@ -58,6 +87,7 @@ public class GameSceneController implements Initializable { ...@@ -58,6 +87,7 @@ public class GameSceneController implements Initializable {
} }
private void renderContent(GraphicsContext graphicsContext) { private void renderContent(GraphicsContext graphicsContext) {
tileManager.renderMap();
player.renderEntity(graphicsContext); player.renderEntity(graphicsContext);
enemy.renderEntity(graphicsContext); enemy.renderEntity(graphicsContext);
} }
......
...@@ -61,7 +61,7 @@ class Player implements IEntity { ...@@ -61,7 +61,7 @@ class Player implements IEntity {
mapPosX = 10; mapPosX = 10;
mapPosY = 10; mapPosY = 10;
boxCollider = new BoundingBox(mapPosX+15,mapPosY+10, playerWidth, playerHeight); boxCollider = new BoundingBox(mapPosX+15,mapPosY+10, playerWidth, playerHeight);
playerSpeed = 3; playerSpeed = 5;
playerDirection = EntityDirection.DOWN; playerDirection = EntityDirection.DOWN;
} }
......
...@@ -16,9 +16,14 @@ public class TileManager { ...@@ -16,9 +16,14 @@ public class TileManager {
private final ITile[] tileSet; private final ITile[] tileSet;
private final int[][] tileMap; private final int[][] tileMap;
private final int horizontalTileCount;
private final int verticalTileCount;
public TileManager(GraphicsContext graphicsContext2D, int diffTileCount, public TileManager(GraphicsContext graphicsContext2D, int diffTileCount,
int horizontalTileCount, int verticalTileCount, String mapString) { int horizontalTileCount, int verticalTileCount, String mapString) {
this.graphicsContext2D = graphicsContext2D; this.graphicsContext2D = graphicsContext2D;
this.horizontalTileCount = horizontalTileCount;
this.verticalTileCount = verticalTileCount;
tileSet = new BackgroundTile[diffTileCount]; tileSet = new BackgroundTile[diffTileCount];
tileMap = new int[horizontalTileCount][verticalTileCount]; tileMap = new int[horizontalTileCount][verticalTileCount];
...@@ -30,9 +35,15 @@ public class TileManager { ...@@ -30,9 +35,15 @@ public class TileManager {
private void createTiles() { private void createTiles() {
try { try {
tileSet[0] = TileFactory.createTile(TileType.WALKABLE, tileSet[0] = TileFactory.createTile(TileType.WALKABLE,
new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/mapPlaceholder.png")))); new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/Grass01.png"))));
tileSet[1] = TileFactory.createTile(TileType.NON_WALKABLE, tileSet[1] = TileFactory.createTile(TileType.WALKABLE,
new Image(Objects.requireNonNull(getClass().getResourceAsStream("/textures/map/stoneExampleTexture.png")))); 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) { } catch (Exception e) {
log.error(e); log.error(e);
} }
...@@ -51,7 +62,7 @@ public class TileManager { ...@@ -51,7 +62,7 @@ public class TileManager {
} }
} }
public void renderMap(int horizontalTileCount, int verticalTileCount) { public void renderMap() {
int currentTile; int currentTile;
int scaledTileSize = 48; //todo: later replace "48" with value from gameScene. int scaledTileSize = 48; //todo: later replace "48" with value from gameScene.
int tilePosX; int tilePosX;
......
...@@ -4,12 +4,11 @@ ...@@ -4,12 +4,11 @@
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<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">
<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">
<children> <children>
<StackPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <StackPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<Canvas fx:id="canvas2D" height="400.0" width="600.0" /> <Canvas fx:id="canvas2D" height="864.0" width="864.0" />
</children> </children>
</StackPane> </StackPane>
</children> </children>
......
src/main/resources/textures/map/Grass01.png

1.76 KiB

src/main/resources/textures/map/Grass02.png

1.76 KiB

src/main/resources/textures/map/Grass04.png

1.91 KiB

src/main/resources/textures/map/Stone01.png

1.82 KiB

src/main/resources/textures/map/Stone02.png

1.91 KiB

src/main/resources/textures/map/mapPlaceholder.png

3.15 KiB

src/main/resources/textures/map/stoneExampleTexture.png

3.03 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment