add setting for light amplification strengh, incl. power drain

This commit is contained in:
yuni 2024-09-22 03:10:11 +02:00
parent aaa5266478
commit 93293092ce
6 changed files with 43 additions and 10 deletions

View file

@ -35,7 +35,7 @@ The `SPACE` key helps you move more intuitively by slowing you down. Hold it fo
When you're ready, take a look around, explore the starting area. There is a friendly person floating nearby in a red space suit that would love to talk to you. When you're ready, take a look around, explore the starting area. There is a friendly person floating nearby in a red space suit that would love to talk to you.
The game is dark. After all, space is dark. The planets and moons orbit in real time, the map changes depending on when you play, and if you're unlucky, you start in the shadow of Jupiter and everything's even darker! Try the flashlight (`f` key), turning off shadows in the menu, and make sure that Augmented Reality is on (`TAB` key) which gives you a little extra light amplification. The game is dark. After all, space is dark. The planets and moons orbit in real time, the map changes depending on when you play, and if you're unlucky, you start in the shadow of Jupiter and everything's even darker! Try the flashlight (`f` key), or stronger light amplification (menu), which requires Augmented Reality to be active (`TAB` key).
Press `Esc` for the menu to restart the game if you get lost, explore more key bindings, game features, and the **achievements** to get some guidance on what you can do in the game. Press `Esc` for the menu to restart the game if you get lost, explore more key bindings, game features, and the **achievements** to get some guidance on what you can do in the game.

View file

@ -263,14 +263,16 @@ impl Default for Battery {
pub fn update_power( pub fn update_power(
time: Res<Time>, time: Res<Time>,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut q_battery: Query<(&mut Battery, Option<&Player>)>, prefs: Res<Preferences>,
mut q_battery: Query<&mut Battery, With<Player>>,
mut q_flashlight: Query<&mut Visibility, With<PlayersFlashLight>>, mut q_flashlight: Query<&mut Visibility, With<PlayersFlashLight>>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_game: EventWriter<game::GameEvent>,
) { ) {
let d = time.delta_seconds(); let d = time.delta_seconds();
for (mut battery, player) in &mut q_battery { for mut battery in &mut q_battery {
if player.is_some() && settings.flashlight_active { if settings.flashlight_active {
battery.power -= 2400000.0 * d; battery.power -= 2400e3 * d; // 2.4MW
if battery.power <= 0.0 { if battery.power <= 0.0 {
settings.flashlight_active = false; settings.flashlight_active = false;
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
@ -279,6 +281,18 @@ pub fn update_power(
} }
} }
} }
if settings.hud_active {
let mut hud_drain = 300e3; // 300kW
hud_drain += prefs.light_amp as f32 * 200e3; // 200kW per level
battery.power -= hud_drain * d;
if battery.power <= 0.0 {
ew_game.send(GameEvent::SetAR(Turn::Off));
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
for mut flashlight_vis in &mut q_flashlight {
*flashlight_vis = Visibility::Hidden;
}
}
}
battery.power = (battery.power + battery.reactor * d).clamp(0.0, battery.capacity); battery.power = (battery.power + battery.reactor * d).clamp(0.0, battery.capacity);
} }
} }

View file

@ -28,8 +28,7 @@ pub const LOG_MAX: usize = LOG_MAX_ROWS;
pub const MAX_CHOICES: usize = 10; pub const MAX_CHOICES: usize = 10;
pub const SPEEDOMETER_WIDTH: f32 = 20.0; pub const SPEEDOMETER_WIDTH: f32 = 20.0;
pub const SPEEDOMETER_HEIGHT: f32 = 10.0; pub const SPEEDOMETER_HEIGHT: f32 = 10.0;
pub const AMBIENT_LIGHT: f32 = 0.0; // Space is DARK pub const AMBIENT_LIGHT: [f32; 4] = [0.0, 20.0, 60.0, 150.0];
pub const AMBIENT_LIGHT_AR: f32 = 20.0;
//pub const REPLY_NUMBERS: [char; 10] = ['❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾', '⓿']; //pub const REPLY_NUMBERS: [char; 10] = ['❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾', '⓿'];
//pub const REPLY_NUMBERS: [char; 10] = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩']; //pub const REPLY_NUMBERS: [char; 10] = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'];
pub const REPLY_NUMBERS: [char; 10] = ['➀', '➁', '➂', '➃', '➄', '➅', '➆', '➇', '➈', '➉']; pub const REPLY_NUMBERS: [char; 10] = ['➀', '➁', '➂', '➃', '➄', '➅', '➆', '➇', '➈', '➉'];
@ -1253,6 +1252,7 @@ fn update_overlay_visibility(
mut ambient_light: ResMut<AmbientLight>, mut ambient_light: ResMut<AmbientLight>,
er_target: EventReader<UpdateOverlayVisibility>, er_target: EventReader<UpdateOverlayVisibility>,
settings: Res<Settings>, settings: Res<Settings>,
prefs: Res<Preferences>,
) { ) {
if er_target.is_empty() { if er_target.is_empty() {
return; return;
@ -1280,9 +1280,9 @@ fn update_overlay_visibility(
} }
ambient_light.brightness = if settings.hud_active { ambient_light.brightness = if settings.hud_active {
AMBIENT_LIGHT_AR AMBIENT_LIGHT[prefs.light_amp]
} else { } else {
AMBIENT_LIGHT AMBIENT_LIGHT[0]
}; };
} }

