open doors with key

This commit is contained in:
LorrensP-2158466
2025-04-06 22:14:51 +02:00
parent 511c936fe4
commit 910cb4c70e
3 changed files with 19 additions and 16 deletions

View File

@@ -101,14 +101,14 @@ pub fn handle_drop(
pub fn handle_door_interaction(
mut commands: Commands,
player_query: Query<(&PlayerAction, &Item), With<Player>>,
mut player_query: Query<(&PlayerAction, &mut Item), With<Player>>,
card_query: Query<&KeyCardId>,
// current interactable
interaction_opportunity: ResMut<InteractionOpportunity>,
door_query: Query<(Entity, &OpenedByKey), With<Interact>>,
) {
// the card
let Ok((PlayerAction::OpenDoor, item)) = player_query.get_single() else {
let Ok((PlayerAction::OpenDoor, mut item)) = player_query.get_single_mut() else {
return;
};
let Some(current_card) = item.inner().and_then(|e| card_query.get(e).ok()) else {
@@ -127,5 +127,6 @@ pub fn handle_door_interaction(
commands.entity(door).despawn_recursive();
// unwrap is safe because of the item.inner().and_then
commands.entity(item.inner().unwrap()).despawn_recursive();
item.take();
}
}

View File

@@ -660,7 +660,7 @@ fn spawn_doors(
(
(0, 1),
Transform::from_xyz(2.0 * x as f32, 0.0, -2.0 * z as f32)
.with_rotation(Quat::from_rotation_y(90.0_f32.to_radians())),
.with_rotation(Quat::from_rotation_y(-90.0_f32.to_radians())),
)
} else {
(

View File

@@ -66,8 +66,7 @@ pub struct Flashlight {
}
#[derive(Debug, Component)]
pub struct SpotlightFlashlight {
}
pub struct SpotlightFlashlight {}
#[derive(Component)]
pub struct FlashlightButtonAnimation {
@@ -95,7 +94,12 @@ pub fn plugin(app: &mut App) {
apply_head_bob,
on_resize_system,
handle_flashlight,
(update_flashlight_button_animation, update_flashlight_charge, update_flashlight_sprite).chain(),
(
update_flashlight_button_animation,
update_flashlight_charge,
update_flashlight_sprite,
)
.chain(),
)
.run_if(in_state(GameState::Playing)),
)
@@ -163,7 +167,10 @@ pub fn init_player(
let window = window.single();
let transform = flashlight_base_transform(window.width(), window.height());
parent.spawn((
Flashlight { charge: 4.0, is_on: false },
Flashlight {
charge: 4.0,
is_on: false,
},
Sprite::from_image(flashlights.flash_hold_4.clone()),
transform.0.clone(),
transform,
@@ -435,10 +442,7 @@ pub fn handle_flashlight(
}
}
pub fn update_flashlight_charge(
time: Res<Time>,
mut flashlight_query: Query<&mut Flashlight>,
) {
pub fn update_flashlight_charge(time: Res<Time>, mut flashlight_query: Query<&mut Flashlight>) {
for mut flashlight in flashlight_query.iter_mut() {
if flashlight.is_on {
flashlight.charge = flashlight.charge - time.delta_secs() * 0.1;
@@ -472,9 +476,7 @@ pub fn update_flashlight_sprite(
flashlights: Res<FlashlightAssets>,
) {
for (animation, mut image, flashlight) in query.iter_mut() {
println!("charge: {}", flashlight.charge);
let charge = flashlight.charge.ceil() as i32;
println!("charge: {}", charge);
let sprite_image = match (charge, animation.is_pressed) {
(4, true) => flashlights.flash_hold_4_pressed.clone(),
(4, false) => flashlights.flash_hold_4.clone(),
@@ -486,7 +488,7 @@ pub fn update_flashlight_sprite(
(1, false) => flashlights.flash_hold_1.clone(),
(0, true) => flashlights.flash_hold_0_pressed.clone(),
(0, false) => flashlights.flash_hold_0.clone(),
_ => flashlights.flash_hold_0.clone()
_ => flashlights.flash_hold_0.clone(),
};
*image = Sprite::from_image(sprite_image);
}