part refactor settings logic
This commit is contained in:
@@ -61,9 +61,8 @@ public class GameScreen implements Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCamera() {
|
private void initCamera() {
|
||||||
camera = new PerspectiveCamera(55f, RETRO_WIDTH, RETRO_HEIGHT);
|
|
||||||
settings = new GameSettings();
|
settings = new GameSettings();
|
||||||
settings.fov = camera.fieldOfView;
|
camera = new PerspectiveCamera(settings.fov, RETRO_WIDTH, RETRO_HEIGHT);
|
||||||
cameraController = new FpsCameraController(camera, settings);
|
cameraController = new FpsCameraController(camera, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,9 +110,10 @@ public class FpsCameraController {
|
|||||||
|
|
||||||
/** Update each frame with delta time */
|
/** Update each frame with delta time */
|
||||||
public void update(float delta, World3D world) {
|
public void update(float delta, World3D world) {
|
||||||
|
if (settings.bobbingEnabled) {
|
||||||
camera.position.y -= bobOffsetY;
|
camera.position.y -= bobOffsetY;
|
||||||
bobOffsetY = 0f;
|
bobOffsetY = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mouseCaptured) {
|
if (!mouseCaptured) {
|
||||||
return;
|
return;
|
||||||
@@ -322,6 +323,7 @@ public class FpsCameraController {
|
|||||||
// 4) VIEW BOBBING (purely visual)
|
// 4) VIEW BOBBING (purely visual)
|
||||||
// =========================================================
|
// =========================================================
|
||||||
// horizontal movement magnitude (world units per frame)
|
// horizontal movement magnitude (world units per frame)
|
||||||
|
if (settings.bobbingEnabled) {
|
||||||
float horizLen = (float)Math.sqrt(moveX * moveX + moveZ * moveZ);
|
float horizLen = (float)Math.sqrt(moveX * moveX + moveZ * moveZ);
|
||||||
|
|
||||||
if (grounded && horizLen > 0.0001f) {
|
if (grounded && horizLen > 0.0001f) {
|
||||||
@@ -339,6 +341,7 @@ public class FpsCameraController {
|
|||||||
|
|
||||||
camera.position.y += bobOffsetY;
|
camera.position.y += bobOffsetY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void updateCameraDirection() {
|
private void updateCameraDirection() {
|
||||||
// build direction vector from yaw/pitch
|
// build direction vector from yaw/pitch
|
||||||
float useYaw = yaw;
|
float useYaw = yaw;
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ package wtf.beatrice.retrorender.engine;
|
|||||||
|
|
||||||
public class GameSettings {
|
public class GameSettings {
|
||||||
|
|
||||||
public float fov = 55f; // degrees
|
public float fov = 60f; // degrees
|
||||||
public float mouseSensitivity = 0.15f;
|
public float mouseSensitivity = 0.15f;
|
||||||
public float moveSpeed = 5f;
|
public float moveSpeed = 5f;
|
||||||
|
|
||||||
public float minFov = 40f;
|
public final float minFov = 40f;
|
||||||
public float maxFov = 100f;
|
public final float maxFov = 100f;
|
||||||
|
public final float fovStep = 2f;
|
||||||
|
|
||||||
|
public boolean bobbingEnabled = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ public class GameUi {
|
|||||||
public GameUi(GameSettings settings) {
|
public GameUi(GameSettings settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.pauseMenu = new PauseMenu();
|
this.pauseMenu = new PauseMenu();
|
||||||
this.settingsMenu = new SettingsMenu();
|
this.settingsMenu = new SettingsMenu(settings);
|
||||||
|
|
||||||
// sync initial settings
|
|
||||||
this.settingsMenu.setFov(settings.fov);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UiMode onEsc(UiMode current) {
|
public UiMode onEsc(UiMode current) {
|
||||||
@@ -54,6 +51,7 @@ public class GameUi {
|
|||||||
boolean close = settingsMenu.handleClick(retroX, retroY);
|
boolean close = settingsMenu.handleClick(retroX, retroY);
|
||||||
// always sync FOV to settings
|
// always sync FOV to settings
|
||||||
settings.fov = settingsMenu.getFov();
|
settings.fov = settingsMenu.getFov();
|
||||||
|
settings.bobbingEnabled = settingsMenu.isBobbingEnabled();
|
||||||
|
|
||||||
if (close) {
|
if (close) {
|
||||||
// Settings “Close” button clicked -> go back to PAUSE
|
// Settings “Close” button clicked -> go back to PAUSE
|
||||||
|
|||||||
@@ -17,18 +17,18 @@ public class SettingsMenu {
|
|||||||
private final BitmapFont boldFont;
|
private final BitmapFont boldFont;
|
||||||
private final Texture pixel;
|
private final Texture pixel;
|
||||||
|
|
||||||
// FOV value stored here, GameScreen syncs it to the camera
|
private final GameSettings settings;
|
||||||
private float fov;
|
|
||||||
private final float minFov = 40f;
|
private boolean bobbingEnabled = true;
|
||||||
private final float maxFov = 100f;
|
|
||||||
private final float fovStep = 2f;
|
|
||||||
|
|
||||||
// button / hit areas
|
// button / hit areas
|
||||||
private float fovDecX, fovDecY, fovDecW, fovDecH;
|
private float fovDecX, fovDecY, fovDecW, fovDecH;
|
||||||
private float fovIncX, fovIncY, fovIncW, fovIncH;
|
private float fovIncX, fovIncY, fovIncW, fovIncH;
|
||||||
private float closeX, closeY, closeW, closeH;
|
private float closeX, closeY, closeW, closeH;
|
||||||
|
|
||||||
public SettingsMenu() {
|
public SettingsMenu(GameSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
|
|
||||||
FreeTypeFontGenerator generator =
|
FreeTypeFontGenerator generator =
|
||||||
@@ -60,19 +60,27 @@ public class SettingsMenu {
|
|||||||
pm.fill();
|
pm.fill();
|
||||||
pixel = new Texture(pm);
|
pixel = new Texture(pm);
|
||||||
pm.dispose();
|
pm.dispose();
|
||||||
|
|
||||||
// default FOV
|
|
||||||
fov = 55f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFov(float fov) {
|
public void setFov(float fov) {
|
||||||
this.fov = MathUtils.clamp(fov, minFov, maxFov);
|
settings.fov = MathUtils.clamp(fov, settings.minFov, settings.maxFov);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFov() {
|
public float getFov() {
|
||||||
return fov;
|
return settings.fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBobbingEnabled()
|
||||||
|
{
|
||||||
|
return bobbingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBobbingEnabled(boolean enabled){
|
||||||
|
bobbingEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param width RETRO_WIDTH
|
* @param width RETRO_WIDTH
|
||||||
* @param height RETRO_HEIGHT
|
* @param height RETRO_HEIGHT
|
||||||
@@ -136,7 +144,7 @@ public class SettingsMenu {
|
|||||||
drawButtonWithLabel(">", fovIncX, fovIncY, fovIncW, fovIncH);
|
drawButtonWithLabel(">", fovIncX, fovIncY, fovIncW, fovIncH);
|
||||||
|
|
||||||
// numeric value centered between dec/inc
|
// numeric value centered between dec/inc
|
||||||
String fovText = String.format("%3.0f°", fov);
|
String fovText = String.format("%3.0f°", settings.fov);
|
||||||
layout.setText(font, fovText);
|
layout.setText(font, fovText);
|
||||||
|
|
||||||
float valueCenter = (fovDecX + fovDecW + fovIncX) / 2f;
|
float valueCenter = (fovDecX + fovDecW + fovIncX) / 2f;
|
||||||
@@ -196,14 +204,14 @@ public class SettingsMenu {
|
|||||||
// FOV -
|
// FOV -
|
||||||
if (x >= fovDecX && x <= fovDecX + fovDecW &&
|
if (x >= fovDecX && x <= fovDecX + fovDecW &&
|
||||||
y >= fovDecY && y <= fovDecY + fovDecH) {
|
y >= fovDecY && y <= fovDecY + fovDecH) {
|
||||||
fov = MathUtils.clamp(fov - fovStep, minFov, maxFov);
|
settings.fov = MathUtils.clamp(settings.fov - settings.fovStep, settings.minFov, settings.maxFov);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FOV +
|
// FOV +
|
||||||
if (x >= fovIncX && x <= fovIncX + fovIncW &&
|
if (x >= fovIncX && x <= fovIncX + fovIncW &&
|
||||||
y >= fovIncY && y <= fovIncY + fovIncH) {
|
y >= fovIncY && y <= fovIncY + fovIncH) {
|
||||||
fov = MathUtils.clamp(fov + fovStep, minFov, maxFov);
|
settings.fov = MathUtils.clamp(settings.fov + settings.fovStep, settings.minFov, settings.maxFov);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user