Spawn Punkte korrigiert

This commit is contained in:
2026-08-10 11:51:42 +02:00
parent 21036a579c
commit 9561966071
9 changed files with 214 additions and 91 deletions

View File

@@ -1,5 +1,6 @@
package de.blight.game;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.ScreenshotAppState;
import com.jme3.input.KeyInput;
@@ -329,6 +330,35 @@ public class BlightGame extends SimpleApplication {
});
stateManager.attach(console);
// ── Debug-Stats (F3): oben-links, default aus ────────────────────────────
com.jme3.app.StatsAppState defaultStats = stateManager.getState(com.jme3.app.StatsAppState.class);
if (defaultStats != null) stateManager.detach(defaultStats);
com.jme3.app.StatsAppState statsState = new com.jme3.app.StatsAppState() {
@Override
public void initialize(com.jme3.app.state.AppStateManager sm, com.jme3.app.Application a) {
super.initialize(sm, a);
setDisplayFps(false);
setDisplayStatView(false);
int h = a.getCamera().getHeight();
if (fpsText != null) fpsText.setLocalTranslation(0, h, 0);
if (statsView != null) {
float fpsH = fpsText != null ? fpsText.getLineHeight() : 0f;
statsView.setLocalTranslation(0, h - fpsH, 0);
}
}
};
stateManager.attach(statsState);
final boolean[] statsVisible = {false};
inputManager.addMapping("ToggleStats", new KeyTrigger(KeyInput.KEY_F3));
inputManager.addListener((ActionListener) (name, isPressed, tpf) -> {
if (!isPressed) return;
com.jme3.app.StatsAppState s = stateManager.getState(com.jme3.app.StatsAppState.class);
if (s == null) return;
statsVisible[0] = !statsVisible[0];
s.setDisplayFps(statsVisible[0]);
s.setDisplayStatView(statsVisible[0]);
}, "ToggleStats");
// ── Debug: Nebel-Toggle (F7) ─────────────────────────────────────────────
inputManager.addMapping("DebugFog", new KeyTrigger(KeyInput.KEY_F7));
inputManager.addListener((ActionListener) (name, isPressed, tpf) -> {

View File

@@ -38,6 +38,13 @@ public class ThirdPersonCamera {
private float distance = BASE_DISTANCE;
private boolean paused = false;
// Intro-Kameradrehung (neues Spiel): yaw animiert von vorne nach hinten
private boolean introRotating = false;
private float introStartYaw;
private float introEndYaw;
private float introDuration;
private float introTimer;
public ThirdPersonCamera(Camera cam, InputManager inputManager, KeyBindings keyBindings) {
this.cam = cam;
@@ -65,7 +72,7 @@ public class ThirdPersonCamera {
inputManager.addMapping("CamTurnRight", new KeyTrigger(keyBindings.turnRight));
AnalogListener analogListener = (name, value, tpf) -> {
if (paused) return;
if (paused || introRotating) return;
switch (name) {
// Horizontale Rotation — Maus
case "MouseX" -> yaw -= value * MOUSE_SENSITIVITY;
@@ -87,6 +94,13 @@ public class ThirdPersonCamera {
}
public void update(float tpf) {
if (introRotating) {
introTimer += tpf;
float t = FastMath.clamp(introTimer / introDuration, 0f, 1f);
yaw = introStartYaw + (introEndYaw - introStartYaw) * t;
if (t >= 1f) introRotating = false;
}
if (target == null || paused) return;
Vector3f pivot = target.getWorldTranslation().add(0, TARGET_HEIGHT, 0);
@@ -101,6 +115,23 @@ public class ThirdPersonCamera {
cam.lookAt(pivot, Vector3f.UNIT_Y);
}
/** Aktueller Yaw-Winkel (für CharacterControl nutzbar). */
/** Aktueller Yaw-Winkel (für CharacterControl nutzbar). */
public float getYaw() { return yaw; }
/** Setzt initialen Kamera-Yaw passend zum Spawn-Yaw (Kamera hinter dem Charakter). */
public void setInitialYaw(float spawnYawDegrees) {
this.yaw = -spawnYawDegrees * FastMath.DEG_TO_RAD;
}
/**
* Startet die Intro-Drehung: Kamera dreht sich im Uhrzeigersinn 180° (von vorne nach hinten)
* über die angegebene Dauer. Während der Drehung ist Mauseingabe blockiert.
*/
public void startIntroRotation(float duration) {
introStartYaw = this.yaw;
introEndYaw = this.yaw - FastMath.PI; // 180° CW von oben gesehen
introDuration = duration;
introTimer = 0f;
introRotating = true;
}
}

View File

@@ -557,7 +557,11 @@ public class WorldScene extends BaseAppState {
characterVisual.setCullHint(Spatial.CullHint.Inherit);
}
playerInput.setInitialFacing(spawnYaw);
playerInput.setInitialFacing(spawnYaw + 180f);
boolean newGame = "true".equals(System.getProperty("blight.new.game"));
// Neues Spiel: Kamera startet gegenüber der Blickrichtung (von vorne) und dreht sich 180° CW
thirdPersonCam.setInitialYaw(newGame ? spawnYaw + 180f : spawnYaw);
String reviveClip = de.blight.game.animation.AnimationLibrary.getClipForAction(
AnimationLibrary.findAssetRoot(), setName, de.blight.game.animation.AnimationAction.REVIVE);
@@ -568,9 +572,9 @@ public class WorldScene extends BaseAppState {
drownState.setReviveInfo(reviveClip, reviveLength);
}
if ("true".equals(System.getProperty("blight.new.game"))) {
if (newGame) {
app.getStateManager().attach(
new de.blight.game.state.NewGameIntroState(playerInput, reviveClip, reviveLength));
new de.blight.game.state.NewGameIntroState(playerInput, thirdPersonCam, reviveClip, reviveLength));
}
}

View File

@@ -95,8 +95,8 @@ public class CompassHudState extends BaseAppState {
if (compassNode == null) { return; }
Vector3f dir = cam.getDirection();
// yaw=0 = Blick nach +Z (Nord); positiv = Osten
float yaw = FastMath.atan2(dir.x, dir.z);
// yaw=0 = Blick nach -Z (Nord); JME3-Kamera blickt in -Z bei Norden
float yaw = FastMath.atan2(dir.x, -dir.z);
// Rose dreht sich so, dass Nord immer in der echten Nord-Richtung liegt
roseRot.fromAngleAxis(-yaw, Vector3f.UNIT_Z);

View File

@@ -10,6 +10,7 @@ import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import de.blight.game.control.PlayerInputControl;
import de.blight.game.control.ThirdPersonCamera;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +33,7 @@ public class NewGameIntroState extends BaseAppState {
private enum Phase { BLACK, FADING_IN, REVIVE_PLAYING, DONE }
private final PlayerInputControl playerInput;
private final ThirdPersonCamera thirdPersonCam;
private final String reviveClip;
private final float reviveLength;
@@ -42,10 +44,12 @@ public class NewGameIntroState extends BaseAppState {
private Phase phase;
private float timer;
public NewGameIntroState(PlayerInputControl playerInput, String reviveClip, float reviveLength) {
this.playerInput = playerInput;
this.reviveClip = reviveClip;
this.reviveLength = reviveLength;
public NewGameIntroState(PlayerInputControl playerInput, ThirdPersonCamera thirdPersonCam,
String reviveClip, float reviveLength) {
this.playerInput = playerInput;
this.thirdPersonCam = thirdPersonCam;
this.reviveClip = reviveClip;
this.reviveLength = reviveLength;
}
@Override
@@ -85,11 +89,15 @@ public class NewGameIntroState extends BaseAppState {
case BLACK -> {
timer -= tpf;
if (timer <= 0f) {
// REVIVE unmittelbar vor dem Einblenden einfrieren
playerInput.startFrozenRevive(reviveClip);
// Drehung startet sofort mit Fade-In: Gesamtdauer = Einblenden + REVIVE
if (thirdPersonCam != null) {
thirdPersonCam.startIntroRotation(FADE_DURATION + reviveLength);
}
phase = Phase.FADING_IN;
timer = FADE_DURATION;
log.info("[NewGameIntro] BLACK fertig REVIVE eingefroren, starte FADING_IN ({} s)", FADE_DURATION);
log.info("[NewGameIntro] BLACK fertig REVIVE eingefroren, Kamera dreht {} s, starte FADING_IN",
FADE_DURATION + reviveLength);
}
}
case FADING_IN -> {