add key to toggle flashlight, fix flashlight in 1st person mode

This commit is contained in:
yuni 2024-05-07 17:11:18 +02:00
parent f88d063beb
commit e08339ad5e
5 changed files with 19 additions and 0 deletions

View file

@ -34,6 +34,7 @@ Source code: https://codeberg.org/hut/outfly
- AWSD/Shift/Ctrl: Accelerate
- R: Rotate (hold & move mouse)
- E: Interact: Talk to people, enter vehicles
- H: Flashlight
- Q: Exit vehicle
- JKULIO: Mouseless camera rotation
- Augmented Reality: (toggle with Tab)

View file

@ -135,6 +135,7 @@ impl Default for ExperiencesGForce { fn default() -> Self { Self {
#[derive(Component)] pub struct JustNowEnteredVehicle;
#[derive(Component)] pub struct ActorEnteringVehicle;
#[derive(Component)] pub struct ActorVehicleBeingEntered;
#[derive(Component)] pub struct PlayersFlashLight;
#[derive(Component)] pub struct WantsMaxRotation(pub f64);
#[derive(Component)] pub struct WantsMaxVelocity(pub f64);
#[derive(Component)] pub struct Identifier(pub String);
@ -263,10 +264,12 @@ pub fn handle_input(
q_talker: Query<(&chat::Talker, &Transform), (Without<actor::Player>, Without<Camera>)>,
player: Query<Entity, With<actor::Player>>,
q_camera: Query<&Transform, With<Camera>>,
mut q_flashlight: Query<&mut Visibility, With<PlayersFlashLight>>,
q_vehicles: Query<(Entity, &Transform), (With<actor::Vehicle>, Without<actor::Player>, Without<Camera>)>,
mut ew_conv: EventWriter<chat::StartConversationEvent>,
mut ew_vehicle: EventWriter<VehicleEnterExitEvent>,
mut ew_playerdies: EventWriter<PlayerDiesEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_player_drives: Query<Entity, With<PlayerDrivesThis>>,
) {
if q_camera.is_empty() || player.is_empty() {
@ -320,6 +323,16 @@ pub fn handle_input(
break;
}
}
else if keyboard_input.just_pressed(settings.key_flashlight) {
for mut flashlight_vis in &mut q_flashlight {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
if *flashlight_vis == Visibility::Hidden {
*flashlight_vis = Visibility::Visible;
} else {
*flashlight_vis = Visibility::Hidden;
}
}
}
else if keyboard_input.just_pressed(settings.key_restart) {
settings.god_mode = false;
ew_playerdies.send(PlayerDiesEvent(DamageType::Mental));

View file

@ -748,6 +748,7 @@ fn spawn_entities(
actor.with_children(|builder| {
builder.spawn((
world::DespawnOnPlayerDeath,
actor::PlayersFlashLight,
SpotLightBundle {
transform: Transform {
translation: Vec3::new(0.0, 0.0, 1.0),
@ -763,6 +764,7 @@ fn spawn_entities(
range: 2000.0,
..default()
},
visibility: Visibility::Hidden,
..default()
}
));

View file

@ -3,6 +3,7 @@ AWSD/Shift/Ctrl: Movement
R: Rotate (hold + move mouse)
E: Interact: Talk to people, enter vehicles
Q: Exit vehicle
H: Flashlight
M: Map
Tab: Toggle HUD + Augmented Reality
Left click: Target objects [AUGMENTED REALITY ONLY]

View file

@ -91,6 +91,7 @@ pub struct Settings {
pub key_interact: KeyCode,
pub key_vehicle: KeyCode,
pub key_camera: KeyCode,
pub key_flashlight: KeyCode,
pub key_shadows: KeyCode,
pub key_rotate: KeyCode,
pub key_rotation_stabilizer: KeyCode,
@ -196,6 +197,7 @@ impl Default for Settings {
key_interact: KeyCode::KeyE,
key_vehicle: KeyCode::KeyQ,
key_camera: KeyCode::KeyF,
key_flashlight: KeyCode::KeyH,
key_shadows: KeyCode::F2,
key_rotate: KeyCode::KeyR,
key_rotation_stabilizer: KeyCode::KeyY,