pickup shows in toolbar

This commit is contained in:
LorrensP-2158466
2025-04-06 16:31:32 +02:00
10 changed files with 349 additions and 59 deletions

193
Cargo.lock generated
View File

@@ -147,6 +147,7 @@ dependencies = [
"bevy", "bevy",
"bevy_asset_loader", "bevy_asset_loader",
"bevy_egui", "bevy_egui",
"bevy_kira_audio",
"bevy_rapier3d", "bevy_rapier3d",
] ]
@@ -168,7 +169,7 @@ dependencies = [
"ndk-context", "ndk-context",
"ndk-sys 0.6.0+11769913", "ndk-sys 0.6.0+11769913",
"num_enum", "num_enum",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -593,7 +594,7 @@ dependencies = [
"bevy", "bevy",
"ron", "ron",
"serde", "serde",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -925,6 +926,20 @@ dependencies = [
"bevy_winit", "bevy_winit",
] ]
[[package]]
name = "bevy_kira_audio"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c929e59bffeb04011aab93880623163c0f8c31c7e99d752d74ba935a53546731"
dependencies = [
"anyhow",
"bevy",
"kira",
"parking_lot",
"thiserror 2.0.12",
"uuid",
]
[[package]] [[package]]
name = "bevy_log" name = "bevy_log"
version = "0.15.3" version = "0.15.3"
@@ -1608,7 +1623,7 @@ dependencies = [
"polling", "polling",
"rustix", "rustix",
"slab", "slab",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -2141,7 +2156,7 @@ dependencies = [
"const_panic", "const_panic",
"encase_derive", "encase_derive",
"glam", "glam",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -2164,6 +2179,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "encoding_rs"
version = "0.8.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "epaint" name = "epaint"
version = "0.31.1" version = "0.31.1"
@@ -2518,6 +2542,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8babf46d4c1c9d92deac9f7be466f76dfc4482b6452fc5024b5e8daf6ffeb3ee" checksum = "8babf46d4c1c9d92deac9f7be466f76dfc4482b6452fc5024b5e8daf6ffeb3ee"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"mint",
"rand", "rand",
"serde", "serde",
] ]
@@ -2612,7 +2637,7 @@ checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd"
dependencies = [ dependencies = [
"log", "log",
"presser", "presser",
"thiserror", "thiserror 1.0.69",
"windows 0.58.0", "windows 0.58.0",
] ]
@@ -3020,7 +3045,7 @@ dependencies = [
"combine", "combine",
"jni-sys", "jni-sys",
"log", "log",
"thiserror", "thiserror 1.0.69",
"walkdir", "walkdir",
"windows-sys 0.45.0", "windows-sys 0.45.0",
] ]
@@ -3074,6 +3099,22 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "kira"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a9f9dff5e262540b628b00d5e1a772270a962d6869f8695bb24832ff3b394"
dependencies = [
"cpal",
"glam",
"mint",
"paste",
"ringbuf",
"send_wrapper",
"symphonia",
"triple_buffer",
]
[[package]] [[package]]
name = "ktx2" name = "ktx2"
version = "0.3.0" version = "0.3.0"
@@ -3295,6 +3336,12 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[package]]
name = "mint"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
[[package]] [[package]]
name = "naga" name = "naga"
version = "23.1.0" version = "23.1.0"
@@ -3313,7 +3360,7 @@ dependencies = [
"rustc-hash 1.1.0", "rustc-hash 1.1.0",
"spirv", "spirv",
"termcolor", "termcolor",
"thiserror", "thiserror 1.0.69",
"unicode-xid", "unicode-xid",
] ]
@@ -3332,7 +3379,7 @@ dependencies = [
"regex", "regex",
"regex-syntax 0.8.5", "regex-syntax 0.8.5",
"rustc-hash 1.1.0", "rustc-hash 1.1.0",
"thiserror", "thiserror 1.0.69",
"tracing", "tracing",
"unicode-ident", "unicode-ident",
] ]
@@ -3376,7 +3423,7 @@ dependencies = [
"log", "log",
"ndk-sys 0.5.0+25.2.9519653", "ndk-sys 0.5.0+25.2.9519653",
"num_enum", "num_enum",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -3391,7 +3438,7 @@ dependencies = [
"ndk-sys 0.6.0+11769913", "ndk-sys 0.6.0+11769913",
"num_enum", "num_enum",
"raw-window-handle", "raw-window-handle",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -3974,7 +4021,7 @@ dependencies = [
"slab", "slab",
"smallvec", "smallvec",
"spade", "spade",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -4282,7 +4329,7 @@ dependencies = [
"profiling", "profiling",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
"simba", "simba",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -4315,7 +4362,7 @@ dependencies = [
"rand_chacha", "rand_chacha",
"simd_helpers", "simd_helpers",
"system-deps", "system-deps",
"thiserror", "thiserror 1.0.69",
"v_frame", "v_frame",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -4457,6 +4504,15 @@ version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a"
[[package]]
name = "ringbuf"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79abed428d1fd2a128201cec72c5f6938e2da607c6f3745f769fabea399d950a"
dependencies = [
"crossbeam-utils",
]
[[package]] [[package]]
name = "robust" name = "robust"
version = "1.1.0" version = "1.1.0"
@@ -4471,7 +4527,7 @@ checksum = "6006a627c1a38d37f3d3a85c6575418cfe34a5392d60a686d0071e1c8d427acb"
dependencies = [ dependencies = [
"cpal", "cpal",
"lewton", "lewton",
"thiserror", "thiserror 1.0.69",
] ]
[[package]] [[package]]
@@ -4753,7 +4809,7 @@ dependencies = [
"log", "log",
"memmap2", "memmap2",
"rustix", "rustix",
"thiserror", "thiserror 1.0.69",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-csd-frame", "wayland-csd-frame",
@@ -4835,6 +4891,77 @@ dependencies = [
"zeno", "zeno",
] ]
[[package]]
name = "symphonia"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "815c942ae7ee74737bb00f965fa5b5a2ac2ce7b6c01c0cc169bbeaf7abd5f5a9"
dependencies = [
"lazy_static",
"symphonia-codec-vorbis",
"symphonia-core",
"symphonia-format-ogg",
"symphonia-metadata",
]
[[package]]
name = "symphonia-codec-vorbis"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a98765fb46a0a6732b007f7e2870c2129b6f78d87db7987e6533c8f164a9f30"
dependencies = [
"log",
"symphonia-core",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-core"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "798306779e3dc7d5231bd5691f5a813496dc79d3f56bf82e25789f2094e022c3"
dependencies = [
"arrayvec",
"bitflags 1.3.2",
"bytemuck",
"lazy_static",
"log",
]
[[package]]
name = "symphonia-format-ogg"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ada3505789516bcf00fc1157c67729eded428b455c27ca370e41f4d785bfa931"
dependencies = [
"log",
"symphonia-core",
"symphonia-metadata",
"symphonia-utils-xiph",
]
[[package]]
name = "symphonia-metadata"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc622b9841a10089c5b18e99eb904f4341615d5aa55bbf4eedde1be721a4023c"
dependencies = [
"encoding_rs",
"lazy_static",
"log",
"symphonia-core",
]
[[package]]
name = "symphonia-utils-xiph"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "484472580fa49991afda5f6550ece662237b00c6f562c7d9638d1b086ed010fe"
dependencies = [
"symphonia-core",
"symphonia-metadata",
]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.100" version = "2.0.100"
@@ -4926,7 +5053,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl 2.0.12",
] ]
[[package]] [[package]]
@@ -4940,6 +5076,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thiserror-impl"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.1.8" version = "1.1.8"
@@ -5141,6 +5288,15 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "triple_buffer"
version = "8.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de7a7d39da903eaef0d0fd14aae8c8c36cdd7dc1d5a251f88c84b676e8dc0a14"
dependencies = [
"crossbeam-utils",
]
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.20.0" version = "0.20.0"
@@ -5271,6 +5427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b"
dependencies = [ dependencies = [
"getrandom 0.2.15", "getrandom 0.2.15",
"rand",
"serde", "serde",
] ]
@@ -5602,7 +5759,7 @@ dependencies = [
"raw-window-handle", "raw-window-handle",
"rustc-hash 1.1.0", "rustc-hash 1.1.0",
"smallvec", "smallvec",
"thiserror", "thiserror 1.0.69",
"wgpu-hal", "wgpu-hal",
"wgpu-types", "wgpu-types",
] ]
@@ -5644,7 +5801,7 @@ dependencies = [
"renderdoc-sys", "renderdoc-sys",
"rustc-hash 1.1.0", "rustc-hash 1.1.0",
"smallvec", "smallvec",
"thiserror", "thiserror 1.0.69",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
"wgpu-types", "wgpu-types",

View File

@@ -7,4 +7,5 @@ edition = "2024"
bevy = { version="0.15.3", features = ["jpeg"]} bevy = { version="0.15.3", features = ["jpeg"]}
bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] } bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] }
bevy_egui = "0.33.0" bevy_egui = "0.33.0"
bevy_kira_audio = "0.22.0"
bevy_rapier3d = "0.29.0" bevy_rapier3d = "0.29.0"

