pickup shows in toolbar
This commit is contained in:
193
Cargo.lock
generated
193
Cargo.lock
generated
@@ -147,6 +147,7 @@ dependencies = [
|
||||
"bevy",
|
||||
"bevy_asset_loader",
|
||||
"bevy_egui",
|
||||
"bevy_kira_audio",
|
||||
"bevy_rapier3d",
|
||||
]
|
||||
|
||||
@@ -168,7 +169,7 @@ dependencies = [
|
||||
"ndk-context",
|
||||
"ndk-sys 0.6.0+11769913",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -593,7 +594,7 @@ dependencies = [
|
||||
"bevy",
|
||||
"ron",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -925,6 +926,20 @@ dependencies = [
|
||||
"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]]
|
||||
name = "bevy_log"
|
||||
version = "0.15.3"
|
||||
@@ -1608,7 +1623,7 @@ dependencies = [
|
||||
"polling",
|
||||
"rustix",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2141,7 +2156,7 @@ dependencies = [
|
||||
"const_panic",
|
||||
"encase_derive",
|
||||
"glam",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2164,6 +2179,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "epaint"
|
||||
version = "0.31.1"
|
||||
@@ -2518,6 +2542,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8babf46d4c1c9d92deac9f7be466f76dfc4482b6452fc5024b5e8daf6ffeb3ee"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"mint",
|
||||
"rand",
|
||||
"serde",
|
||||
]
|
||||
@@ -2612,7 +2637,7 @@ checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd"
|
||||
dependencies = [
|
||||
"log",
|
||||
"presser",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"windows 0.58.0",
|
||||
]
|
||||
|
||||
@@ -3020,7 +3045,7 @@ dependencies = [
|
||||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"walkdir",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
@@ -3074,6 +3099,22 @@ version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "ktx2"
|
||||
version = "0.3.0"
|
||||
@@ -3295,6 +3336,12 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mint"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
|
||||
|
||||
[[package]]
|
||||
name = "naga"
|
||||
version = "23.1.0"
|
||||
@@ -3313,7 +3360,7 @@ dependencies = [
|
||||
"rustc-hash 1.1.0",
|
||||
"spirv",
|
||||
"termcolor",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
@@ -3332,7 +3379,7 @@ dependencies = [
|
||||
"regex",
|
||||
"regex-syntax 0.8.5",
|
||||
"rustc-hash 1.1.0",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"tracing",
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -3376,7 +3423,7 @@ dependencies = [
|
||||
"log",
|
||||
"ndk-sys 0.5.0+25.2.9519653",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3391,7 +3438,7 @@ dependencies = [
|
||||
"ndk-sys 0.6.0+11769913",
|
||||
"num_enum",
|
||||
"raw-window-handle",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3974,7 +4021,7 @@ dependencies = [
|
||||
"slab",
|
||||
"smallvec",
|
||||
"spade",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4282,7 +4329,7 @@ dependencies = [
|
||||
"profiling",
|
||||
"rustc-hash 2.1.1",
|
||||
"simba",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4315,7 +4362,7 @@ dependencies = [
|
||||
"rand_chacha",
|
||||
"simd_helpers",
|
||||
"system-deps",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"v_frame",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
@@ -4457,6 +4504,15 @@ version = "0.8.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "robust"
|
||||
version = "1.1.0"
|
||||
@@ -4471,7 +4527,7 @@ checksum = "6006a627c1a38d37f3d3a85c6575418cfe34a5392d60a686d0071e1c8d427acb"
|
||||
dependencies = [
|
||||
"cpal",
|
||||
"lewton",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4753,7 +4809,7 @@ dependencies = [
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
@@ -4835,6 +4891,77 @@ dependencies = [
|
||||
"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]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
@@ -4926,7 +5053,16 @@ version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
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]]
|
||||
@@ -4940,6 +5076,17 @@ dependencies = [
|
||||
"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]]
|
||||
name = "thread_local"
|
||||
version = "1.1.8"
|
||||
@@ -5141,6 +5288,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "ttf-parser"
|
||||
version = "0.20.0"
|
||||
@@ -5271,6 +5427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b"
|
||||
dependencies = [
|
||||
"getrandom 0.2.15",
|
||||
"rand",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@@ -5602,7 +5759,7 @@ dependencies = [
|
||||
"raw-window-handle",
|
||||
"rustc-hash 1.1.0",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"wgpu-hal",
|
||||
"wgpu-types",
|
||||
]
|
||||
@@ -5644,7 +5801,7 @@ dependencies = [
|
||||
"renderdoc-sys",
|
||||
"rustc-hash 1.1.0",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"wgpu-types",
|
||||
|
||||
@@ -7,4 +7,5 @@ edition = "2024"
|
||||
bevy = { version="0.15.3", features = ["jpeg"]}
|
||||
bevy_asset_loader = { version ="0.22.0", features = ["standard_dynamic_assets"] }
|
||||
bevy_egui = "0.33.0"
|
||||
bevy_kira_audio = "0.22.0"
|
||||
bevy_rapier3d = "0.29.0"
|
||||
|
||||
BIN
assets/audio/flashlight-switch.mp3
Normal file
BIN
assets/audio/flashlight-switch.mp3
Normal file
Binary file not shown.
BIN
assets/audio/flashlight-switch.ogg
Normal file
BIN
assets/audio/flashlight-switch.ogg
Normal file
Binary file not shown.
@@ -1,10 +1,12 @@
|
||||
({
|
||||
"lebron": File (path: "images/KingLebron.png"),
|
||||
"flash_hold_4": File (path: "images/pixelart/Flashlight_hold_4.png"),
|
||||
"house": File (path: "meshes/House.glb"),
|
||||
"library": Folder (
|
||||
path: "meshes/library",
|
||||
),
|
||||
"id_card": File(path: "meshes/id_card.glb")
|
||||
"id_card_toolbar": File(path: "images/id_card_toolbar.png"")
|
||||
"id_card": File(path: "meshes/id_card.glb"),
|
||||
"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"),
|
||||
})
|
||||
|
||||
@@ -3,20 +3,20 @@ use bevy::{prelude::*, utils::HashMap};
|
||||
use crate::GameState;
|
||||
use bevy_asset_loader::prelude::*;
|
||||
// use bevy_egui::{EguiContexts, egui, egui::ProgressBar};
|
||||
// use bevy_kira_audio::AudioSource;
|
||||
use bevy_kira_audio::{AudioPlugin, AudioSource};
|
||||
// use iyes_progress::{ProgressCounter, ProgressPlugin};
|
||||
|
||||
/// Loads resources and assets for the game.
|
||||
/// See assets/main.assets.ron for the actual paths used.
|
||||
pub(super) fn plugin(app: &mut App) {
|
||||
app.add_loading_state(
|
||||
app.add_plugins(AudioPlugin).add_loading_state(
|
||||
LoadingState::new(GameState::Loading)
|
||||
.continue_to_state(GameState::Menu)
|
||||
.with_dynamic_assets_file::<StandardDynamicAssetCollection>("main.assets.ron")
|
||||
.load_collection::<ImageAssets>()
|
||||
.load_collection::<FlashlightAssets>()
|
||||
.load_collection::<GltfAssets>(),
|
||||
// .load_collection::<AudioAssets>()
|
||||
.load_collection::<GltfAssets>()
|
||||
.load_collection::<AudioAssets>(),
|
||||
// .load_collection::<TextureAssets>()
|
||||
// .load_collection::<GrassAssets>()
|
||||
// .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>)
|
||||
|
||||
#[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)]
|
||||
pub(crate) struct GltfAssets {
|
||||
@@ -58,4 +61,6 @@ pub(crate) struct ImageAssets {
|
||||
pub(crate) struct FlashlightAssets {
|
||||
#[asset(key = "flash_hold_4")]
|
||||
pub(crate) flash_hold_4: Handle<Image>,
|
||||
#[asset(key = "flash_hold_4_pressed")]
|
||||
pub(crate) flash_hold_4_pressed: Handle<Image>,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
use bevy::{prelude::*, reflect::DynamicTypePath};
|
||||
use bevy::{image, prelude::*, reflect::DynamicTypePath};
|
||||
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) {
|
||||
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
|
||||
// .library
|
||||
// .get("meshes/library/hammer.glb")
|
||||
@@ -147,6 +157,7 @@ fn spawn_objects(mut commands: Commands, models: Res<Assets<Gltf>>, gltf_assets:
|
||||
Interact,
|
||||
RigidBody::Dynamic,
|
||||
Name::new("Id Card"),
|
||||
ItemIcon::new(image_assets.id_card.clone()),
|
||||
SceneRoot(asset.clone()),
|
||||
))
|
||||
.with_children(|parent| {
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -22,7 +22,7 @@ fn main() {
|
||||
RapierPhysicsPlugin::<NoUserData>::default(),
|
||||
RapierDebugRenderPlugin::default(),
|
||||
player::plugin,
|
||||
debugging::plugin,
|
||||
// debugging::plugin
|
||||
))
|
||||
.init_state::<GameState>()
|
||||
.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),
|
||||
// ));
|
||||
}
|
||||
|
||||
104
src/player.rs
104
src/player.rs
@@ -2,11 +2,12 @@
|
||||
use bevy::{
|
||||
input::mouse::AccumulatedMouseMotion, prelude::*, render::view::RenderLayers, window::{PrimaryWindow, WindowResized}
|
||||
};
|
||||
use bevy_kira_audio::{Audio, AudioControl};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
pub mod toolbar;
|
||||
|
||||
use crate::{asset_loading::FlashlightAssets, GameState};
|
||||
use crate::{asset_loading::{AudioAssets, FlashlightAssets}, GameState};
|
||||
|
||||
#[derive(Debug, Component, Default)]
|
||||
pub struct Player {
|
||||
@@ -51,12 +52,38 @@ impl Default for HeadBob {
|
||||
#[derive(Component, Debug)]
|
||||
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) {
|
||||
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,
|
||||
update_flashlight_button_animation,
|
||||
).run_if(in_state(GameState::Playing)),
|
||||
)
|
||||
.add_systems(
|
||||
FixedUpdate,
|
||||
@@ -112,6 +139,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((
|
||||
@@ -119,6 +147,24 @@ pub fn init_player(
|
||||
transform.0.clone(),
|
||||
transform,
|
||||
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>>,
|
||||
) {
|
||||
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;
|
||||
@@ -221,10 +269,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 +343,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 +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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,12 @@ pub struct Item(Option<Entity>);
|
||||
#[derive(Component, Default, Debug)]
|
||||
pub struct ItemIcon(Handle<Image>);
|
||||
|
||||
impl ItemIcon {
|
||||
pub fn new(h: Handle<Image>) -> Self {
|
||||
Self(h)
|
||||
}
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn none() -> Self {
|
||||
Default::default()
|
||||
@@ -31,9 +37,19 @@ fn bottom_panel(
|
||||
mut egui_ctx: EguiContexts,
|
||||
player_item_query: Query<&Item, With<Player>>,
|
||||
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")
|
||||
.frame(egui::Frame {
|
||||
fill: egui::Color32::from_rgba_premultiplied(0, 0, 0, 0),
|
||||
@@ -52,7 +68,7 @@ fn bottom_panel(
|
||||
|
||||
// Create a frame for the slot
|
||||
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),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -61,20 +77,24 @@ fn bottom_panel(
|
||||
ui.add_sized([50.0, 50.0], |ui: &mut egui::Ui| {
|
||||
// Display the item
|
||||
ui.vertical_centered(|ui| {
|
||||
let item = single!(player_item_query);
|
||||
let item = item.0.and_then(|id| item_query.get(id).ok());
|
||||
// Placeholder for texture - in a real app, load the texture
|
||||
ui.label(egui::RichText::new("🔨").size(24.0));
|
||||
// let (name, icon) = item.map_or_else((Name::new(""), ), |(name, handle)|{
|
||||
|
||||
// });
|
||||
|
||||
// Item count (display only if > 1)
|
||||
ui.label(
|
||||
egui::RichText::new("")
|
||||
.color(egui::Color32::WHITE)
|
||||
.size(12.0),
|
||||
);
|
||||
ui.horizontal_centered(|ui| {
|
||||
match icon {
|
||||
Some(image) => {
|
||||
ui.add(egui::widgets::Image::new(
|
||||
egui::load::SizedTexture::new(image, [50.0, 30.0]),
|
||||
));
|
||||
}
|
||||
None => {
|
||||
ui.label(egui::RichText::new("➖").size(24.0));
|
||||
ui.label(egui::RichText::new("Empty").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())
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user