diff --git a/src/main.rs b/src/main.rs index cf1bac4..48bedad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn main() { RapierPhysicsPlugin::::default(), RapierDebugRenderPlugin::default(), player::plugin, - debugging::plugin + // debugging::plugin )) .init_state::() .add_systems(OnEnter(GameState::Playing), setup) @@ -62,11 +62,11 @@ fn setup( Collider::cuboid(0.5, 0.5, 0.5), )); // light - commands.spawn(( - PointLight { - shadows_enabled: true, - ..default() - }, - Transform::from_xyz(4.0, 8.0, 4.0), - )); + // commands.spawn(( + // PointLight { + // shadows_enabled: true, + // ..default() + // }, + // Transform::from_xyz(4.0, 8.0, 4.0), + // )); } diff --git a/src/player.rs b/src/player.rs index be909ac..369fcb7 100644 --- a/src/player.rs +++ b/src/player.rs @@ -51,12 +51,21 @@ impl Default for HeadBob { #[derive(Component, Debug)] pub struct BaseTransform(pub Transform); +#[derive(Debug, Component)] +pub struct Flashlight; + pub fn plugin(app: &mut App) { app.add_plugins(toolbar::plugin) .add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor)) .add_systems( Update, - (move_camera, handle_input, apply_head_bob, on_resize_system).run_if(in_state(GameState::Playing)), + ( + move_camera, + handle_input, + apply_head_bob, + on_resize_system, + handle_flashlight, + ).run_if(in_state(GameState::Playing)), ) .add_systems( FixedUpdate, @@ -112,6 +121,7 @@ pub fn init_player( RenderLayers::layer(STATIC_LAYER), )); + // pitslamp sprite let window = window.single(); let transform = flashlight_base_transform(window.width(), window.height()); parent.spawn(( @@ -120,6 +130,19 @@ pub fn init_player( transform, RenderLayers::layer(STATIC_LAYER), )); + + // feitelijke pitslamp + parent.spawn(( + Flashlight, + PointLight { + intensity: 0.0, // start with the light off + color: Color::WHITE, + shadows_enabled: true, + ..default() + }, + Transform::from_xyz(1.0, 2.0, 0.0), + GlobalTransform::default(), + )); }); } @@ -221,10 +244,10 @@ pub fn handle_input( } else { player.speed_factor = 1.0; } - if keyboard_input.pressed(KeyCode::KeyE) { + if keyboard_input.just_pressed(KeyCode::KeyE) { *action = PlayerAction::Interact } - if keyboard_input.pressed(KeyCode::KeyA) { + if keyboard_input.just_pressed(KeyCode::KeyF) { *action = PlayerAction::ToggleFlashlight; } @@ -295,7 +318,7 @@ pub fn apply_head_bob( if is_moving { transform.translation.x = horizontal_offset; } else { - // decrease bobbing magnitued + // decrease bobbing magnitude transform.translation.x *= 0.8; } } @@ -320,4 +343,25 @@ pub fn apply_head_bob( } } } -} \ No newline at end of file +} + +pub fn handle_flashlight( + mut player_query: Query<(&mut PlayerAction, Entity), With>, + mut flashlight_query: Query<&mut PointLight, With>, +) { + let Ok((mut action, player_entity)) = player_query.get_single_mut() else { + return; + }; + if *action != PlayerAction::ToggleFlashlight { + return; + } + if let Ok(mut point_light) = flashlight_query.get_mut(player_entity) { + point_light.intensity = if point_light.intensity > 0.0 { + 0.0 + } else { + 100_000.0 + }; + println!("Flashlight {}", if point_light.intensity > 0.0 { "on" } else { "off" }); + } + *action = PlayerAction::Move; +}