Binary file not shown.

Binary file not shown.

View File

@@ -1,10 +1,12 @@
({ ({
"lebron": File (path: "images/KingLebron.png"), "lebron": File (path: "images/KingLebron.png"),
"flash_hold_4": File (path: "images/pixelart/Flashlight_hold_4.png"),
"house": File (path: "meshes/House.glb"), "house": File (path: "meshes/House.glb"),
"library": Folder ( "library": Folder (
path: "meshes/library", path: "meshes/library",
), ),
"id_card": File(path: "meshes/id_card.glb") "id_card": File(path: "meshes/id_card.glb"),
"id_card_toolbar": File(path: "images/id_card_toolbar.png"") "id_card_toolbar": File(path: "images/id_card_toolbar.png"),
"flash_hold_4": File (path: "images/pixelart/Flashlight_hold_4.png"),
"flash_hold_4_pressed": File (path: "images/pixelart/Flashlight_click_4.png"),
"flashlight_click": File (path: "audio/flashlight-switch.ogg"),
}) })

View File

@@ -3,20 +3,20 @@ use bevy::{prelude::*, utils::HashMap};
use crate::GameState; use crate::GameState;
use bevy_asset_loader::prelude::*; use bevy_asset_loader::prelude::*;
// use bevy_egui::{EguiContexts, egui, egui::ProgressBar}; // use bevy_egui::{EguiContexts, egui, egui::ProgressBar};
// use bevy_kira_audio::AudioSource; use bevy_kira_audio::{AudioPlugin, AudioSource};
// use iyes_progress::{ProgressCounter, ProgressPlugin}; // use iyes_progress::{ProgressCounter, ProgressPlugin};
/// Loads resources and assets for the game. /// Loads resources and assets for the game.
/// See assets/main.assets.ron for the actual paths used. /// See assets/main.assets.ron for the actual paths used.
pub(super) fn plugin(app: &mut App) { pub(super) fn plugin(app: &mut App) {
app.add_loading_state( app.add_plugins(AudioPlugin).add_loading_state(
LoadingState::new(GameState::Loading) LoadingState::new(GameState::Loading)
.continue_to_state(GameState::Menu) .continue_to_state(GameState::Menu)
.with_dynamic_assets_file::<StandardDynamicAssetCollection>("main.assets.ron") .with_dynamic_assets_file::<StandardDynamicAssetCollection>("main.assets.ron")
.load_collection::<ImageAssets>() .load_collection::<ImageAssets>()
.load_collection::<FlashlightAssets>() .load_collection::<FlashlightAssets>()
.load_collection::<GltfAssets>(), .load_collection::<GltfAssets>()
// .load_collection::<AudioAssets>() .load_collection::<AudioAssets>(),
// .load_collection::<TextureAssets>() // .load_collection::<TextureAssets>()
// .load_collection::<GrassAssets>() // .load_collection::<GrassAssets>()
// .load_collection::<ConfigAssets>(), // .load_collection::<ConfigAssets>(),
@@ -27,7 +27,10 @@ pub(super) fn plugin(app: &mut App) {
// when done loading, they will be inserted as resources (see <https://github.com/NiklasEi/bevy_asset_loader>) // when done loading, they will be inserted as resources (see <https://github.com/NiklasEi/bevy_asset_loader>)
#[derive(AssetCollection, Resource, Clone)] #[derive(AssetCollection, Resource, Clone)]
pub(crate) struct AudioAssets {} pub(crate) struct AudioAssets {
#[asset(key = "flashlight_click")]
pub(crate) flash_click: Handle<AudioSource>,
}
#[derive(AssetCollection, Resource, Clone)] #[derive(AssetCollection, Resource, Clone)]
pub(crate) struct GltfAssets { pub(crate) struct GltfAssets {
@@ -58,4 +61,6 @@ pub(crate) struct ImageAssets {
pub(crate) struct FlashlightAssets { pub(crate) struct FlashlightAssets {
#[asset(key = "flash_hold_4")] #[asset(key = "flash_hold_4")]
pub(crate) flash_hold_4: Handle<Image>, pub(crate) flash_hold_4: Handle<Image>,
#[asset(key = "flash_hold_4_pressed")]
pub(crate) flash_hold_4_pressed: Handle<Image>,
} }

View File

@@ -1,7 +1,12 @@
use bevy::{prelude::*, reflect::DynamicTypePath}; use bevy::{image, prelude::*, reflect::DynamicTypePath};
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
use crate::{GameState, asset_loading::GltfAssets, interaction::Interact}; use crate::{
GameState,
asset_loading::{GltfAssets, ImageAssets},
interaction::Interact,
player::toolbar::ItemIcon,
};
pub fn map_plugin(app: &mut App) { pub fn map_plugin(app: &mut App) {
app.add_systems( app.add_systems(
@@ -112,7 +117,12 @@ fn spawn_level(mut commands: Commands, models: Res<Assets<Gltf>>, gltf_assets: R
)); ));
} }
fn spawn_objects(mut commands: Commands, models: Res<Assets<Gltf>>, gltf_assets: Res<GltfAssets>) { fn spawn_objects(
mut commands: Commands,
models: Res<Assets<Gltf>>,
gltf_assets: Res<GltfAssets>,
image_assets: Res<ImageAssets>,
) {
// let hammer = gltf_assets // let hammer = gltf_assets
// .library // .library
// .get("meshes/library/hammer.glb") // .get("meshes/library/hammer.glb")
@@ -147,6 +157,7 @@ fn spawn_objects(mut commands: Commands, models: Res<Assets<Gltf>>, gltf_assets:
Interact, Interact,
RigidBody::Dynamic, RigidBody::Dynamic,
Name::new("Id Card"), Name::new("Id Card"),
ItemIcon::new(image_assets.id_card.clone()),
SceneRoot(asset.clone()), SceneRoot(asset.clone()),
)) ))
.with_children(|parent| { .with_children(|parent| {

View File

@@ -22,7 +22,7 @@ fn main() {
RapierPhysicsPlugin::<NoUserData>::default(), RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(), RapierDebugRenderPlugin::default(),
player::plugin, player::plugin,
debugging::plugin, // debugging::plugin
)) ))
.init_state::<GameState>() .init_state::<GameState>()
.add_systems(OnEnter(GameState::Playing), setup) .add_systems(OnEnter(GameState::Playing), setup)
@@ -62,11 +62,11 @@ fn setup(
Collider::cuboid(0.5, 0.5, 0.5), Collider::cuboid(0.5, 0.5, 0.5),
)); ));
// light // light
commands.spawn(( // commands.spawn((
PointLight { // PointLight {
shadows_enabled: true, // shadows_enabled: true,
..default() // ..default()
}, // },
Transform::from_xyz(4.0, 8.0, 4.0), // Transform::from_xyz(4.0, 8.0, 4.0),
)); // ));
} }

View File

@@ -2,11 +2,12 @@
use bevy::{ use bevy::{
input::mouse::AccumulatedMouseMotion, prelude::*, render::view::RenderLayers, window::{PrimaryWindow, WindowResized} input::mouse::AccumulatedMouseMotion, prelude::*, render::view::RenderLayers, window::{PrimaryWindow, WindowResized}
}; };
use bevy_kira_audio::{Audio, AudioControl};
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
pub mod toolbar; pub mod toolbar;
use crate::{asset_loading::FlashlightAssets, GameState}; use crate::{asset_loading::{AudioAssets, FlashlightAssets}, GameState};
#[derive(Debug, Component, Default)] #[derive(Debug, Component, Default)]
pub struct Player { pub struct Player {
@@ -51,12 +52,38 @@ impl Default for HeadBob {
#[derive(Component, Debug)] #[derive(Component, Debug)]
pub struct BaseTransform(pub Transform); pub struct BaseTransform(pub Transform);
#[derive(Debug, Component)]
pub struct Flashlight;
#[derive(Component)]
pub struct FlashlightButtonAnimation {
pub timer: Timer,
pub is_pressed: bool,
}
impl Default for FlashlightButtonAnimation {
fn default() -> Self {
Self {
timer: Timer::from_seconds(0.20, TimerMode::Once),
is_pressed: false,
}
}
}
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {
app.add_plugins(toolbar::plugin) app.add_plugins(toolbar::plugin)
.add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor)) .add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor))
.add_systems( .add_systems(
Update, 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,
update_flashlight_button_animation,
).run_if(in_state(GameState::Playing)),
) )
.add_systems( .add_systems(
FixedUpdate, FixedUpdate,
@@ -112,6 +139,7 @@ pub fn init_player(
RenderLayers::layer(STATIC_LAYER), RenderLayers::layer(STATIC_LAYER),
)); ));
// pitslamp sprite
let window = window.single(); let window = window.single();
let transform = flashlight_base_transform(window.width(), window.height()); let transform = flashlight_base_transform(window.width(), window.height());
parent.spawn(( parent.spawn((
@@ -119,6 +147,24 @@ pub fn init_player(
transform.0.clone(), transform.0.clone(),
transform, transform,
RenderLayers::layer(STATIC_LAYER), RenderLayers::layer(STATIC_LAYER),
FlashlightButtonAnimation::default(),
));
// feitelijke pitslamp
parent.spawn((
Flashlight,
SpotLight {
intensity: 0.0,
color: Color::WHITE,
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(0.0, -0.15, 0.5),
GlobalTransform::default(),
)); ));
}); });
} }
@@ -194,6 +240,8 @@ pub fn handle_input(
mut query: Query<(&Transform, &mut PlayerInput, &mut PlayerAction, &mut Player), With<Player>>, mut query: Query<(&Transform, &mut PlayerInput, &mut PlayerAction, &mut Player), With<Player>>,
) { ) {
for (transform, mut input, mut action, mut player) in query.iter_mut() { for (transform, mut input, mut action, mut player) in query.iter_mut() {
*action = PlayerAction::Move;
let forward = transform.forward(); let forward = transform.forward();
let right = transform.right(); let right = transform.right();
let mut movement_direction = Vec3::ZERO; let mut movement_direction = Vec3::ZERO;
@@ -221,10 +269,10 @@ pub fn handle_input(
} else { } else {
player.speed_factor = 1.0; player.speed_factor = 1.0;
} }
if keyboard_input.pressed(KeyCode::KeyE) { if keyboard_input.just_pressed(KeyCode::KeyE) {
*action = PlayerAction::Interact *action = PlayerAction::Interact
} }
if keyboard_input.pressed(KeyCode::KeyA) { if keyboard_input.just_pressed(KeyCode::KeyF) {
*action = PlayerAction::ToggleFlashlight; *action = PlayerAction::ToggleFlashlight;
} }
@@ -295,7 +343,7 @@ pub fn apply_head_bob(
if is_moving { if is_moving {
transform.translation.x = horizontal_offset; transform.translation.x = horizontal_offset;
} else { } else {
// decrease bobbing magnitued // decrease bobbing magnitude
transform.translation.x *= 0.8; transform.translation.x *= 0.8;
} }
} }
@@ -320,4 +368,50 @@ pub fn apply_head_bob(
} }
} }
} }
}
pub fn handle_flashlight(
player_query: Query<&PlayerAction, With<Player>>,
mut flashlight_query: Query<&mut SpotLight, With<Flashlight>>,
mut flashlight_sprite_query: Query<&mut FlashlightButtonAnimation>,
audio_assets: Res<AudioAssets>,
audio: Res<Audio>,
) {
let Ok(action) = player_query.get_single() else {
return;
};
if *action != PlayerAction::ToggleFlashlight {
return;
}
if let Ok(mut animation) = flashlight_sprite_query.get_single_mut() {
animation.is_pressed = true;
animation.timer.reset();
}
if let Ok(mut spotlight) = flashlight_query.get_single_mut() {
audio.play(audio_assets.flash_click.clone());
spotlight.intensity = if spotlight.intensity > 0.0 {
0.0
} else {
300_000.0
};
}
}
pub fn update_flashlight_button_animation(
time: Res<Time>,
mut query: Query<(&mut FlashlightButtonAnimation, &mut Sprite)>,
flashlights: Res<FlashlightAssets>,
) {
for (mut animation, mut image) in query.iter_mut() {
if animation.is_pressed {
animation.timer.tick(time.delta());
if animation.timer.finished() {
*image = Sprite::from_image(flashlights.flash_hold_4.clone());
animation.is_pressed = false;
} else {
*image = Sprite::from_image(flashlights.flash_hold_4_pressed.clone());
}
}
}
} }

