diff --git a/Projekte/.run/MdgaApp.run.xml b/Projekte/.run/MdgaApp.run.xml index a33a2cd3..abb487c3 100644 --- a/Projekte/.run/MdgaApp.run.xml +++ b/Projekte/.run/MdgaApp.run.xml @@ -1,18 +1,17 @@ - - + \ No newline at end of file diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/Asset.java similarity index 88% rename from Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java rename to Projekte/mdga/client/src/main/java/pp/mdga/client/Board/Asset.java index 25ac35f3..ad4ca6ed 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Asset.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/Asset.java @@ -1,4 +1,4 @@ -package pp.mdga.client; +package pp.mdga.client.Board; public enum Asset { bigTent, @@ -8,13 +8,13 @@ public enum Asset { jet, lw, marine, - node_home_blue("./node_home/node_home.j3o", "./node_home/node_home_blue.png"), - node_home_black("./node_home/node_home.j3o", "./node_home/node_home_black.png"), - node_home_green("./node_home/node_home.j3o", "./node_home/node_home_green.png"), - node_home_yellow("./node_home/node_home.j3o", "./node_home/node_home_yellow.png"), + node_home_blue("./node_home/node_home.j3o", "./node_home/node_home_blue_diff.png"), + node_home_black("./node_home/node_home.j3o", "./node_home/node_home_black_diff.png"), + node_home_green("./node_home/node_home.j3o", "./node_home/node_home_green_diff.png"), + node_home_yellow("./node_home/node_home.j3o", "./node_home/node_home_yellow_diff.png"), node_normal, - node_start("./node_normal/node_normal.j3o", "./node_normal/node_normal_start.png"), - node_bonus("./node_normal/node_normal.j3o", "./node_normal/node_normal_bonus.png"), + node_start("./node_normal/node_normal.j3o", "./node_normal/node_start_diff.png"), + node_bonus("./node_normal/node_normal.j3o", "./node_normal/node_bonus_diff.png"), radar, shieldCard, ship, @@ -22,7 +22,7 @@ public enum Asset { swapCard, tank, turboCard, - world(1.1f); + world(1.2f); private final String modelPath; private final String diffPath; diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/AssetOnMap.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/AssetOnMap.java new file mode 100644 index 00000000..e2700b00 --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/AssetOnMap.java @@ -0,0 +1,3 @@ +package pp.mdga.client.Board; + +public record AssetOnMap(Asset asset, int x, int y){} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/BoardView.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/BoardView.java index 7bbd1f1e..87677a70 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/BoardView.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/BoardView.java @@ -1,13 +1,21 @@ package pp.mdga.client.Board; +import com.jme3.material.Material; import com.jme3.math.Vector3f; +import com.jme3.renderer.queue.RenderQueue; +import com.jme3.scene.Spatial; +import pp.mdga.client.MdgaApp; import java.util.ArrayList; +import java.util.List; public class BoardView { - private static final float GRID_SIZE = 10.0f; + private static final float GRID_SIZE = 1.72f; private static final float GRID_ELEVATION = 0.0f; private static final int GRID_EXTEND = 5; + private static final String MAP_NAME = "map.mdga"; + + private final MdgaApp mdgaApp; private PileControl drawPile = new PileControl(); private PileControl discardPile = new PileControl(); @@ -15,16 +23,47 @@ public class BoardView { private ArrayList infield = new ArrayList(40); private ArrayList pieces; - BoardView(int playerCount) { + public BoardView(int playerCount, MdgaApp mdgaApp) { assert(2 <= playerCount && playerCount <= 4); + assert(mdgaApp != null); + + this.mdgaApp = mdgaApp; pieces = new ArrayList(4 * playerCount); + + + initMap(); + } + + private void initMap() { + List assetOnMaps = new MapLoader().loadMap(MAP_NAME); + + for (AssetOnMap assetOnMap : assetOnMaps){ + int x = assetOnMap.x(); + int y = assetOnMap.y(); + Spatial model = createModel(assetOnMap.asset()); + model.setLocalTranslation(gridToWorld(x,y)); + } + } + + private Spatial createModel(Asset asset){ + String modelName = asset.getModelPath(); + String texName = asset.getDiffPath(); + Spatial model = mdgaApp.getAssetManager().loadModel(modelName); + model.scale(asset.getSize()); + model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90)); + model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); + Material mat = new Material(mdgaApp.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); + mat.setTexture("DiffuseMap", mdgaApp.getAssetManager().loadTexture(texName)); + model.setMaterial(mat); + mdgaApp.getRootNode().attachChild(model); + return model; } private static Vector3f gridToWorld(int x, int y) { assert(-GRID_EXTEND <= x && x <= GRID_EXTEND); assert(-GRID_EXTEND <= y && y < GRID_EXTEND); - return new Vector3f(GRID_SIZE * x, GRID_ELEVATION, GRID_SIZE * y); + return new Vector3f(GRID_SIZE * x, GRID_SIZE * y, GRID_ELEVATION); } } diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/MapLoader.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/MapLoader.java new file mode 100644 index 00000000..fc60077c --- /dev/null +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/Board/MapLoader.java @@ -0,0 +1,65 @@ +package pp.mdga.client.Board; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class MapLoader { + public MapLoader(){ + + } + public List loadMap(String mapName) { + List assetsOnMap = new ArrayList<>(); + + try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mapName); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + + while (true) { + String entry = reader.readLine(); + if(entry == null) break; + + entry = entry.trim(); + + if(entry.isEmpty()) continue; + if(entry.charAt(0) == '#') continue; + + String[] parts = entry.trim().split(" "); + assert(parts.length == 2); + + String assetName = parts[0]; + String[] coordinates = parts[1].split(","); + + assert(coordinates.length == 2); + + int x = Integer.parseInt(coordinates[0]); + int y = Integer.parseInt(coordinates[1]); + + Asset asset = getLoadedAsset(assetName); + assetsOnMap.add(new AssetOnMap(asset, x, y)); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + + return assetsOnMap; + } + + private Asset getLoadedAsset(String assetName) { + return switch(assetName){ + case "node" -> Asset.node_normal; + case "node_start" -> Asset.node_start; + case "node_bonus" -> Asset.node_bonus; + case "node_home_blue" -> Asset.node_home_blue; + case "node_home_yellow" -> Asset.node_home_yellow; + case "node_home_black" -> Asset.node_home_black; + case "node_home_green" -> Asset.node_home_green; + case "world" -> Asset.world; + default -> throw new IllegalStateException("Unexpected value: " + assetName); + }; + } +} diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java index 1567ee4f..fb3740ba 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/MdgaApp.java @@ -1,21 +1,26 @@ package pp.mdga.client; import com.jme3.app.SimpleApplication; -import com.jme3.renderer.RenderManager; import pp.mdga.client.Animation.AnimationHandler; import com.jme3.light.AmbientLight; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; -import com.jme3.renderer.RenderManager; import com.jme3.renderer.queue.RenderQueue; import com.jme3.scene.Spatial; import com.jme3.shadow.DirectionalLightShadowRenderer; import com.jme3.system.AppSettings; +import pp.mdga.client.Board.Asset; +import pp.mdga.client.Board.AssetOnMap; +import pp.mdga.client.Board.BoardView; +import pp.mdga.client.Board.MapLoader; + +import java.util.List; public class MdgaApp extends SimpleApplication { private AnimationHandler animationHandler; + private BoardView boardView; public static void main(String[] args) { MdgaApp app = new MdgaApp(); @@ -32,6 +37,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { animationHandler = new AnimationHandler(this); + boardView = new BoardView(4,this); flyCam.setEnabled(true); int zoom = 20; @@ -51,37 +57,7 @@ public void simpleInitApp() { dlsr.setLight(sun); viewPort.addProcessor(dlsr); - createModel(Asset.lw).setLocalTranslation(new Vector3f(0,-10,0)); - createModel(Asset.cir).setLocalTranslation(new Vector3f(0,-8,0)); - createModel(Asset.marine).setLocalTranslation(new Vector3f(0,-6,0)); - createModel(Asset.heer).setLocalTranslation(new Vector3f(0,-4,0)); - createModel(Asset.node_normal).setLocalTranslation(new Vector3f(0,-2.5f,0)); - createModel(Asset.node_home_blue).setLocalTranslation(new Vector3f(0,-1,0)); - createModel(Asset.smallTent).setLocalTranslation(new Vector3f(0,1,0)); - createModel(Asset.tank).setLocalTranslation(new Vector3f(0,5,0)); - createModel(Asset.jet).setLocalTranslation(new Vector3f(0,12,0)); - createModel(Asset.ship).setLocalTranslation(new Vector3f(0,17,0)); - createModel(Asset.radar).setLocalTranslation(new Vector3f(0,20,0)); - createModel(Asset.world); - - //System.out.println(Asset.node_normal.getModelPath()); - //System.out.println(Asset.node_normal.getDiffPath()); - } - - - private Spatial createModel(Asset asset){ - String modelName = asset.getModelPath(); - String texName = asset.getDiffPath(); - Spatial model = assetManager.loadModel(modelName); - model.scale(asset.getSize()); - model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90)); - model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); - Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); - mat.setTexture("DiffuseMap", assetManager.loadTexture(texName)); - model.setMaterial(mat); - rootNode.attachChild(model); - return model; } @Override diff --git a/Projekte/mdga/client/src/main/resources/map.mdga b/Projekte/mdga/client/src/main/resources/map.mdga new file mode 100644 index 00000000..344daf81 --- /dev/null +++ b/Projekte/mdga/client/src/main/resources/map.mdga @@ -0,0 +1,64 @@ +world 0,0 + +#Nodes für Map +node_start -1,-5 +node -1,-4 +node -1,-3 +node -1,-2 +node_bonus -1,-1 +node -2,-1 +node -3,-1 +node -4,-1 +node -5,-1 +node -5,0 +node_start -5,1 +node -4,1 +node -3,1 +node -2,1 +node_bonus -1,1 +node -1,2 +node -1,3 +node -1,4 +node -1,5 +node 0,5 +node_start 1,5 +node 1,4 +node 1,3 +node 1,2 +node_bonus 1,1 +node 2,1 +node 3,1 +node 4,1 +node 5,1 +node 5,0 +node_start 5,-1 +node 4,-1 +node 3,-1 +node 2,-1 +node_bonus 1,-1 +node 1,-2 +node 1,-3 +node 1,-4 +node 1,-5 +node 0,-5 + +#Node Home +node_home_blue 0,-1 +node_home_blue 0,-2 +node_home_blue 0,-3 +node_home_blue 0,-4 + +node_home_black 0,1 +node_home_black 0,2 +node_home_black 0,3 +node_home_black 0,4 + +node_home_yellow 1,0 +node_home_yellow 2,0 +node_home_yellow 3,0 +node_home_yellow 4,0 + +node_home_green -1,0 +node_home_green -2,0 +node_home_green -3,0 +node_home_green -4,0 diff --git a/Projekte/mdga/client/src/main/resources/node_home/node_home_blue.png b/Projekte/mdga/client/src/main/resources/node_home/node_home_blue_diff.png similarity index 100% rename from Projekte/mdga/client/src/main/resources/node_home/node_home_blue.png rename to Projekte/mdga/client/src/main/resources/node_home/node_home_blue_diff.png