Figurenbewegung

This commit is contained in:
Luca Puderbach
2024-12-09 04:19:00 +01:00
parent c4955e0b57
commit b819e1ca9b
5 changed files with 77 additions and 53 deletions

View File

@@ -120,7 +120,7 @@ public class BoardAppState extends MonopolyAppState {
final float x = mx - cos;
final float y = my - sin;
final Camera camera = getApp().getCamera();
camera.setLocation(new Vector3f(0,40,0));
camera.setLocation(new Vector3f(-30,25,-30));
camera.lookAt(new Vector3f(0,0, 0),
Vector3f.UNIT_Y);
camera.update();

View File

@@ -36,14 +36,15 @@ public class BobTheBuilder extends GameBoardSynchronizer {
@Override
public Spatial visit(Figure figure) {
final Node node = new Node(FIGURE);
node.attachChild(createFigure(figure));
Spatial spatial = createFigure(figure);
node.attachChild(spatial);
// Setze die Position basierend auf der Feld-ID
node.setLocalTranslation(figure.getPos());
// Setze die Rotation basierend auf der Feld-ID
node.setLocalRotation(figure.getRot().toQuaternion());
node.addControl(new FigureControl(figure));
node.addControl(new FigureControl(spatial, figure, app));
return node;
}
@@ -138,9 +139,4 @@ public class BobTheBuilder extends GameBoardSynchronizer {
material.setColor(COLOR, color);
return material;
}
@Override
public void receivedEvent(UpdatePlayerView event) {
//TODO player move animation
}
}

View File

@@ -2,17 +2,26 @@ package pp.monopoly.client.gui;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.model.Figure;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.UpdatePlayerView;
public class FigureControl extends AbstractControl {
public class FigureControl extends AbstractControl implements GameEventListener{
private final Figure figure;
private final Spatial spatial;
private final MonopolyApp app;
public FigureControl(Figure figure) {
public FigureControl(Spatial spatial, Figure figure, MonopolyApp app) {
super();
this.figure = figure;
this.app = app;
this.spatial = spatial;
app.getGameLogic().addListener(this);
}
@Override
@@ -24,5 +33,15 @@ public class FigureControl extends AbstractControl {
protected void controlRender(RenderManager rm, ViewPort vp) {
// No rendering required
}
@Override
public void receivedEvent(UpdatePlayerView event) {
int newPos = app.getGameLogic().getPlayerHandler().getPlayerById(figure.getId()).getFieldID();
figure.moveTo(newPos);
//TODO hier einzelne Punkte der Animation ablkaufen mit figure.setLocalTransLation und jeweils Rotation anpassen
spatial.setLocalTranslation(figure.getPos());
}
}