View File

@@ -12,6 +12,12 @@ pub struct Item(Option<Entity>);
#[derive(Component, Default, Debug)] #[derive(Component, Default, Debug)]
pub struct ItemIcon(Handle<Image>); pub struct ItemIcon(Handle<Image>);
impl ItemIcon {
pub fn new(h: Handle<Image>) -> Self {
Self(h)
}
}
impl Item { impl Item {
pub fn none() -> Self { pub fn none() -> Self {
Default::default() Default::default()
@@ -31,9 +37,19 @@ fn bottom_panel(
mut egui_ctx: EguiContexts, mut egui_ctx: EguiContexts,
player_item_query: Query<&Item, With<Player>>, player_item_query: Query<&Item, With<Player>>,
item_query: Query<(&Name, &ItemIcon), With<Interact>>, item_query: Query<(&Name, &ItemIcon), With<Interact>>,
models: Res<Assets<Image>>,
gltf_assets: Res<ImageAssets>,
) { ) {
let item = single!(player_item_query);
let item = item.0.and_then(|id| item_query.get(id).ok());
let (name, icon) = item.map_or_else(
|| (Name::new(""), None),
|(name, handle)| {
(
name.clone(),
Some(egui_ctx.add_image(handle.0.clone_weak())),
)
},
);
egui::TopBottomPanel::bottom("inventory_toolbar") egui::TopBottomPanel::bottom("inventory_toolbar")
.frame(egui::Frame { .frame(egui::Frame {
fill: egui::Color32::from_rgba_premultiplied(0, 0, 0, 0), fill: egui::Color32::from_rgba_premultiplied(0, 0, 0, 0),
@@ -52,7 +68,7 @@ fn bottom_panel(
// Create a frame for the slot // Create a frame for the slot
let slot_frame = egui::Frame { let slot_frame = egui::Frame {
fill: egui::Color32::from_rgba_premultiplied(50, 50, 50, 100), fill: egui::Color32::from_rgba_premultiplied(75, 75, 75, 100),
stroke: egui::Stroke::new(2.0, egui::Color32::WHITE), stroke: egui::Stroke::new(2.0, egui::Color32::WHITE),
..Default::default() ..Default::default()
}; };
@@ -61,20 +77,24 @@ fn bottom_panel(
ui.add_sized([50.0, 50.0], |ui: &mut egui::Ui| { ui.add_sized([50.0, 50.0], |ui: &mut egui::Ui| {
// Display the item // Display the item
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
let item = single!(player_item_query); ui.horizontal_centered(|ui| {
let item = item.0.and_then(|id| item_query.get(id).ok()); match icon {
// Placeholder for texture - in a real app, load the texture Some(image) => {
ui.label(egui::RichText::new("🔨").size(24.0)); ui.add(egui::widgets::Image::new(
// let (name, icon) = item.map_or_else((Name::new(""), ), |(name, handle)|{ egui::load::SizedTexture::new(image, [50.0, 30.0]),
));
// }); }
None => {
// Item count (display only if > 1) ui.label(egui::RichText::new("").size(24.0));
ui.label( ui.label(egui::RichText::new("Empty").size(12.0));
egui::RichText::new("") }
.color(egui::Color32::WHITE) }
.size(12.0), ui.label(
); egui::RichText::new(name)
.color(egui::Color32::WHITE)
.size(12.0),
);
});
}); });
ui.allocate_response(ui.available_size(), egui::Sense::click()) ui.allocate_response(ui.available_size(), egui::Sense::click())
}); });