added init & taktical view by ownColor

This commit is contained in:
Cedric Beck
2024-12-01 22:46:17 +01:00
parent 661c28f096
commit 7762b97303
4 changed files with 38 additions and 9 deletions

View File

@@ -277,6 +277,10 @@ public float getRotation() {
return (rotationAngle / 2) % 360; return (rotationAngle / 2) % 360;
} }
public void setRotation(float rotationAngle){
this.rotationAngle = rotationAngle;
}
/** /**
* Gets the current scroll value. * Gets the current scroll value.
* *

View File

@@ -75,8 +75,8 @@ public static void main(String[] args) {
AppSettings settings = new AppSettings(true); AppSettings settings = new AppSettings(true);
settings.setSamples(128); settings.setSamples(128);
settings.setCenterWindow(true); settings.setCenterWindow(true);
settings.setWidth(1080); settings.setWidth((int) (1920*0.9f));
settings.setHeight(720); settings.setHeight((int) (1080*0.9f));
settings.setVSync(false); settings.setVSync(false);
MdgaApp app = new MdgaApp(); MdgaApp app = new MdgaApp();
@@ -107,7 +107,7 @@ public void simpleInitApp() {
gameView = new GameView(this); gameView = new GameView(this);
ceremonyView = new CeremonyView(this); ceremonyView = new CeremonyView(this);
enter(MdgaState.MAIN); enter(MdgaState.GAME);
} }
/** /**

View File

@@ -13,6 +13,7 @@
import com.jme3.util.SkyFactory; import com.jme3.util.SkyFactory;
import com.jme3.util.SkyFactory.EnvMapType; import com.jme3.util.SkyFactory.EnvMapType;
import pp.mdga.client.MdgaApp; import pp.mdga.client.MdgaApp;
import pp.mdga.game.Color;
public class CameraHandler { public class CameraHandler {
MdgaApp app; MdgaApp app;
@@ -29,11 +30,15 @@ public class CameraHandler {
DirectionalLightShadowFilter dlsf; DirectionalLightShadowFilter dlsf;
Spatial sky; Spatial sky;
private Color ownColor;
private boolean init;
private boolean initRot;
public CameraHandler(MdgaApp app, FilterPostProcessor fpp) { public CameraHandler(MdgaApp app, FilterPostProcessor fpp) {
init = false;
initRot = false;
this.app = app; this.app = app;
this.fpp = fpp; this.fpp = fpp;
// Save the default camera state // Save the default camera state
this.defaultCameraPosition = app.getCamera().getLocation().clone(); this.defaultCameraPosition = app.getCamera().getLocation().clone();
this.defaultCameraRotation = app.getCamera().getRotation().clone(); this.defaultCameraRotation = app.getCamera().getRotation().clone();
@@ -56,11 +61,15 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp) {
} }
public void init() { public void init(Color ownColor) {
app.getRootNode().addLight(sun); app.getRootNode().addLight(sun);
app.getRootNode().addLight(ambient); app.getRootNode().addLight(ambient);
app.getRootNode().attachChild(sky); app.getRootNode().attachChild(sky);
fpp.addFilter(dlsf); fpp.addFilter(dlsf);
init = true;
initRot = true;
this.ownColor = ownColor;
app.getInputSynchronize().setRotation(getInitAngleByColor(ownColor)*2);
} }
public void shutdown() { public void shutdown() {
@@ -76,6 +85,7 @@ public void shutdown() {
} }
public void update(float scroll, float rotation) { public void update(float scroll, float rotation) {
if(!init) return;
float scrollValue = Math.max(0, Math.min(scroll, 100)); float scrollValue = Math.max(0, Math.min(scroll, 100));
float rotationValue = rotation % 360; float rotationValue = rotation % 360;
@@ -83,6 +93,7 @@ public void update(float scroll, float rotation) {
rotationValue += 360; rotationValue += 360;
} }
float radius; float radius;
float verticalAngle; float verticalAngle;
@@ -91,10 +102,10 @@ public void update(float scroll, float rotation) {
radius = 30f; radius = 30f;
} else { } else {
verticalAngle = 90f; verticalAngle = 90f;
rotationValue = 270f; rotationValue = getAngleByColor(ownColor);
radius = 50f; radius = 50f;
} }
System.out.println(rotationValue);
float verticalAngleRadians = FastMath.DEG_TO_RAD * verticalAngle; float verticalAngleRadians = FastMath.DEG_TO_RAD * verticalAngle;
float z = radius * FastMath.sin(verticalAngleRadians); float z = radius * FastMath.sin(verticalAngleRadians);
@@ -107,4 +118,18 @@ public void update(float scroll, float rotation) {
app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Z); app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Z);
} }
private float getAngleByColor(Color color){
return switch (color){
case ARMY -> 0;
case AIRFORCE -> 90;
case NAVY -> 270;
case CYBER -> 180;
default -> throw new RuntimeException("None is not allowed");
};
}
private float getInitAngleByColor(Color color){
return (getAngleByColor(color) + 180) % 360;
}
} }

View File

@@ -58,9 +58,9 @@ public GameView(MdgaApp app) {
@Override @Override
public void onEnter() { public void onEnter() {
camera.init();
boardHandler.init();
setOwnColor(Color.AIRFORCE); setOwnColor(Color.AIRFORCE);
camera.init(ownColor);
boardHandler.init();
guiHandler.init(ownColor); guiHandler.init(ownColor);
app.getViewPort().addProcessor(fpp); app.getViewPort().addProcessor(fpp);