added playerMap for location playerAssets
This commit is contained in:
@@ -5,9 +5,13 @@
|
|||||||
import com.jme3.renderer.queue.RenderQueue;
|
import com.jme3.renderer.queue.RenderQueue;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import pp.mdga.client.MdgaApp;
|
import pp.mdga.client.MdgaApp;
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BoardView {
|
public class BoardView {
|
||||||
private static final float GRID_SIZE = 1.72f;
|
private static final float GRID_SIZE = 1.72f;
|
||||||
@@ -15,6 +19,7 @@ public class BoardView {
|
|||||||
private static final int GRID_EXTEND = 5;
|
private static final int GRID_EXTEND = 5;
|
||||||
private static final String MAP_NAME = "map.mdga";
|
private static final String MAP_NAME = "map.mdga";
|
||||||
|
|
||||||
|
|
||||||
private final MdgaApp mdgaApp;
|
private final MdgaApp mdgaApp;
|
||||||
|
|
||||||
private PileControl drawPile = new PileControl();
|
private PileControl drawPile = new PileControl();
|
||||||
@@ -23,35 +28,60 @@ public class BoardView {
|
|||||||
private ArrayList<NodeControl> infield = new ArrayList<NodeControl>(40);
|
private ArrayList<NodeControl> infield = new ArrayList<NodeControl>(40);
|
||||||
private ArrayList<PieceControl> pieces;
|
private ArrayList<PieceControl> pieces;
|
||||||
|
|
||||||
|
private Map<Color, List<AssetOnMap>> playerMap;
|
||||||
|
|
||||||
public BoardView(int playerCount, MdgaApp mdgaApp) {
|
public BoardView(int playerCount, MdgaApp mdgaApp) {
|
||||||
assert(2 <= playerCount && playerCount <= 4);
|
assert(2 <= playerCount && playerCount <= 4);
|
||||||
assert(mdgaApp != null);
|
assert(mdgaApp != null);
|
||||||
|
|
||||||
this.mdgaApp = mdgaApp;
|
this.mdgaApp = mdgaApp;
|
||||||
|
|
||||||
pieces = new ArrayList<PieceControl>(4 * playerCount);
|
this.pieces = new ArrayList<>(4 * playerCount);
|
||||||
|
this.playerMap = new HashMap<>();
|
||||||
|
|
||||||
initMap();
|
initMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addFigureToPlayerMap(Color col, AssetOnMap assetOnMap){
|
||||||
|
List<AssetOnMap> inMap = playerMap.getOrDefault(col, new ArrayList<>());
|
||||||
|
inMap.add(assetOnMap);
|
||||||
|
|
||||||
|
if(inMap.size() > 4) throw new RuntimeException("to many assets for one player");
|
||||||
|
|
||||||
|
playerMap.put(col, inMap);
|
||||||
|
}
|
||||||
|
|
||||||
private void initMap() {
|
private void initMap() {
|
||||||
List<AssetOnMap> assetOnMaps = new MapLoader().loadMap(MAP_NAME);
|
List<AssetOnMap> assetOnMaps = MapLoader.loadMap(MAP_NAME);
|
||||||
|
|
||||||
for (AssetOnMap assetOnMap : assetOnMaps){
|
for (AssetOnMap assetOnMap : assetOnMaps){
|
||||||
int x = assetOnMap.x();
|
switch (assetOnMap.asset()){
|
||||||
int y = assetOnMap.y();
|
case lw -> addFigureToPlayerMap(assetToColor(Asset.lw), assetOnMap);
|
||||||
Spatial model = createModel(assetOnMap.asset());
|
case heer -> addFigureToPlayerMap(assetToColor(Asset.heer), assetOnMap);
|
||||||
model.setLocalTranslation(gridToWorld(x,y));
|
case cir -> addFigureToPlayerMap(assetToColor(Asset.cir), assetOnMap);
|
||||||
|
case marine -> addFigureToPlayerMap(assetToColor(Asset.marine), assetOnMap);
|
||||||
|
default -> displayAsset(assetOnMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Spatial createModel(Asset asset){
|
private Color assetToColor(Asset asset){
|
||||||
|
return switch(asset){
|
||||||
|
case lw -> Color.AIRFORCE;
|
||||||
|
case heer -> Color.ARMY;
|
||||||
|
case marine -> Color.NAVY;
|
||||||
|
case cir -> Color.CYBER;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Spatial createModel(Asset asset, Vector3f pos){
|
||||||
String modelName = asset.getModelPath();
|
String modelName = asset.getModelPath();
|
||||||
String texName = asset.getDiffPath();
|
String texName = asset.getDiffPath();
|
||||||
Spatial model = mdgaApp.getAssetManager().loadModel(modelName);
|
Spatial model = mdgaApp.getAssetManager().loadModel(modelName);
|
||||||
model.scale(asset.getSize());
|
model.scale(asset.getSize());
|
||||||
model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90));
|
model.rotate((float) Math.toRadians(0), 0, (float) Math.toRadians(90));
|
||||||
|
model.setLocalTranslation(pos);
|
||||||
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
|
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
|
||||||
Material mat = new Material(mdgaApp.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
Material mat = new Material(mdgaApp.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||||
mat.setTexture("DiffuseMap", mdgaApp.getAssetManager().loadTexture(texName));
|
mat.setTexture("DiffuseMap", mdgaApp.getAssetManager().loadTexture(texName));
|
||||||
@@ -66,4 +96,19 @@ private static Vector3f gridToWorld(int x, int y) {
|
|||||||
|
|
||||||
return new Vector3f(GRID_SIZE * x, GRID_SIZE * y, GRID_ELEVATION);
|
return new Vector3f(GRID_SIZE * x, GRID_SIZE * y, GRID_ELEVATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayer(Color color){
|
||||||
|
List<AssetOnMap> playerAssets = playerMap.get(color);
|
||||||
|
if (playerAssets == null) throw new RuntimeException("Assets for Player color are not defined");
|
||||||
|
|
||||||
|
for (AssetOnMap assetOnMap : playerAssets){
|
||||||
|
displayAsset(assetOnMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayAsset(AssetOnMap assetOnMap){
|
||||||
|
int x = assetOnMap.x();
|
||||||
|
int y = assetOnMap.y();
|
||||||
|
Spatial model = createModel(assetOnMap.asset(), gridToWorld(x,y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MapLoader {
|
public class MapLoader {
|
||||||
public MapLoader(){
|
private MapLoader(){
|
||||||
|
|
||||||
}
|
}
|
||||||
public List<AssetOnMap> loadMap(String mapName) {
|
public static List<AssetOnMap> loadMap(String mapName) {
|
||||||
List<AssetOnMap> assetsOnMap = new ArrayList<>();
|
List<AssetOnMap> assetsOnMap = new ArrayList<>();
|
||||||
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mapName);
|
try (InputStream inputStream = MapLoader.class.getClassLoader().getResourceAsStream(mapName);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -49,8 +49,12 @@ public List<AssetOnMap> loadMap(String mapName) {
|
|||||||
return assetsOnMap;
|
return assetsOnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Asset getLoadedAsset(String assetName) {
|
private static Asset getLoadedAsset(String assetName) {
|
||||||
return switch(assetName){
|
return switch(assetName){
|
||||||
|
case "lw" -> Asset.lw;
|
||||||
|
case "cir" -> Asset.cir;
|
||||||
|
case "marine" -> Asset.marine;
|
||||||
|
case "heer" -> Asset.heer;
|
||||||
case "node" -> Asset.node_normal;
|
case "node" -> Asset.node_normal;
|
||||||
case "node_start" -> Asset.node_start;
|
case "node_start" -> Asset.node_start;
|
||||||
case "node_bonus" -> Asset.node_bonus;
|
case "node_bonus" -> Asset.node_bonus;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import pp.mdga.client.Board.AssetOnMap;
|
import pp.mdga.client.Board.AssetOnMap;
|
||||||
import pp.mdga.client.Board.BoardView;
|
import pp.mdga.client.Board.BoardView;
|
||||||
import pp.mdga.client.Board.MapLoader;
|
import pp.mdga.client.Board.MapLoader;
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ public static void main(String[] args) {
|
|||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
animationHandler = new AnimationHandler(this);
|
animationHandler = new AnimationHandler(this);
|
||||||
boardView = new BoardView(4,this);
|
boardView = new BoardView(4,this);
|
||||||
|
// boardView.addPlayer(Color.NAVY);
|
||||||
flyCam.setEnabled(true);
|
flyCam.setEnabled(true);
|
||||||
int zoom = 20;
|
int zoom = 20;
|
||||||
cam.setLocation(new Vector3f(zoom,0,zoom));
|
cam.setLocation(new Vector3f(zoom,0,zoom));
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
world 0,0
|
world 0,0
|
||||||
|
|
||||||
|
#Marine Pos
|
||||||
|
marine 4,-3
|
||||||
|
marine 4,-4
|
||||||
|
marine 5,-4
|
||||||
|
marine 5,-3
|
||||||
|
|
||||||
#Nodes für Map
|
#Nodes für Map
|
||||||
node_start -1,-5
|
node_start -1,-5
|
||||||
node -1,-4
|
node -1,-4
|
||||||
|
|||||||
Reference in New Issue
Block a user