flashlight working
This commit is contained in:
@@ -65,6 +65,7 @@ pub fn plugin(app: &mut App) {
|
||||
apply_head_bob,
|
||||
on_resize_system,
|
||||
handle_flashlight,
|
||||
// handle_flashlight_movement,
|
||||
).run_if(in_state(GameState::Playing)),
|
||||
)
|
||||
.add_systems(
|
||||
@@ -134,13 +135,17 @@ pub fn init_player(
|
||||
// feitelijke pitslamp
|
||||
parent.spawn((
|
||||
Flashlight,
|
||||
PointLight {
|
||||
intensity: 0.0, // start with the light off
|
||||
SpotLight {
|
||||
intensity: 0.0,
|
||||
color: Color::WHITE,
|
||||
shadows_enabled: true,
|
||||
range: 4.0,
|
||||
outer_angle: 30.0_f32.to_radians(), // wide cone for flashlight
|
||||
inner_angle: 10.0_f32.to_radians(), // narrower inner cone
|
||||
shadows_enabled: false, // (set to true for realism)
|
||||
radius: 0.35, // low value for hard light
|
||||
..default()
|
||||
},
|
||||
Transform::from_xyz(1.0, 2.0, 0.0),
|
||||
Transform::from_xyz(0.0, -0.15, 0.5),
|
||||
GlobalTransform::default(),
|
||||
));
|
||||
});
|
||||
@@ -217,6 +222,8 @@ pub fn handle_input(
|
||||
mut query: Query<(&Transform, &mut PlayerInput, &mut PlayerAction, &mut Player), With<Player>>,
|
||||
) {
|
||||
for (transform, mut input, mut action, mut player) in query.iter_mut() {
|
||||
*action = PlayerAction::Move;
|
||||
|
||||
let forward = transform.forward();
|
||||
let right = transform.right();
|
||||
let mut movement_direction = Vec3::ZERO;
|
||||
@@ -346,22 +353,21 @@ pub fn apply_head_bob(
|
||||
}
|
||||
|
||||
pub fn handle_flashlight(
|
||||
mut player_query: Query<(&mut PlayerAction, Entity), With<Player>>,
|
||||
mut flashlight_query: Query<&mut PointLight, With<Flashlight>>,
|
||||
player_query: Query<&PlayerAction, With<Player>>,
|
||||
mut flashlight_query: Query<&mut SpotLight, With<Flashlight>>,
|
||||
) {
|
||||
let Ok((mut action, player_entity)) = player_query.get_single_mut() else {
|
||||
let Ok(action) = player_query.get_single() 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 {
|
||||
if let Ok(mut spotlight) = flashlight_query.get_single_mut() {
|
||||
spotlight.intensity = if spotlight.intensity > 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
100_000.0
|
||||
300_000.0
|
||||
};
|
||||
println!("Flashlight {}", if point_light.intensity > 0.0 { "on" } else { "off" });
|
||||
println!("Flashlight {}", if spotlight.intensity > 0.0 { "on" } else { "off" });
|
||||
}
|
||||
*action = PlayerAction::Move;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user