View file

@ -30,7 +30,7 @@ pub mod world;
pub mod prelude { pub mod prelude {
pub use crate::common::*; pub use crate::common::*;
pub use crate::load::load_asset; pub use crate::load::load_asset;
pub use crate::var::Settings; pub use crate::var::{Preferences, Settings};
pub use crate::{ pub use crate::{
actor, audio, camera, chat, cmd, common, game, hud, load, menu, nature, var, visual, world, actor, audio, camera, chat, cmd, common, game, hud, load, menu, nature, var, visual, world,
}; };

View file

@ -66,6 +66,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[
("", MenuAction::ToggleMap), ("", MenuAction::ToggleMap),
("", MenuAction::ToggleAR), ("", MenuAction::ToggleAR),
("", MenuAction::ChangeARAvatar), ("", MenuAction::ChangeARAvatar),
("", MenuAction::ModLightAmp),
("", MenuAction::ToggleSound), ("", MenuAction::ToggleSound),
("", MenuAction::ToggleMusic), ("", MenuAction::ToggleMusic),
("", MenuAction::ToggleCamera), ("", MenuAction::ToggleCamera),
@ -80,6 +81,7 @@ pub enum MenuAction {
ToggleMap, ToggleMap,
ToggleAR, ToggleAR,
ChangeARAvatar, ChangeARAvatar,
ModLightAmp,
ToggleSound, ToggleSound,
ToggleMusic, ToggleMusic,
ToggleCamera, ToggleCamera,
@ -428,6 +430,7 @@ pub fn update_menu(
achievement_tracker: Res<var::AchievementTracker>, achievement_tracker: Res<var::AchievementTracker>,
menustate: Res<MenuState>, menustate: Res<MenuState>,
settings: Res<Settings>, settings: Res<Settings>,
prefs: Res<Preferences>,
) { ) {
for mut vis in &mut q_vis { for mut vis in &mut q_vis {
*vis = bool2vis(settings.menu_active); *vis = bool2vis(settings.menu_active);
@ -481,6 +484,10 @@ pub fn update_menu(
let onoff = bool2string(settings.hud_active); let onoff = bool2string(settings.hud_active);
text.sections[i].value = format!("Augmented Reality: {onoff} [TAB]\n"); text.sections[i].value = format!("Augmented Reality: {onoff} [TAB]\n");
} }
MenuAction::ModLightAmp => {
let n = prefs.light_amp;
text.sections[i].value = format!("Light Amplification: {n}/3\n");
}
MenuAction::ChangeARAvatar => { MenuAction::ChangeARAvatar => {
if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) { if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
let avatar_title = ava.3; let avatar_title = ava.3;
@ -516,6 +523,7 @@ pub fn update_menu(
pub fn handle_input( pub fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut prefs: ResMut<Preferences>,
mut menustate: ResMut<MenuState>, mut menustate: ResMut<MenuState>,
mut app_exit_events: ResMut<Events<AppExit>>, mut app_exit_events: ResMut<Events<AppExit>>,
mut ew_game: EventWriter<game::GameEvent>, mut ew_game: EventWriter<game::GameEvent>,
@ -523,6 +531,7 @@ pub fn handle_input(
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_updatemenu: EventWriter<UpdateMenuEvent>, mut ew_updatemenu: EventWriter<UpdateMenuEvent>,
mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>, mut ew_updateavatar: EventWriter<hud::UpdateAvatarEvent>,
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
) { ) {
let last_menu_entry = MENUDEF.len() - 1; let last_menu_entry = MENUDEF.len() - 1;
@ -577,6 +586,14 @@ pub fn handle_input(
ew_updateavatar.send(hud::UpdateAvatarEvent); ew_updateavatar.send(hud::UpdateAvatarEvent);
ew_updatemenu.send(UpdateMenuEvent); ew_updatemenu.send(UpdateMenuEvent);
} }
MenuAction::ModLightAmp => {
prefs.light_amp += 1;
if prefs.light_amp > 3 {
prefs.light_amp = 0;
}
ew_updateoverlays.send(hud::UpdateOverlayVisibility);
ew_updatemenu.send(UpdateMenuEvent);
}
MenuAction::ToggleMusic => { MenuAction::ToggleMusic => {
ew_game.send(GameEvent::SetMusic(Next)); ew_game.send(GameEvent::SetMusic(Next));
ew_updatemenu.send(UpdateMenuEvent); ew_updatemenu.send(UpdateMenuEvent);

View file

@ -439,6 +439,7 @@ impl AchievementTracker {
} }
} }
// Used for settings that are preserved across restarts
#[derive(Resource, Serialize, Deserialize, Debug, Default)] #[derive(Resource, Serialize, Deserialize, Debug, Default)]
#[serde(default)] #[serde(default)]
pub struct Preferences { pub struct Preferences {
@ -451,6 +452,7 @@ pub struct Preferences {
pub third_person: bool, pub third_person: bool,
pub shadows_sun: bool, pub shadows_sun: bool,
pub avatar: usize, pub avatar: usize,
pub light_amp: usize, // 0-3
#[serde(skip)] #[serde(skip)]
pub source_file: Option<String>, pub source_file: Option<String>,