mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-06 13:30:15 +02:00
player now moves without animation
This commit is contained in:
@@ -23,7 +23,6 @@ import com.jme3.util.TangentBinormalGenerator;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.client.gui.BobTheBuilder;
|
||||
import pp.monopoly.client.gui.Toolbar;
|
||||
import pp.util.FloatMath;
|
||||
|
||||
import static pp.util.FloatMath.PI;
|
||||
import static pp.util.FloatMath.TWO_PI;
|
||||
@@ -86,11 +85,11 @@ public class BoardAppState extends MonopolyAppState {
|
||||
getApp().getRootNode().detachAllChildren();
|
||||
getApp().getGuiNode().detachAllChildren();
|
||||
|
||||
getApp().getGuiNode().attachChild(new Toolbar(getApp()));
|
||||
new Toolbar(getApp()).open();
|
||||
sceneNode.detachAllChildren();
|
||||
setupScene();
|
||||
if (bobTheBuilder == null) {
|
||||
bobTheBuilder = new BobTheBuilder(getApp(), sceneNode, getGameLogic().getBoard());
|
||||
bobTheBuilder = new BobTheBuilder(getApp(), getApp().getRootNode());
|
||||
getGameLogic().addListener(bobTheBuilder);
|
||||
}
|
||||
getApp().getRootNode().attachChild(viewNode);
|
||||
@@ -108,13 +107,13 @@ public class BoardAppState extends MonopolyAppState {
|
||||
final Board board = getGameLogic().getBoard();
|
||||
final float mx = 0.5f * board.getWidth();
|
||||
final float my = 0.5f * board.getHeight();
|
||||
// final float radius = 2f * sqrt(mx * mx + my + my);
|
||||
// final float cos = radius * cos(cameraAngle);
|
||||
// final float sin = radius * sin(cameraAngle);
|
||||
// final float x = mx - cos;
|
||||
// final float y = my - sin;
|
||||
final float radius = 2f * sqrt(mx * mx + my + my);
|
||||
final float cos = radius * cos(cameraAngle);
|
||||
final float sin = radius * sin(cameraAngle);
|
||||
final float x = mx - cos;
|
||||
final float y = my - sin;
|
||||
final Camera camera = getApp().getCamera();
|
||||
camera.setLocation(new Vector3f(20, ABOVE_SEA_LEVEL, 0));
|
||||
camera.setLocation(new Vector3f(x, ABOVE_SEA_LEVEL, y));
|
||||
camera.lookAt(new Vector3f(0,0, 0),
|
||||
Vector3f.UNIT_Y);
|
||||
camera.update();
|
||||
@@ -152,16 +151,16 @@ public class BoardAppState extends MonopolyAppState {
|
||||
*/
|
||||
private void setupLights() {
|
||||
final AssetManager assetManager = getApp().getAssetManager();
|
||||
// final DirectionalLightShadowRenderer shRend = new DirectionalLightShadowRenderer(assetManager, 2048, 3);
|
||||
// shRend.setLambda(0.55f);
|
||||
// shRend.setShadowIntensity(0.6f);
|
||||
// shRend.setEdgeFilteringMode(EdgeFilteringMode.Bilinear);
|
||||
// getApp().getViewPort().addProcessor(shRend);
|
||||
final DirectionalLightShadowRenderer shRend = new DirectionalLightShadowRenderer(assetManager, 2048, 3);
|
||||
shRend.setLambda(0.55f);
|
||||
shRend.setShadowIntensity(0.6f);
|
||||
shRend.setEdgeFilteringMode(EdgeFilteringMode.Bilinear);
|
||||
getApp().getViewPort().addProcessor(shRend);
|
||||
|
||||
// final DirectionalLight sun = new DirectionalLight();
|
||||
// sun.setDirection(new Vector3f(-1f, -0.7f, -1f).normalizeLocal());
|
||||
// viewNode.addLight(sun);
|
||||
// shRend.setLight(sun);
|
||||
final DirectionalLight sun = new DirectionalLight();
|
||||
sun.setDirection(new Vector3f(-1f, -0.7f, -1f).normalizeLocal());
|
||||
viewNode.addLight(sun);
|
||||
shRend.setLight(sun);
|
||||
|
||||
final AmbientLight ambientLight = new AmbientLight(new ColorRGBA(1f, 1f, 1f, 1f));
|
||||
viewNode.addLight(ambientLight);
|
||||
@@ -194,8 +193,7 @@ public class BoardAppState extends MonopolyAppState {
|
||||
final float y = board.getHeight();
|
||||
final Box seaMesh = new Box(y, 0.1f, x);
|
||||
final Geometry seaGeo = new Geometry("sea", seaMesh); //NON-NLS
|
||||
// seaGeo.setLocalTranslation(new Vector3f(y, -0.1f, x));
|
||||
// seaMesh.scaleTextureCoordinates(new Vector2f(4f, 4f));
|
||||
seaGeo.setLocalTranslation(new Vector3f(0, -0.1f, 0));
|
||||
final Material seaMat = new Material(getApp().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
|
||||
Texture texture = getApp().getAssetManager().loadTexture("Pictures/board2.png");
|
||||
seaMat.setTexture("DiffuseMap", texture);
|
||||
|
@@ -1,8 +1,13 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.lang.management.PlatformLoggingMXBean;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
@@ -10,10 +15,12 @@ import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Box;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.Hotel;
|
||||
import pp.monopoly.model.House;
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
|
||||
public class BobTheBuilder extends GameBoardSynchronizer {
|
||||
|
||||
@@ -24,30 +31,42 @@ public class BobTheBuilder extends GameBoardSynchronizer {
|
||||
private static final String HOTEL = "hotel"; //NON-NLS
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Board board;
|
||||
|
||||
public BobTheBuilder(MonopolyApp app, Node root, Board board) {
|
||||
public BobTheBuilder(MonopolyApp app, Node root) {
|
||||
super(app.getGameLogic().getBoard(), root);
|
||||
this.app = app;
|
||||
this.board = board;
|
||||
addExisting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spatial visit(Figure figure) {
|
||||
try {
|
||||
// Lade das Modell
|
||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel(
|
||||
"models/" + "Spielfiguren/" + figure.getType() + "/" + figure.getType() + ".j3o");
|
||||
|
||||
// Skaliere und positioniere das Modell
|
||||
model.setLocalScale(0.5f);
|
||||
model.setLocalTranslation(figure.getPosition());
|
||||
|
||||
// Setze die Rotation basierend auf der Feld-ID
|
||||
model.setLocalRotation(figure.getRot().toQuaternion());
|
||||
|
||||
return model;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Laden des Modells für Spieler " + e.getMessage());
|
||||
}
|
||||
return createBox(figure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spatial visit(Hotel hotel) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visit'");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spatial visit(House figure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visit'");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +75,7 @@ public class BobTheBuilder extends GameBoardSynchronizer {
|
||||
* @param ship the battleship to be represented
|
||||
* @return the geometry representing the battleship as a box
|
||||
*/
|
||||
private Spatial createBox(Figure figure) {
|
||||
private Spatial createBox(Item item) {
|
||||
final Box box = new Box(3,
|
||||
3f,
|
||||
3);
|
||||
@@ -87,4 +106,15 @@ public class BobTheBuilder extends GameBoardSynchronizer {
|
||||
return material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(UpdatePlayerView event) {
|
||||
clear();
|
||||
board.removePlayers();
|
||||
for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) {
|
||||
board.add(player.getFigure());
|
||||
}
|
||||
for (Item item : board.getItems().stream().filter(p -> p instanceof Figure).collect(Collectors.toList())) {
|
||||
add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,12 @@ import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.monopoly.model.Item;
|
||||
import pp.monopoly.model.Visitor;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.ItemAddedEvent;
|
||||
import pp.monopoly.notification.ItemRemovedEvent;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.view.ModelViewSynchronizer;
|
||||
|
||||
/**
|
||||
@@ -22,7 +23,7 @@ import pp.view.ModelViewSynchronizer;
|
||||
*/
|
||||
abstract class GameBoardSynchronizer extends ModelViewSynchronizer<Item> implements Visitor<Spatial>, GameEventListener {
|
||||
// The board that this synchronizer is responsible for
|
||||
private final Board board;
|
||||
protected final Board board;
|
||||
|
||||
/**
|
||||
* Constructs a new GameBoardSynchronizer.
|
||||
@@ -57,32 +58,23 @@ abstract class GameBoardSynchronizer extends ModelViewSynchronizer<Item> impleme
|
||||
board.getItems().forEach(this::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when an item is removed from the board.
|
||||
* Removes the visual representation of the item from the view if it belongs to the synchronized board.
|
||||
*
|
||||
* @param event the event indicating that an item has been removed from the board
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(ItemRemovedEvent event) {
|
||||
if (board == event.board())
|
||||
delete(event.item());
|
||||
public void receivedEvent(UpdatePlayerView event) {
|
||||
for (Item item : board.getItems()) {
|
||||
// if(!(item instanceof Figure)) {
|
||||
delete(item);
|
||||
add(item);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when an item is added to the board.
|
||||
* Adds the visual representation of the new item to the view if it belongs to the synchronized board.
|
||||
*
|
||||
* @param event the event indicating that an item has been added to the board
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(ItemAddedEvent event) {
|
||||
if (board == event.board())
|
||||
add(event.item());
|
||||
public void receivedEvent(DiceRollEvent event) {
|
||||
for (Item item : board.getItems()) {
|
||||
if(item instanceof Figure) {
|
||||
//????????????????????????????????????????
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void recievedEvent(UpdatePlayerView event) {
|
||||
clear();
|
||||
addExisting();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user