18 Commits

Author SHA1 Message Date
6050a61c12 fix
All checks were successful
ci / ci (macos) (pull_request) Successful in 7m50s
ci / ci (linux) (pull_request) Successful in 24m4s
2025-12-23 08:48:32 -05:00
2fd9b965aa test 3
Some checks failed
ci / ci ([self-hosted linux]) (pull_request) Has been cancelled
ci / ci ([self-hosted macos]) (pull_request) Has been cancelled
2025-12-23 08:46:13 -05:00
9162a38013 try
Some checks failed
ci / ci (macos) (pull_request) Failing after 13s
ci / ci (linux) (pull_request) Has been cancelled
2025-12-23 08:44:20 -05:00
618d02d145 test
All checks were successful
ci / ci (linux) (pull_request) Successful in 24m8s
2025-12-23 08:40:40 -05:00
544c4053c0 try fixing matrix buil
Some checks are pending
ci / ci (linux) (push) Waiting to run
ci / ci (macos) (push) Waiting to run
2025-12-23 08:35:25 -05:00
1390bab2df test matrix syntax 2025-12-22 23:19:22 -05:00
a7239b3e83 fix ci
Some checks failed
ci / ci ([self-hosted linux]) (push) Has been cancelled
ci / ci ([self-hosted macos]) (push) Has been cancelled
2025-12-22 22:18:55 -05:00
16b08e2547 use gitea compatible artifact upload
Some checks failed
ci / ci ([self-hosted linux]) (push) Has been cancelled
ci / ci ([self-hosted macos]) (push) Has been cancelled
2025-12-22 22:07:04 -05:00
6ed54dfdc7 fix animation (feet)
Some checks failed
ci / ci ([self-hosted linux]) (push) Has been cancelled
ci / ci ([self-hosted macos]) (push) Has been cancelled
2025-12-22 08:36:36 -05:00
PROMETHIA-27
dd01b03526 fix depenetration panic (#98) 2025-12-22 07:22:27 -05:00
extrawurst
da5c0f8fb7 fix cash in multiplayer (#97)
* replicate it
* use collision observer to simplify
* pass entity of player that receives cash for a duplicate head
2025-12-21 21:44:43 -05:00
375b8a5b46 fix cash ui 2025-12-21 17:52:24 -05:00
89e6102b06 fix player rotation 2025-12-21 16:01:36 -05:00
e22fa8d134 more clear splitting of visual stuff in client mod 2025-12-21 15:27:11 -05:00
181b617620 make backwork in multiplayer 2025-12-21 13:53:57 -05:00
56ca801992 move heads_ui in client only module 2025-12-21 13:10:50 -05:00
16cd95ae02 cleaunup 2025-12-21 12:55:29 -05:00
fcb13eed31 UiActiveHeads can be a local player resource only 2025-12-21 12:46:32 -05:00
46 changed files with 1035 additions and 732 deletions

View File

@@ -30,7 +30,7 @@ jobs:
cp target/x86_64-unknown-linux-gnu/release/hedz_reloaded ./
tar -czf steamos.tar.gz hedz_reloaded
- uses: actions/upload-artifact@v4
- uses: christopherhx/gitea-upload-artifact@v4
with:
name: steamos.tar.gz
path: ./steamos.tar.gz

View File

@@ -35,7 +35,7 @@ jobs:
cp target/x86_64-pc-windows-msvc/release/hedz_reloaded.exe ./
tar -czf win.tar.gz hedz_reloaded.exe
- uses: actions/upload-artifact@v4
- uses: christopherhx/gitea-upload-artifact@v4
with:
name: win.tar.gz
path: ./win.tar.gz

View File

@@ -9,13 +9,11 @@ jobs:
ci:
strategy:
matrix:
os: [[self-hosted, linux], [self-hosted, macos]]
runs-on: "${{ matrix.os }}"
os: ["linux", "macos"]
runs-on: ["self-hosted", "${{ matrix.os }}"]
steps:
- uses: actions/checkout@v4
- uses: cargo-bins/cargo-binstall@main
if: runner.os == 'linux'
- uses: extractions/setup-just@v1
- uses: dtolnay/rust-toolchain@master
with:

View File

@@ -38,7 +38,7 @@ jobs:
cp target/x86_64-unknown-linux-gnu/debug/hedz_reloaded target/x86_64-unknown-linux-gnu/debug/hedz_reloaded_server ./
tar -czf steamos-debug.tar.gz hedz_reloaded hedz_reloaded_server
- uses: actions/upload-artifact@v4
- uses: christopherhx/gitea-upload-artifact@v4
with:
name: steamos-debug.tar.gz
path: ./steamos-debug.tar.gz

View File

@@ -32,7 +32,7 @@ jobs:
tar -czf hedz-macos.tar.gz hedz_reloaded
ls -lisah hedz-macos.tar.gz
- uses: actions/upload-artifact@v4
- uses: christopherhx/gitea-upload-artifact@v4
with:
name: hedz-macos
path: ./hedz-macos.tar.gz
@@ -118,7 +118,7 @@ jobs:
cp target/x86_64-unknown-linux-gnu/release/hedz_reloaded ./
tar -czf steamos.tar.gz hedz_reloaded
- uses: actions/upload-artifact@v4
- uses: christopherhx/gitea-upload-artifact@v4
with:
name: steamos.tar.gz
path: ./steamos.tar.gz

15
.github/workflows/test_matrix.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: test matrix
on:
workflow_dispatch:
jobs:
test-single:
runs-on: linux
steps:
- run: echo "Single label works"
test-array:
runs-on: [self-hosted, linux]
steps:
- run: echo "Array label works"

275
Cargo.lock generated
View File

@@ -102,6 +102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
dependencies = [
"cfg-if",
"getrandom 0.3.4",
"once_cell",
"version_check",
"zerocopy",
@@ -580,7 +581,7 @@ dependencies = [
"bevy_utils",
"blake3",
"derive_more",
"downcast-rs",
"downcast-rs 2.0.2",
"either",
"petgraph",
"ron 0.10.1",
@@ -640,7 +641,7 @@ dependencies = [
"cfg-if",
"console_error_panic_hook",
"ctrlc",
"downcast-rs",
"downcast-rs 2.0.2",
"log",
"thiserror 2.0.17",
"variadics_please",
@@ -671,7 +672,7 @@ dependencies = [
"crossbeam-channel",
"derive_more",
"disqualified",
"downcast-rs",
"downcast-rs 2.0.2",
"either",
"futures-io",
"futures-lite",
@@ -743,6 +744,7 @@ dependencies = [
"bevy_reflect",
"bevy_transform",
"coreaudio-sys",
"cpal",
"rodio",
"tracing",
]
@@ -774,7 +776,7 @@ dependencies = [
"bevy_utils",
"bevy_window",
"derive_more",
"downcast-rs",
"downcast-rs 2.0.2",
"serde",
"smallvec",
"thiserror 2.0.17",
@@ -1177,6 +1179,7 @@ dependencies = [
"bevy_pbr",
"bevy_picking",
"bevy_platform",
"bevy_post_process",
"bevy_ptr",
"bevy_reflect",
"bevy_render",
@@ -1393,6 +1396,36 @@ dependencies = [
"web-time",
]
[[package]]
name = "bevy_post_process"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b857972f5d56b43b0dce2c843b75b64d5fbbd0f6177f6ecccd75e7e41f72deb"
dependencies = [
"bevy_app",
"bevy_asset",
"bevy_camera",
"bevy_color",
"bevy_core_pipeline",
"bevy_derive",
"bevy_ecs",
"bevy_image",
"bevy_math",
"bevy_platform",
"bevy_reflect",
"bevy_render",
"bevy_shader",
"bevy_transform",
"bevy_utils",
"bevy_window",
"bitflags 2.10.0",
"nonmax",
"radsort",
"smallvec",
"thiserror 2.0.17",
"tracing",
]
[[package]]
name = "bevy_ptr"
version = "0.17.3"
@@ -1412,7 +1445,7 @@ dependencies = [
"bevy_utils",
"derive_more",
"disqualified",
"downcast-rs",
"downcast-rs 2.0.2",
"erased-serde",
"foldhash 0.2.0",
"glam 0.30.9",
@@ -1471,7 +1504,7 @@ dependencies = [
"bitflags 2.10.0",
"bytemuck",
"derive_more",
"downcast-rs",
"downcast-rs 2.0.2",
"encase",
"fixedbitset",
"image",
@@ -2121,6 +2154,18 @@ dependencies = [
"thiserror 1.0.69",
]
[[package]]
name = "calloop-wayland-source"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
dependencies = [
"calloop",
"rustix 0.38.44",
"wayland-backend",
"wayland-client",
]
[[package]]
name = "cc"
version = "1.2.49"
@@ -2854,6 +2899,12 @@ dependencies = [
"litrs",
]
[[package]]
name = "downcast-rs"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
[[package]]
name = "downcast-rs"
version = "2.0.2"
@@ -3634,7 +3685,7 @@ dependencies = [
[[package]]
name = "happy_feet"
version = "0.1.0"
source = "git+https://github.com/rustunit/happy_feet.git?rev=919657fa#919657fa3330b3a78026c239c17122b3e3beefd7"
source = "git+https://github.com/PROMETHIA-27/happy_feet.git?rev=e3a4660e0b68f9bf4d6facb0fb4d93f2d7848b27#e3a4660e0b68f9bf4d6facb0fb4d93f2d7848b27"
dependencies = [
"avian3d",
"bevy",
@@ -5015,7 +5066,7 @@ dependencies = [
"approx",
"arrayvec",
"bitflags 2.10.0",
"downcast-rs",
"downcast-rs 2.0.2",
"either",
"ena",
"foldhash 0.2.0",
@@ -5046,7 +5097,7 @@ dependencies = [
"approx",
"arrayvec",
"bitflags 2.10.0",
"downcast-rs",
"downcast-rs 2.0.2",
"either",
"ena",
"foldhash 0.2.0",
@@ -5332,6 +5383,15 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quick-xml"
version = "0.37.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb"
dependencies = [
"memchr",
]
[[package]]
name = "quote"
version = "1.0.42"
@@ -5775,12 +5835,31 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "scoped-tls"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sctk-adwaita"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec"
dependencies = [
"ab_glyph",
"log",
"memmap2",
"smithay-client-toolkit",
"tiny-skia",
]
[[package]]
name = "self_cell"
version = "1.2.1"
@@ -5945,6 +6024,31 @@ dependencies = [
"syn",
]
[[package]]
name = "smithay-client-toolkit"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
dependencies = [
"bitflags 2.10.0",
"calloop",
"calloop-wayland-source",
"cursor-icon",
"libc",
"log",
"memmap2",
"rustix 0.38.44",
"thiserror 1.0.69",
"wayland-backend",
"wayland-client",
"wayland-csd-frame",
"wayland-cursor",
"wayland-protocols",
"wayland-protocols-wlr",
"wayland-scanner",
"xkeysym",
]
[[package]]
name = "smol_str"
version = "0.2.2"
@@ -6024,6 +6128,12 @@ version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42862065c9e685d08cc3d9f6c609d4b46bd9684ec7e9420688eb979213469582"
[[package]]
name = "strict-num"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
[[package]]
name = "strsim"
version = "0.10.0"
@@ -6243,6 +6353,31 @@ dependencies = [
"time-core",
]
[[package]]
name = "tiny-skia"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
dependencies = [
"arrayref",
"arrayvec",
"bytemuck",
"cfg-if",
"log",
"tiny-skia-path",
]
[[package]]
name = "tiny-skia-path"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93"
dependencies = [
"arrayref",
"bytemuck",
"strict-num",
]
[[package]]
name = "tinystr"
version = "0.8.2"
@@ -6717,6 +6852,114 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "wayland-backend"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673a33c33048a5ade91a6b139580fa174e19fb0d23f396dca9fa15f2e1e49b35"
dependencies = [
"cc",
"downcast-rs 1.2.1",
"rustix 1.1.2",
"scoped-tls",
"smallvec",
"wayland-sys",
]
[[package]]
name = "wayland-client"
version = "0.31.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66a47e840dc20793f2264eb4b3e4ecb4b75d91c0dd4af04b456128e0bdd449d"
dependencies = [
"bitflags 2.10.0",
"rustix 1.1.2",
"wayland-backend",
"wayland-scanner",
]
[[package]]
name = "wayland-csd-frame"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e"
dependencies = [
"bitflags 2.10.0",
"cursor-icon",
"wayland-backend",
]
[[package]]
name = "wayland-cursor"
version = "0.31.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447ccc440a881271b19e9989f75726d60faa09b95b0200a9b7eb5cc47c3eeb29"
dependencies = [
"rustix 1.1.2",
"wayland-client",
"xcursor",
]
[[package]]
name = "wayland-protocols"
version = "0.32.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efa790ed75fbfd71283bd2521a1cfdc022aabcc28bdcff00851f9e4ae88d9901"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-scanner",
]
[[package]]
name = "wayland-protocols-plasma"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a07a14257c077ab3279987c4f8bb987851bf57081b93710381daea94f2c2c032"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-scanner",
]
[[package]]
name = "wayland-protocols-wlr"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd94963ed43cf9938a090ca4f7da58eb55325ec8200c3848963e98dc25b78ec"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-scanner",
]
[[package]]
name = "wayland-scanner"
version = "0.31.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3"
dependencies = [
"proc-macro2",
"quick-xml",
"quote",
]
[[package]]
name = "wayland-sys"
version = "0.31.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34949b42822155826b41db8e5d0c1be3a2bd296c747577a43a3e6daefc296142"
dependencies = [
"dlib",
"log",
"pkg-config",
]
[[package]]
name = "web-sys"
version = "0.3.83"
@@ -7395,6 +7638,7 @@ version = "0.30.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66d4b9ed69c4009f6321f762d6e61ad8a2389cd431b97cb1e146812e9e6c732"
dependencies = [
"ahash",
"android-activity",
"atomic-waker",
"bitflags 2.10.0",
@@ -7409,6 +7653,7 @@ dependencies = [
"dpi",
"js-sys",
"libc",
"memmap2",
"ndk 0.9.0",
"objc2 0.5.2",
"objc2-app-kit 0.2.2",
@@ -7420,11 +7665,17 @@ dependencies = [
"raw-window-handle",
"redox_syscall 0.4.1",
"rustix 0.38.44",
"sctk-adwaita",
"smithay-client-toolkit",
"smol_str",
"tracing",
"unicode-segmentation",
"wasm-bindgen",
"wasm-bindgen-futures",
"wayland-backend",
"wayland-client",
"wayland-protocols",
"wayland-protocols-plasma",
"web-sys",
"web-time",
"windows-sys 0.52.0",
@@ -7495,6 +7746,12 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
[[package]]
name = "xcursor"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec9e4a500ca8864c5b47b8b482a73d62e4237670e5b5f1d6b9e3cae50f28f2b"
[[package]]
name = "xkbcommon-dl"
version = "0.4.2"

View File

@@ -67,7 +67,7 @@ bevy_trenchbroom = { version = "0.10", default-features = false, features = [
bevy_trenchbroom_avian = "0.10"
clap = { version = "=4.5.47", features = ["derive"] }
dirs = "6.0.0"
happy_feet = { git = "https://github.com/rustunit/happy_feet.git", rev = "919657fa", features = [
happy_feet = { git = "https://github.com/PROMETHIA-27/happy_feet.git", rev = "e3a4660e0b68f9bf4d6facb0fb4d93f2d7848b27", features = [
"serde",
] }
nil = "0.14.0"

View File

@@ -1,8 +1,11 @@
use super::TriggerArrow;
use crate::{
GameState, billboards::Billboard, global_observer, heads_database::HeadsDatabase,
hitpoints::Hit, loading_assets::GameAssets, physics_layers::GameLayer,
utils::sprite_3d_animation::AnimationTimer,
GameState, global_observer,
heads_database::HeadsDatabase,
hitpoints::Hit,
loading_assets::GameAssets,
physics_layers::GameLayer,
utils::{Billboard, sprite_3d_animation::AnimationTimer},
};
use avian3d::prelude::*;
use bevy::{light::NotShadowCaster, prelude::*};

View File

@@ -1,8 +1,14 @@
use super::TriggerGun;
use crate::{
GameState, abilities::ProjectileId, billboards::Billboard, global_observer,
heads_database::HeadsDatabase, hitpoints::Hit, loading_assets::GameAssets,
physics_layers::GameLayer, tb_entities::EnemySpawn, utils::sprite_3d_animation::AnimationTimer,
GameState,
abilities::ProjectileId,
global_observer,
heads_database::HeadsDatabase,
hitpoints::Hit,
loading_assets::GameAssets,
physics_layers::GameLayer,
tb_entities::EnemySpawn,
utils::{Billboard, sprite_3d_animation::AnimationTimer},
};
use avian3d::prelude::*;
use bevy::{light::NotShadowCaster, prelude::*};

View File

@@ -17,7 +17,7 @@ use crate::{
physics_layers::GameLayer,
player::Player,
protocol::PlaySound,
utils::{billboards::Billboard, explosions::Explosion, sprite_3d_animation::AnimationTimer},
utils::{Billboard, explosions::Explosion, sprite_3d_animation::AnimationTimer},
};
use bevy::{light::NotShadowCaster, prelude::*};
use bevy_replicon::prelude::{SendMode, ServerTriggerExt, Signature, ToClients};

View File

@@ -1,39 +0,0 @@
use super::UiHeadState;
use bevy::prelude::*;
pub static BACKPACK_HEAD_SLOTS: usize = 5;
#[derive(Component, Default)]
pub struct BackpackMarker;
#[derive(Component, Default)]
pub struct BackpackCountText;
#[derive(Component, Default)]
pub struct HeadSelector(pub usize);
#[derive(Component, Default)]
pub struct HeadImage(pub usize);
#[derive(Component, Default)]
pub struct HeadDamage(pub usize);
#[derive(Component, Default, Debug, Reflect)]
#[reflect(Component, Default)]
pub struct BackpackUiState {
pub heads: [Option<UiHeadState>; 5],
pub scroll: usize,
pub count: usize,
pub current_slot: usize,
pub open: bool,
}
impl BackpackUiState {
pub fn relative_current_slot(&self) -> usize {
self.current_slot.saturating_sub(self.scroll)
}
}
pub fn plugin(app: &mut App) {
app.register_type::<BackpackUiState>();
}

View File

@@ -6,13 +6,7 @@ use crate::{
heads_database::HeadsDatabase,
};
use bevy::prelude::*;
#[cfg(feature = "client")]
use bevy_replicon::prelude::ClientTriggerExt;
use serde::{Deserialize, Serialize};
pub use ui_head_state::UiHeadState;
pub mod backpack_ui;
pub mod ui_head_state;
#[derive(Component, Default, Reflect, Serialize, Deserialize, PartialEq)]
#[reflect(Component)]
@@ -40,120 +34,15 @@ impl Backpack {
}
}
#[derive(Event, Serialize, Deserialize)]
#[derive(Event, Debug, Serialize, Deserialize)]
pub struct BackpackSwapEvent(pub usize);
pub fn plugin(app: &mut App) {
app.register_type::<Backpack>();
app.add_plugins(backpack_ui::plugin);
#[cfg(feature = "client")]
app.add_systems(FixedUpdate, (backpack_inputs, sync_on_change));
global_observer!(app, on_head_collect);
}
#[cfg(feature = "client")]
fn backpack_inputs(
backpacks: Single<
(&Backpack, &mut backpack_ui::BackpackUiState),
With<crate::player::LocalPlayer>,
>,
mut backpack_inputs: MessageReader<crate::control::BackpackButtonPress>,
mut commands: Commands,
time: Res<Time>,
) {
use crate::{control::BackpackButtonPress, protocol::PlaySound};
let (backpack, mut state) = backpacks.into_inner();
for input in backpack_inputs.read() {
match input {
BackpackButtonPress::Toggle => {
if state.count == 0 {
return;
}
state.open = !state.open;
commands.trigger(PlaySound::Backpack { open: state.open });
}
BackpackButtonPress::Swap => {
if !state.open {
return;
}
commands.client_trigger(BackpackSwapEvent(state.current_slot));
}
BackpackButtonPress::Left => {
if !state.open {
return;
}
if state.current_slot > 0 {
state.current_slot -= 1;
commands.trigger(PlaySound::Selection);
sync_backpack_ui(backpack, &mut state, time.elapsed_secs());
}
}
BackpackButtonPress::Right => {
if !state.open {
return;
}
if state.current_slot < state.count.saturating_sub(1) {
state.current_slot += 1;
commands.trigger(PlaySound::Selection);
sync_backpack_ui(backpack, &mut state, time.elapsed_secs());
}
}
}
}
}
#[cfg(feature = "client")]
fn sync_on_change(
backpack: Query<Ref<Backpack>>,
mut state: Single<&mut backpack_ui::BackpackUiState>,
time: Res<Time>,
) {
for backpack in backpack.iter() {
if backpack.is_changed() || backpack.reloading() {
sync_backpack_ui(&backpack, &mut state, time.elapsed_secs());
}
}
}
#[cfg(feature = "client")]
fn sync_backpack_ui(backpack: &Backpack, state: &mut backpack_ui::BackpackUiState, time: f32) {
use crate::backpack::backpack_ui::BACKPACK_HEAD_SLOTS;
state.count = backpack.heads.len();
state.scroll = state
.scroll
.min(state.count.saturating_sub(BACKPACK_HEAD_SLOTS));
if state.current_slot >= state.scroll + BACKPACK_HEAD_SLOTS {
state.scroll = state.current_slot.saturating_sub(BACKPACK_HEAD_SLOTS - 1);
}
if state.current_slot < state.scroll {
state.scroll = state.current_slot;
}
for i in 0..BACKPACK_HEAD_SLOTS {
if let Some(head) = backpack.heads.get(i + state.scroll) {
use crate::backpack::ui_head_state::UiHeadState;
state.heads[i] = Some(UiHeadState::new(*head, time));
} else {
state.heads[i] = None;
}
}
}
fn on_head_collect(
trigger: On<HeadCollected>,
mut cmds: Commands,
@@ -165,7 +54,7 @@ fn on_head_collect(
let (mut backpack, active_heads) = query.get_mut(entity)?;
if backpack.contains(head) || active_heads.contains(head) {
cmds.trigger(CashCollectEvent);
cmds.trigger(CashCollectEvent { entity });
} else {
backpack.insert(head, heads_db.as_ref());
}

View File

@@ -1,40 +0,0 @@
use crate::heads::HeadState;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Default, Serialize, Deserialize)]
pub struct UiHeadState {
pub head: usize,
pub health: f32,
pub ammo: f32,
pub reloading: Option<f32>,
}
impl UiHeadState {
pub fn damage(&self) -> f32 {
1. - self.health
}
pub fn ammo_used(&self) -> f32 {
1. - self.ammo
}
pub fn reloading(&self) -> Option<f32> {
self.reloading
}
pub fn new(value: HeadState, time: f32) -> Self {
let reloading = if value.has_ammo() {
None
} else {
Some((time - value.last_use) / value.reload_duration)
};
Self {
head: value.head,
ammo: value.ammo as f32 / value.ammo_max as f32,
health: value.health as f32 / value.health_max as f32,
reloading,
}
}
}

View File

@@ -1,19 +1,3 @@
use crate::GameState;
#[cfg(feature = "client")]
use crate::control::Inputs;
use crate::control::ViewMode;
#[cfg(feature = "client")]
use crate::physics_layers::GameLayer;
#[cfg(feature = "client")]
use crate::player::LocalPlayer;
#[cfg(feature = "client")]
use crate::{control::LookDirMovement, loading_assets::UIAssets};
#[cfg(feature = "client")]
use avian3d::prelude::SpatialQuery;
#[cfg(feature = "client")]
use avian3d::prelude::{
Collider, LayerMask, PhysicsLayer as _, ShapeCastConfig, SpatialQueryFilter,
};
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
@@ -22,183 +6,3 @@ pub struct CameraTarget;
#[derive(Component, Reflect, Debug, Serialize, Deserialize, PartialEq)]
pub struct CameraArmRotation;
/// Requested camera rotation based on various input sources (keyboard, gamepad)
#[derive(Component, Reflect, Debug, Default, Deref, DerefMut)]
#[reflect(Component)]
pub struct CameraRotationInput(pub Vec2);
#[derive(Resource, Reflect, Debug, Default)]
#[reflect(Resource)]
pub struct CameraState {
pub cutscene: bool,
pub view_mode: ViewMode,
}
#[derive(Component, Reflect, Debug, Default)]
struct CameraUi;
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
pub struct MainCamera {
pub enabled: bool,
dir: Dir3,
distance: f32,
target_offset: Vec3,
}
impl MainCamera {
fn new(arm: Vec3) -> Self {
let (dir, distance) = Dir3::new_and_length(arm).expect("invalid arm length");
Self {
enabled: true,
dir,
distance,
target_offset: Vec3::new(0., 2., 0.),
}
}
}
pub fn plugin(app: &mut App) {
app.register_type::<CameraRotationInput>();
app.register_type::<CameraState>();
app.register_type::<MainCamera>();
app.init_resource::<CameraState>();
app.add_systems(OnEnter(GameState::Playing), startup);
#[cfg(feature = "client")]
app.add_systems(
PostUpdate,
(update, update_ui, update_look_around, rotate_view).run_if(in_state(GameState::Playing)),
);
}
fn startup(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
MainCamera::new(Vec3::new(0., 1.8, 15.)),
CameraRotationInput::default(),
));
}
#[cfg(feature = "client")]
fn update_look_around(
inputs: Single<&Inputs, With<LocalPlayer>>,
mut cam_state: ResMut<CameraState>,
) {
let view_mode = inputs.view_mode;
if view_mode != cam_state.view_mode {
cam_state.view_mode = view_mode;
}
}
#[cfg(feature = "client")]
fn update_ui(
mut commands: Commands,
cam_state: Res<CameraState>,
assets: Res<UIAssets>,
query: Query<Entity, With<CameraUi>>,
) {
if cam_state.is_changed() {
let show_free_cam_ui = cam_state.view_mode.is_free() || cam_state.cutscene;
if show_free_cam_ui {
commands.spawn((
CameraUi,
Node {
margin: UiRect::top(Val::Px(20.))
.with_left(Val::Auto)
.with_right(Val::Auto),
justify_content: JustifyContent::Center,
..default()
},
children![(
Node {
display: Display::Block,
position_type: PositionType::Absolute,
..default()
},
ImageNode::new(assets.camera.clone()),
)],
));
} else {
for entity in query.iter() {
commands.entity(entity).despawn();
}
}
}
}
#[cfg(feature = "client")]
fn update(
cam: Single<
(&MainCamera, &mut Transform, &CameraRotationInput),
(Without<CameraTarget>, Without<CameraArmRotation>),
>,
target_q: Single<
(&Transform, &Children),
(
With<CameraTarget>,
With<LocalPlayer>,
Without<CameraArmRotation>,
),
>,
arm_rotation: Query<&Transform, With<CameraArmRotation>>,
spatial_query: SpatialQuery,
cam_state: Res<CameraState>,
) {
if cam_state.cutscene {
return;
}
let (camera, mut cam_transform, cam_rotation_input) = cam.into_inner();
let (target_q, children) = target_q.into_inner();
let arm_tf = children
.iter()
.find_map(|child| arm_rotation.get(child).ok())
.unwrap();
if !camera.enabled {
return;
}
let target = target_q.translation + camera.target_offset;
let direction = arm_tf.rotation * Quat::from_rotation_y(cam_rotation_input.x) * camera.dir;
let max_distance = camera.distance;
let filter = SpatialQueryFilter::from_mask(LayerMask(GameLayer::Level.to_bits()));
let cam_pos = if let Some(first_hit) = spatial_query.cast_shape(
&Collider::sphere(0.5),
target,
Quat::IDENTITY,
direction,
&ShapeCastConfig::from_max_distance(max_distance),
&filter,
) {
let distance = first_hit.distance;
target + (direction * distance)
} else {
target + (direction * camera.distance)
};
*cam_transform = Transform::from_translation(cam_pos).looking_at(target, Vec3::Y);
}
#[cfg(feature = "client")]
fn rotate_view(
inputs: Single<&Inputs, With<LocalPlayer>>,
look_dir: Res<LookDirMovement>,
mut cam: Single<&mut CameraRotationInput>,
) {
if !inputs.view_mode.is_free() {
cam.x = 0.0;
return;
}
cam.0 += look_dir.0 * -0.001;
}

View File

@@ -1,12 +1,17 @@
use crate::{
GameState, HEDZ_GREEN, global_observer, loading_assets::UIAssets, protocol::PlaySound,
GameState, global_observer,
physics_layers::GameLayer,
player::Player,
protocol::{GltfSceneRoot, PlaySound, is_server},
server_observer,
tb_entities::CashSpawn,
};
use avian3d::prelude::Rotation;
use avian3d::prelude::*;
use bevy::prelude::*;
use bevy_replicon::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Component, Reflect, Default)]
#[derive(Component, Reflect, Default, Deserialize, Serialize)]
#[reflect(Component)]
#[require(Transform)]
pub struct Cash;
@@ -20,32 +25,64 @@ pub struct CashInventory {
pub cash: i32,
}
#[derive(Event)]
pub struct CashCollectEvent;
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(
Update,
(rotate, update_ui).run_if(in_state(GameState::Playing)),
);
server_observer!(app, on_cash_collect);
#[derive(EntityEvent)]
pub struct CashCollectEvent {
pub entity: Entity,
}
fn on_cash_collect(
_trigger: On<CashCollectEvent>,
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), setup.run_if(is_server));
app.add_systems(Update, rotate.run_if(in_state(GameState::Playing)));
server_observer!(app, on_cash_collected);
}
fn setup(mut commands: Commands, query: Query<Entity, With<CashSpawn>>) {
for entity in query.iter() {
commands
.entity(entity)
.insert((
Name::new("cash"),
GltfSceneRoot::Cash,
Cash,
Collider::cuboid(2., 3.0, 2.),
CollisionLayers::new(GameLayer::CollectibleSensors, LayerMask::ALL),
RigidBody::Kinematic,
CollisionEventsEnabled,
Sensor,
Replicated,
))
.observe(on_cash_collision);
}
}
fn on_cash_collected(
trigger: On<CashCollectEvent>,
mut commands: Commands,
mut cash: Single<&mut CashInventory>,
mut query_player: Query<&mut CashInventory, With<Player>>,
) {
use bevy_replicon::prelude::{SendMode, ServerTriggerExt, ToClients};
if let Ok(mut cash) = query_player.get_mut(trigger.entity) {
commands.server_trigger(ToClients {
mode: SendMode::Broadcast,
message: PlaySound::CashCollect,
});
commands.server_trigger(ToClients {
mode: SendMode::Broadcast,
message: PlaySound::CashCollect,
});
cash.cash += 100;
}
}
cash.cash += 100;
fn on_cash_collision(
trigger: On<CollisionStart>,
mut commands: Commands,
query_player: Query<&Player>,
) {
let collectable = trigger.event().collider1;
let collider = trigger.event().collider2;
if query_player.contains(collider) {
commands.trigger(CashCollectEvent { entity: collider });
commands.entity(collectable).despawn();
}
}
fn rotate(time: Res<Time>, mut query: Query<&mut Rotation, With<Cash>>) {
@@ -55,37 +92,3 @@ fn rotate(time: Res<Time>, mut query: Query<&mut Rotation, With<Cash>>) {
.mul_quat(Quat::from_rotation_y(time.delta_secs()));
}
}
fn update_ui(
cash: Single<&CashInventory, Changed<CashInventory>>,
text: Query<Entity, With<CashText>>,
mut writer: TextUiWriter,
) {
let Some(text) = text.iter().next() else {
return;
};
*writer.text(text, 0) = cash.cash.to_string();
}
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
commands.spawn((
Name::new("cash-ui"),
Text::new("0"),
TextShadow::default(),
CashText,
TextFont {
font: assets.font.clone(),
font_size: 34.0,
..default()
},
TextColor(HEDZ_GREEN.into()),
TextLayout::new_with_justify(Justify::Center),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(40.0),
left: Val::Px(100.0),
..default()
},
));
}

View File

@@ -1,6 +1,5 @@
use crate::{
GameState, aim::MarkerEvent, global_observer, loading_assets::UIAssets,
utils::billboards::Billboard,
GameState, aim::MarkerEvent, global_observer, loading_assets::UIAssets, utils::Billboard,
};
use bevy::prelude::*;
use bevy_sprite3d::Sprite3d;

View File

@@ -1,8 +1,8 @@
use crate::{
GameState,
aim::AimTarget,
backpack::UiHeadState,
heads::{ActiveHeads, HeadsImages},
client::ui::{HeadsImages, UiHeadState},
heads::ActiveHeads,
hitpoints::Hitpoints,
loading_assets::UIAssets,
npc::Npc,

View File

@@ -0,0 +1,98 @@
use crate::{
backpack::{Backpack, BackpackSwapEvent},
client::ui::{BACKPACK_HEAD_SLOTS, BackpackUiState, UiHeadState},
control::BackpackButtonPress,
player::LocalPlayer,
protocol::PlaySound,
};
use bevy::prelude::*;
use bevy_replicon::prelude::ClientTriggerExt;
pub fn plugin(app: &mut App) {
app.add_systems(FixedUpdate, (backpack_inputs, sync_on_change));
}
fn backpack_inputs(
backpack: Single<&Backpack, With<LocalPlayer>>,
mut state: ResMut<BackpackUiState>,
mut backpack_inputs: MessageReader<crate::control::BackpackButtonPress>,
mut commands: Commands,
time: Res<Time>,
) {
for input in backpack_inputs.read() {
match input {
BackpackButtonPress::Toggle => {
if state.count == 0 {
return;
}
state.open = !state.open;
commands.trigger(PlaySound::Backpack { open: state.open });
}
BackpackButtonPress::Swap => {
if !state.open {
return;
}
commands.client_trigger(BackpackSwapEvent(state.current_slot));
}
BackpackButtonPress::Left => {
if !state.open {
return;
}
if state.current_slot > 0 {
state.current_slot -= 1;
commands.trigger(PlaySound::Selection);
sync_backpack_ui(&backpack, &mut state, time.elapsed_secs());
}
}
BackpackButtonPress::Right => {
if !state.open {
return;
}
if state.current_slot < state.count.saturating_sub(1) {
state.current_slot += 1;
commands.trigger(PlaySound::Selection);
sync_backpack_ui(&backpack, &mut state, time.elapsed_secs());
}
}
}
}
}
fn sync_on_change(
backpack: Single<Ref<Backpack>, With<LocalPlayer>>,
mut state: ResMut<BackpackUiState>,
time: Res<Time>,
) {
if backpack.is_changed() || backpack.reloading() {
sync_backpack_ui(&backpack, &mut state, time.elapsed_secs());
}
}
fn sync_backpack_ui(backpack: &Backpack, state: &mut BackpackUiState, time: f32) {
state.count = backpack.heads.len();
state.scroll = state
.scroll
.min(state.count.saturating_sub(BACKPACK_HEAD_SLOTS));
if state.current_slot >= state.scroll + BACKPACK_HEAD_SLOTS {
state.scroll = state.current_slot.saturating_sub(BACKPACK_HEAD_SLOTS - 1);
}
if state.current_slot < state.scroll {
state.scroll = state.current_slot;
}
for i in 0..BACKPACK_HEAD_SLOTS {
if let Some(head) = backpack.heads.get(i + state.scroll) {
state.heads[i] = Some(UiHeadState::new(*head, time));
} else {
state.heads[i] = None;
}
}
}

View File

@@ -1,7 +0,0 @@
pub mod backpack_ui;
use bevy::prelude::*;
pub fn plugin(app: &mut App) {
app.add_plugins(backpack_ui::plugin);
}

View File

@@ -0,0 +1,192 @@
use crate::{
GameState,
camera::{CameraArmRotation, CameraTarget},
control::{Inputs, LookDirMovement, ViewMode},
loading_assets::UIAssets,
physics_layers::GameLayer,
player::LocalPlayer,
};
use avian3d::prelude::{
Collider, LayerMask, PhysicsLayer as _, ShapeCastConfig, SpatialQuery, SpatialQueryFilter,
};
use bevy::prelude::*;
/// Requested camera rotation based on various input sources (keyboard, gamepad)
#[derive(Component, Reflect, Debug, Default, Deref, DerefMut)]
#[reflect(Component)]
pub struct CameraRotationInput(pub Vec2);
#[derive(Resource, Reflect, Debug, Default)]
#[reflect(Resource)]
pub struct CameraState {
pub cutscene: bool,
pub view_mode: ViewMode,
}
#[derive(Component, Reflect, Debug, Default)]
struct CameraUi;
#[derive(Component, Reflect, Debug)]
#[reflect(Component)]
pub struct MainCamera {
pub enabled: bool,
dir: Dir3,
distance: f32,
target_offset: Vec3,
}
impl MainCamera {
fn new(arm: Vec3) -> Self {
let (dir, distance) = Dir3::new_and_length(arm).expect("invalid arm length");
Self {
enabled: true,
dir,
distance,
target_offset: Vec3::new(0., 2., 0.),
}
}
}
pub fn plugin(app: &mut App) {
app.register_type::<CameraRotationInput>();
app.register_type::<CameraState>();
app.register_type::<MainCamera>();
app.init_resource::<CameraState>();
app.add_systems(OnEnter(GameState::Playing), startup);
app.add_systems(
PostUpdate,
(update, update_ui, update_look_around, rotate_view).run_if(in_state(GameState::Playing)),
);
}
fn startup(mut commands: Commands) {
commands.spawn((
Camera3d::default(),
MainCamera::new(Vec3::new(0., 1.8, 15.)),
CameraRotationInput::default(),
));
}
#[cfg(feature = "client")]
fn update_look_around(
inputs: Single<&Inputs, With<LocalPlayer>>,
mut cam_state: ResMut<CameraState>,
) {
let view_mode = inputs.view_mode;
if view_mode != cam_state.view_mode {
cam_state.view_mode = view_mode;
}
}
#[cfg(feature = "client")]
fn update_ui(
mut commands: Commands,
cam_state: Res<CameraState>,
assets: Res<UIAssets>,
query: Query<Entity, With<CameraUi>>,
) {
if cam_state.is_changed() {
let show_free_cam_ui = cam_state.view_mode.is_free() || cam_state.cutscene;
if show_free_cam_ui {
commands.spawn((
CameraUi,
Node {
margin: UiRect::top(Val::Px(20.))
.with_left(Val::Auto)
.with_right(Val::Auto),
justify_content: JustifyContent::Center,
..default()
},
children![(
Node {
display: Display::Block,
position_type: PositionType::Absolute,
..default()
},
ImageNode::new(assets.camera.clone()),
)],
));
} else {
for entity in query.iter() {
commands.entity(entity).despawn();
}
}
}
}
fn update(
cam: Single<
(&MainCamera, &mut Transform, &CameraRotationInput),
(Without<CameraTarget>, Without<CameraArmRotation>),
>,
target_q: Single<
(&Transform, &Children),
(
With<CameraTarget>,
With<LocalPlayer>,
Without<CameraArmRotation>,
),
>,
arm_rotation: Query<&Transform, With<CameraArmRotation>>,
spatial_query: SpatialQuery,
cam_state: Res<CameraState>,
) {
if cam_state.cutscene {
return;
}
let (camera, mut cam_transform, cam_rotation_input) = cam.into_inner();
let (target_q, children) = target_q.into_inner();
let arm_tf = children
.iter()
.find_map(|child| arm_rotation.get(child).ok())
.unwrap();
if !camera.enabled {
return;
}
let target = target_q.translation + camera.target_offset;
let direction = arm_tf.rotation * Quat::from_rotation_y(cam_rotation_input.x) * camera.dir;
let max_distance = camera.distance;
let filter = SpatialQueryFilter::from_mask(LayerMask(GameLayer::Level.to_bits()));
let cam_pos = if let Some(first_hit) = spatial_query.cast_shape(
&Collider::sphere(0.5),
target,
Quat::IDENTITY,
direction,
&ShapeCastConfig::from_max_distance(max_distance),
&filter,
) {
let distance = first_hit.distance;
target + (direction * distance)
} else {
target + (direction * camera.distance)
};
*cam_transform = Transform::from_translation(cam_pos).looking_at(target, Vec3::Y);
}
#[cfg(feature = "client")]
fn rotate_view(
inputs: Single<&Inputs, With<LocalPlayer>>,
look_dir: Res<LookDirMovement>,
mut cam: Single<&mut CameraRotationInput>,
) {
if !inputs.view_mode.is_free() {
cam.x = 0.0;
return;
}
cam.0 += look_dir.0 * -0.001;
}

View File

@@ -26,13 +26,13 @@ fn rotate_rig(
return;
}
let (local_player_childer, selected_controller) = *local_player;
let (local_player_children, selected_controller) = *local_player;
if !matches!(selected_controller, SelectedController::Flying) {
return;
}
local_player_childer.iter().find(|&child| {
local_player_children.iter().find(|&child| {
if let Ok(mut rig_transform) = player_mesh.get_mut(child) {
let look_dir = look_dir.0;

View File

@@ -1,4 +1,8 @@
use crate::{GameState, control::ControllerSet};
use crate::{
GameState,
control::{ControllerSet, Inputs},
player::{LocalPlayer, Player, PlayerBodyMesh},
};
use bevy::prelude::*;
use bevy_replicon::client::ClientSystems;
@@ -22,4 +26,22 @@ pub fn plugin(app: &mut App) {
.before(ClientSystems::Receive)
.run_if(in_state(GameState::Playing)),
);
app.add_systems(
FixedUpdate,
rotate_others.run_if(in_state(GameState::Playing)),
);
}
fn rotate_others(
players: Query<(&Inputs, &Children), (With<Player>, Without<LocalPlayer>)>,
mut rig: Query<(&mut Transform, &PlayerBodyMesh)>,
) {
for (input, children) in players.iter() {
for child in children.iter() {
if let Ok((mut rig, _)) = rig.get_mut(child) {
*rig = rig.looking_to(input.look_dir, Vec3::Y);
}
}
}
}

View File

@@ -0,0 +1,104 @@
use crate::{
GameState,
client::camera::{CameraState, MainCamera},
cutscene::StartCutscene,
global_observer,
tb_entities::{CameraTarget, CutsceneCamera, CutsceneCameraMovementEnd},
};
use bevy::prelude::*;
use bevy_trenchbroom::prelude::*;
#[derive(Resource, Debug, Default)]
enum CutsceneState {
#[default]
None,
Playing {
timer: Timer,
camera_start: Transform,
camera_end: Transform,
},
}
pub fn plugin(app: &mut App) {
app.init_resource::<CutsceneState>();
app.add_systems(Update, update.run_if(in_state(GameState::Playing)));
global_observer!(app, on_start_cutscene);
}
fn on_start_cutscene(
trigger: On<StartCutscene>,
mut cam_state: ResMut<CameraState>,
mut cutscene_state: ResMut<CutsceneState>,
cutscenes: Query<(&Transform, &CutsceneCamera, &Target), Without<MainCamera>>,
cutscene_movement: Query<
(&Transform, &CutsceneCameraMovementEnd, &Target),
Without<MainCamera>,
>,
cam_target: Query<(&Transform, &CameraTarget), Without<MainCamera>>,
) {
let cutscene = trigger.event().0.clone();
cam_state.cutscene = true;
// asumes `name` and `targetname` are equal
let Some((t, _, target)) = cutscenes
.iter()
.find(|(_, cutscene_camera, _)| cutscene == cutscene_camera.name)
else {
return;
};
let move_end = cutscene_movement
.iter()
.find(|(_, _, target)| cutscene == target.target.clone().unwrap_or_default())
.map(|(t, _, _)| *t)
.unwrap_or_else(|| *t);
let Some((target, _)) = cam_target.iter().find(|(_, camera_target)| {
camera_target.targetname == target.target.clone().unwrap_or_default()
}) else {
return;
};
*cutscene_state = CutsceneState::Playing {
timer: Timer::from_seconds(2.0, TimerMode::Once),
camera_start: t.looking_at(target.translation, Vec3::Y),
camera_end: move_end.looking_at(target.translation, Vec3::Y),
};
}
fn update(
mut cam_state: ResMut<CameraState>,
mut cutscene_state: ResMut<CutsceneState>,
mut cam: Query<&mut Transform, With<MainCamera>>,
time: Res<Time>,
) {
if let CutsceneState::Playing {
timer,
camera_start,
camera_end,
} = &mut *cutscene_state
{
cam_state.cutscene = true;
timer.tick(time.delta());
let t = Transform::from_translation(
camera_start
.translation
.lerp(camera_end.translation, timer.fraction()),
)
.with_rotation(
camera_start
.rotation
.lerp(camera_end.rotation, timer.fraction()),
);
let _ = cam.single_mut().map(|mut cam| *cam = t);
if timer.is_finished() {
cam_state.cutscene = false;
*cutscene_state = CutsceneState::None;
}
}
}

View File

@@ -2,7 +2,7 @@ use crate::{
GameState,
abilities::Healing,
loading_assets::{AudioAssets, GameAssets},
utils::{billboards::Billboard, observers::global_observer},
utils::{Billboard, observers::global_observer},
};
use bevy::prelude::*;
use rand::{Rng, thread_rng};

View File

@@ -24,8 +24,10 @@ use bevy_trenchbroom::geometry::Brushes;
pub mod aim;
pub mod audio;
pub mod backpack;
mod backpack;
pub mod camera;
pub mod control;
pub mod cutscene;
pub mod debug;
pub mod enemy;
pub mod heal_effect;
@@ -34,12 +36,12 @@ mod settings;
pub mod setup;
pub mod steam;
pub mod ui;
mod utils;
pub fn plugin(app: &mut App) {
app.add_plugins((
aim::plugin,
audio::plugin,
backpack::plugin,
control::plugin,
debug::plugin,
enemy::plugin,
@@ -49,6 +51,10 @@ pub fn plugin(app: &mut App) {
steam::plugin,
ui::plugin,
settings::plugin,
backpack::plugin,
camera::plugin,
utils::billboards::plugin,
cutscene::plugin,
));
app.add_systems(

View File

@@ -1,4 +1,4 @@
use crate::{DebugVisuals, camera::MainCamera};
use crate::{DebugVisuals, client::camera::MainCamera};
use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*, render::view::ColorGrading};
use bevy_trenchbroom::TrenchBroomServer;

View File

@@ -1,15 +1,47 @@
use crate::{
GameState, HEDZ_GREEN,
backpack::backpack_ui::{
BACKPACK_HEAD_SLOTS, BackpackCountText, BackpackMarker, BackpackUiState, HeadDamage,
HeadImage, HeadSelector,
},
heads::HeadsImages,
client::ui::heads_ui::{HeadsImages, UiHeadState},
loading_assets::UIAssets,
};
use bevy::{ecs::spawn::SpawnIter, prelude::*};
pub static BACKPACK_HEAD_SLOTS: usize = 5;
#[derive(Component, Default)]
pub struct BackpackMarker;
#[derive(Component, Default)]
pub struct BackpackCountText;
#[derive(Component, Default)]
pub struct HeadSelector(pub usize);
#[derive(Component, Default)]
pub struct HeadImage(pub usize);
#[derive(Component, Default)]
pub struct HeadDamage(pub usize);
#[derive(Resource, Default, Debug, Reflect)]
#[reflect(Resource)]
pub struct BackpackUiState {
pub heads: [Option<UiHeadState>; 5],
pub scroll: usize,
pub count: usize,
pub current_slot: usize,
pub open: bool,
}
impl BackpackUiState {
pub fn relative_current_slot(&self) -> usize {
self.current_slot.saturating_sub(self.scroll)
}
}
pub fn plugin(app: &mut App) {
app.register_type::<BackpackUiState>();
app.init_resource::<BackpackUiState>();
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(
FixedUpdate,
@@ -152,10 +184,14 @@ fn spawn_head_ui(
}
fn update_visibility(
state: Single<&BackpackUiState, Changed<BackpackUiState>>,
state: Res<BackpackUiState>,
mut backpack: Single<&mut Visibility, (With<BackpackMarker>, Without<BackpackCountText>)>,
mut count: Single<&mut Visibility, (Without<BackpackMarker>, With<BackpackCountText>)>,
) {
if !state.is_changed() {
return;
}
**backpack = if state.open {
Visibility::Visible
} else {
@@ -170,10 +206,14 @@ fn update_visibility(
}
fn update_count(
state: Single<&BackpackUiState, Changed<BackpackUiState>>,
state: Res<BackpackUiState>,
text: Option<Single<Entity, With<BackpackCountText>>>,
mut writer: TextUiWriter,
) {
if !state.is_changed() {
return;
}
let Some(text) = text else {
return;
};
@@ -182,12 +222,16 @@ fn update_count(
}
fn update(
state: Single<&BackpackUiState, Changed<BackpackUiState>>,
state: Res<BackpackUiState>,
heads_images: Res<HeadsImages>,
mut head_image: Query<(&HeadImage, &mut Visibility, &mut ImageNode), Without<HeadSelector>>,
mut head_damage: Query<(&HeadDamage, &mut Node), Without<HeadSelector>>,
mut head_selector: Query<(&HeadSelector, &mut Visibility), Without<HeadImage>>,
) {
if !state.is_changed() {
return;
}
for (HeadImage(head), mut vis, mut image) in head_image.iter_mut() {
if let Some(head) = &state.heads[*head] {
*vis = Visibility::Inherited;

View File

@@ -0,0 +1,47 @@
use crate::{
GameState, HEDZ_GREEN, cash::CashInventory, loading_assets::UIAssets, player::LocalPlayer,
};
use bevy::prelude::*;
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
struct CashText;
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(Update, update_ui.run_if(in_state(GameState::Playing)));
}
fn update_ui(
cash: Single<&CashInventory, (Changed<CashInventory>, With<LocalPlayer>)>,
text: Query<Entity, With<CashText>>,
mut writer: TextUiWriter,
) {
let Some(text) = text.iter().next() else {
return;
};
*writer.text(text, 0) = cash.cash.to_string();
}
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
commands.spawn((
Name::new("cash-ui"),
Text::new("0"),
TextShadow::default(),
CashText,
TextFont {
font: assets.font.clone(),
font_size: 34.0,
..default()
},
TextColor(HEDZ_GREEN.into()),
TextLayout::new_with_justify(Justify::Center),
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(40.0),
left: Val::Px(100.0),
..default()
},
));
}

View File

@@ -1,14 +1,19 @@
use super::{ActiveHeads, HEAD_SLOTS};
#[cfg(feature = "client")]
use crate::heads::HeadsImages;
use crate::{
GameState, backpack::UiHeadState, loading_assets::UIAssets, player::LocalPlayer,
protocol::is_server,
GameState,
heads::{ActiveHeads, HEAD_COUNT, HEAD_SLOTS, HeadState},
heads_database::HeadsDatabase,
loading_assets::UIAssets,
player::LocalPlayer,
};
use bevy::{ecs::spawn::SpawnIter, prelude::*};
use serde::{Deserialize, Serialize};
use std::f32::consts::PI;
#[derive(Resource, Default)]
pub struct HeadsImages {
pub heads: Vec<Handle<Image>>,
}
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
struct HeadSelector(pub usize);
@@ -21,29 +26,78 @@ struct HeadImage(pub usize);
#[reflect(Component)]
struct HeadDamage(pub usize);
#[derive(Component, Default, Reflect, Serialize, Deserialize, PartialEq)]
#[reflect(Component)]
pub struct UiActiveHeads {
#[derive(Resource, Default, Reflect, Serialize, Deserialize, PartialEq)]
#[reflect(Resource)]
struct UiActiveHeads {
heads: [Option<UiHeadState>; 5],
selected_slot: usize,
}
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Default, Serialize, Deserialize)]
pub struct UiHeadState {
pub head: usize,
pub health: f32,
pub ammo: f32,
pub reloading: Option<f32>,
}
impl UiHeadState {
pub fn damage(&self) -> f32 {
1. - self.health
}
pub fn ammo_used(&self) -> f32 {
1. - self.ammo
}
pub fn reloading(&self) -> Option<f32> {
self.reloading
}
pub fn new(value: HeadState, time: f32) -> Self {
let reloading = if value.has_ammo() {
None
} else {
Some((time - value.last_use) / value.reload_duration)
};
Self {
head: value.head,
ammo: value.ammo as f32 / value.ammo_max as f32,
health: value.health as f32 / value.health_max as f32,
reloading,
}
}
}
pub fn plugin(app: &mut App) {
app.register_type::<HeadDamage>();
app.register_type::<UiActiveHeads>();
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(
FixedUpdate,
sync.run_if(in_state(GameState::Playing).and(is_server)),
);
#[cfg(feature = "client")]
app.init_resource::<UiActiveHeads>();
app.add_systems(OnEnter(GameState::Playing), (setup, setup_heads_images));
app.add_systems(FixedUpdate, sync.run_if(in_state(GameState::Playing)));
app.add_systems(
FixedUpdate,
(update, update_ammo, update_health).run_if(in_state(GameState::Playing)),
);
}
fn setup_heads_images(
mut commands: Commands,
asset_server: Res<AssetServer>,
heads: Res<HeadsDatabase>,
) {
// TODO: load via asset loader
let heads = (0usize..HEAD_COUNT)
.map(|i| asset_server.load(format!("ui/heads/{}.png", heads.head_key(i))))
.collect();
commands.insert_resource(HeadsImages { heads });
}
fn setup(mut commands: Commands, assets: Res<UIAssets>) {
commands.spawn((
Name::new("heads-ui"),
@@ -177,7 +231,7 @@ fn spawn_head_ui(
#[cfg(feature = "client")]
fn update(
res: Single<&UiActiveHeads>,
res: Res<UiActiveHeads>,
heads_images: Res<HeadsImages>,
mut head_image: Query<(&HeadImage, &mut Visibility, &mut ImageNode), Without<HeadSelector>>,
mut head_selector: Query<(&HeadSelector, &mut Visibility), Without<HeadImage>>,
@@ -201,10 +255,14 @@ fn update(
#[cfg(feature = "client")]
fn update_ammo(
res: Single<&UiActiveHeads, Changed<UiActiveHeads>>,
res: Res<UiActiveHeads>,
heads: Query<&HeadImage>,
mut gradients: Query<(&mut BackgroundGradient, &ChildOf)>,
) {
if !res.is_changed() {
return;
}
for (mut gradient, child_of) in gradients.iter_mut() {
let Ok(HeadImage(head)) = heads.get(child_of.parent()) else {
continue;
@@ -230,22 +288,22 @@ fn update_ammo(
}
#[cfg(feature = "client")]
fn update_health(
res: Single<&UiActiveHeads, Changed<UiActiveHeads>>,
mut query: Query<(&mut Node, &HeadDamage)>,
) {
for (mut node, HeadDamage(head)) in query.iter_mut() {
node.height = Val::Percent(res.heads[*head].map(|head| head.damage()).unwrap_or(0.) * 100.);
fn update_health(res: Res<UiActiveHeads>, mut query: Query<(&mut Node, &HeadDamage)>) {
if res.is_changed() {
for (mut node, HeadDamage(head)) in query.iter_mut() {
node.height =
Val::Percent(res.heads[*head].map(|head| head.damage()).unwrap_or(0.) * 100.);
}
}
}
fn sync(
active_heads: Single<Ref<ActiveHeads>, With<LocalPlayer>>,
mut state: Single<&mut UiActiveHeads>,
mut state: ResMut<UiActiveHeads>,
time: Res<Time>,
) {
if active_heads.is_changed() || active_heads.reloading() {
state.selected_slot = active_heads.selected_slot;
state.selected_slot = active_heads.slot();
for i in 0..HEAD_SLOTS {
state.heads[i] = active_heads

View File

@@ -1,7 +1,15 @@
mod backpack_ui;
mod cash_ui;
mod heads_ui;
mod pause;
pub use backpack_ui::{BACKPACK_HEAD_SLOTS, BackpackUiState};
use bevy::prelude::*;
pub use heads_ui::{HeadsImages, UiHeadState};
pub fn plugin(app: &mut App) {
app.add_plugins(heads_ui::plugin);
app.add_plugins(backpack_ui::plugin);
app.add_plugins(pause::plugin);
app.add_plugins(cash_ui::plugin);
}

View File

@@ -1,22 +1,12 @@
use crate::camera::MainCamera;
use crate::{client::camera::MainCamera, utils::Billboard};
use bevy::prelude::*;
use bevy_sprite3d::Sprite3dPlugin;
use serde::{Deserialize, Serialize};
#[derive(Component, Reflect, Default, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component)]
pub enum Billboard {
#[default]
All,
XZ,
}
pub fn plugin(app: &mut App) {
if !app.is_plugin_added::<Sprite3dPlugin>() {
app.add_plugins(Sprite3dPlugin);
}
app.register_type::<Billboard>();
app.add_systems(Update, (face_camera, face_camera_no_parent));
}

View File

@@ -0,0 +1 @@
pub mod billboards;

View File

@@ -1,107 +1,5 @@
use crate::{
GameState,
camera::{CameraState, MainCamera},
global_observer,
tb_entities::{CameraTarget, CutsceneCamera, CutsceneCameraMovementEnd},
};
use bevy::prelude::*;
use bevy_trenchbroom::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Event, Serialize, Deserialize)]
pub struct StartCutscene(pub String);
#[derive(Resource, Debug, Default)]
enum CutsceneState {
#[default]
None,
Playing {
timer: Timer,
camera_start: Transform,
camera_end: Transform,
},
}
pub fn plugin(app: &mut App) {
app.init_resource::<CutsceneState>();
app.add_systems(Update, update.run_if(in_state(GameState::Playing)));
global_observer!(app, on_start_cutscene);
}
fn on_start_cutscene(
trigger: On<StartCutscene>,
mut cam_state: ResMut<CameraState>,
mut cutscene_state: ResMut<CutsceneState>,
cutscenes: Query<(&Transform, &CutsceneCamera, &Target), Without<MainCamera>>,
cutscene_movement: Query<
(&Transform, &CutsceneCameraMovementEnd, &Target),
Without<MainCamera>,
>,
cam_target: Query<(&Transform, &CameraTarget), Without<MainCamera>>,
) {
let cutscene = trigger.event().0.clone();
cam_state.cutscene = true;
// asumes `name` and `targetname` are equal
let Some((t, _, target)) = cutscenes
.iter()
.find(|(_, cutscene_camera, _)| cutscene == cutscene_camera.name)
else {
return;
};
let move_end = cutscene_movement
.iter()
.find(|(_, _, target)| cutscene == target.target.clone().unwrap_or_default())
.map(|(t, _, _)| *t)
.unwrap_or_else(|| *t);
let Some((target, _)) = cam_target.iter().find(|(_, camera_target)| {
camera_target.targetname == target.target.clone().unwrap_or_default()
}) else {
return;
};
*cutscene_state = CutsceneState::Playing {
timer: Timer::from_seconds(2.0, TimerMode::Once),
camera_start: t.looking_at(target.translation, Vec3::Y),
camera_end: move_end.looking_at(target.translation, Vec3::Y),
};
}
fn update(
mut cam_state: ResMut<CameraState>,
mut cutscene_state: ResMut<CutsceneState>,
mut cam: Query<&mut Transform, With<MainCamera>>,
time: Res<Time>,
) {
if let CutsceneState::Playing {
timer,
camera_start,
camera_end,
} = &mut *cutscene_state
{
cam_state.cutscene = true;
timer.tick(time.delta());
let t = Transform::from_translation(
camera_start
.translation
.lerp(camera_end.translation, timer.fraction()),
)
.with_rotation(
camera_start
.rotation
.lerp(camera_end.rotation, timer.fraction()),
);
let _ = cam.single_mut().map(|mut cam| *cam = t);
if timer.is_finished() {
cam_state.cutscene = false;
*cutscene_state = CutsceneState::None;
}
}
}

View File

@@ -6,9 +6,7 @@ use crate::{
protocol::{GltfSceneRoot, NetworkEnv, PlaySound},
server_observer,
tb_entities::SecretHead,
utils::{
billboards::Billboard, one_shot_force::OneShotImpulse, squish_animation::SquishAnimation,
},
utils::{Billboard, one_shot_force::OneShotImpulse, squish_animation::SquishAnimation},
};
use avian3d::prelude::*;
use bevy::{ecs::relationship::RelatedSpawner, prelude::*};

View File

@@ -13,16 +13,9 @@ use bevy::prelude::*;
use bevy_replicon::prelude::FromClient;
use serde::{Deserialize, Serialize};
pub mod heads_ui;
pub static HEAD_COUNT: usize = 18;
pub static HEAD_SLOTS: usize = 5;
#[derive(Resource, Default)]
pub struct HeadsImages {
pub heads: Vec<Handle<Image>>,
}
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Serialize, Deserialize)]
pub struct HeadState {
pub head: usize,
@@ -74,6 +67,10 @@ impl ActiveHeads {
self.heads[self.current_slot]
}
pub fn slot(&self) -> usize {
self.current_slot
}
pub fn use_ammo(&mut self, time: f32) {
let Some(head) = &mut self.heads[self.current_slot] else {
error!("cannot use ammo of empty head");
@@ -184,11 +181,8 @@ pub struct HeadChanged {
}
pub fn plugin(app: &mut App) {
app.add_plugins(heads_ui::plugin);
app.register_type::<ActiveHeads>();
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_systems(
FixedUpdate,
(
@@ -201,15 +195,6 @@ pub fn plugin(app: &mut App) {
global_observer!(app, on_swap_backpack);
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, heads: Res<HeadsDatabase>) {
// TODO: load via asset loader
let heads = (0usize..HEAD_COUNT)
.map(|i| asset_server.load(format!("ui/heads/{}.png", heads.head_key(i))))
.collect();
commands.insert_resource(HeadsImages { heads });
}
fn sync_hp(mut query: Query<(&mut ActiveHeads, &Hitpoints)>) {
for (mut active_heads, hp) in query.iter_mut() {
if active_heads.hp().get() != hp.get() {
@@ -307,12 +292,15 @@ fn on_select_active_head(
fn on_swap_backpack(
trigger: On<FromClient<BackpackSwapEvent>>,
clients: ClientToController,
mut commands: Commands,
mut query: Query<(Entity, &mut ActiveHeads, &mut Hitpoints, &mut Backpack), With<Player>>,
) {
let player = clients.get_controller(trigger.client_id);
let backpack_slot = trigger.event().0;
let Ok((player, mut active_heads, mut hp, mut backpack)) = query.single_mut() else {
let Ok((player, mut active_heads, mut hp, mut backpack)) = query.get_mut(player) else {
return;
};

View File

@@ -1,11 +1,10 @@
use crate::{
billboards::Billboard,
global_observer,
physics_layers::GameLayer,
player::Player,
protocol::{GltfSceneRoot, PlaySound},
squish_animation::SquishAnimation,
utils::one_shot_force::OneShotImpulse,
utils::{Billboard, one_shot_force::OneShotImpulse},
};
use avian3d::prelude::*;
use bevy::prelude::*;

View File

@@ -52,7 +52,7 @@ use bevy_trenchbroom::{
TrenchBroomPlugins, config::TrenchBroomConfig, prelude::TrenchBroomPhysicsPlugin,
};
use bevy_trenchbroom_avian::AvianPhysicsBackend;
use utils::{billboards, squish_animation};
use utils::squish_animation;
pub const HEDZ_GREEN: Srgba = Srgba::rgb(0.0, 1.0, 0.0);
pub const HEDZ_PURPLE: Srgba = Srgba::rgb(91. / 256., 4. / 256., 138. / 256.);
@@ -119,16 +119,13 @@ pub fn plugin(app: &mut App) {
app.add_plugins(gates::plugin);
app.add_plugins(platforms::plugin);
app.add_plugins(movables::plugin);
app.add_plugins(utils::billboards::plugin);
app.add_plugins(aim::plugin);
app.add_plugins(npc::plugin);
app.add_plugins(keys::plugin);
app.add_plugins(utils::squish_animation::plugin);
app.add_plugins(camera::plugin);
#[cfg(feature = "client")]
app.add_plugins(client::plugin);
app.add_plugins(control::plugin);
app.add_plugins(cutscene::plugin);
app.add_plugins(backpack::plugin);
app.add_plugins(loading_assets::LoadingPlugin);
app.add_plugins(loading_map::plugin);

View File

@@ -12,7 +12,7 @@ use crate::{
loading_assets::GameAssets,
protocol::{PlaySound, is_server},
tb_entities::EnemySpawn,
utils::billboards::Billboard,
utils::Billboard,
};
use bevy::{light::NotShadowCaster, prelude::*};
use serde::{Deserialize, Serialize};

View File

@@ -1,22 +1,21 @@
use crate::{
GameState,
abilities::PlayerTriggerState,
backpack::{Backpack, backpack_ui::BackpackUiState},
backpack::Backpack,
camera::{CameraArmRotation, CameraTarget},
cash::{Cash, CashCollectEvent, CashInventory},
cash::CashInventory,
character::{AnimatedCharacter, HedzCharacter},
control::{Inputs, LocalInputs, controller_common::PlayerCharacterController},
global_observer,
head::ActiveHead,
head_drop::HeadDrops,
heads::{ActiveHeads, HeadChanged, HeadState, heads_ui::UiActiveHeads},
heads::{ActiveHeads, HeadChanged, HeadState},
heads_database::HeadsDatabase,
hitpoints::{Hitpoints, Kill},
npc::SpawnCharacter,
protocol::{ClientHeadChanged, OwnedByClient, PlaySound, PlayerId},
tb_entities::SpawnPoint,
};
use avian3d::prelude::*;
use bevy::{
input::common_conditions::input_just_pressed,
prelude::*,
@@ -24,6 +23,7 @@ use bevy::{
};
use bevy_replicon::prelude::{ClientId, Replicated, SendMode, ServerTriggerExt, ToClients};
use happy_feet::debug::DebugInput;
use rand::Rng;
use serde::{Deserialize, Serialize};
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
@@ -32,7 +32,7 @@ pub struct Player;
#[derive(Component, Debug, Reflect)]
#[reflect(Component)]
#[require(LocalInputs, BackpackUiState)]
#[require(LocalInputs)]
pub struct LocalPlayer;
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
@@ -52,7 +52,6 @@ pub fn plugin(app: &mut App) {
app.add_systems(
Update,
(
collect_cash,
setup_animations_marker_for_player,
toggle_cursor_system.run_if(input_just_pressed(KeyCode::Escape)),
)
@@ -71,7 +70,15 @@ pub fn spawn(
) -> Option<Entity> {
let spawn = query.iter().next()?;
let transform = Transform::from_translation(spawn.translation + Vec3::new(0., 3., 0.));
// This offset helps prevent players from getting stuck inside each other on spawn and causing a perpetual
// motion machine.
let random_offset = Vec3::new(
rand::thread_rng().gen_range(-0.01..0.01),
0.0,
rand::thread_rng().gen_range(-0.01..0.01),
);
let transform =
Transform::from_translation(spawn.translation + Vec3::new(0., 3., 0.) + random_offset);
let id = commands
.spawn((
@@ -95,8 +102,6 @@ pub fn spawn(
id,
),
Backpack::default(),
BackpackUiState::default(),
UiActiveHeads::default(),
Inputs::default(),
Replicated,
))
@@ -166,7 +171,7 @@ fn on_update_head_mesh(
animated_characters: Query<&AnimatedCharacter>,
mut active_head: Query<&mut ActiveHead>,
) -> Result {
let player_id = player_id.get(trigger.entity)?.clone();
let player_id = *(player_id.get(trigger.entity)?);
let player_body_mesh = children
.get(trigger.entity)?
@@ -226,33 +231,6 @@ fn toggle_cursor_system(mut window: Single<&mut CursorOptions, With<PrimaryWindo
toggle_grab_cursor(&mut window);
}
fn collect_cash(
mut commands: Commands,
mut collision_message_reader: MessageReader<CollisionStart>,
query_player: Query<&Player>,
query_cash: Query<&Cash>,
) {
for CollisionStart {
collider1: e1,
collider2: e2,
..
} in collision_message_reader.read()
{
let collect = if query_player.contains(*e1) && query_cash.contains(*e2) {
Some(*e2)
} else if query_player.contains(*e2) && query_cash.contains(*e1) {
Some(*e1)
} else {
None
};
if let Some(cash) = collect {
commands.trigger(CashCollectEvent);
commands.entity(cash).despawn();
}
}
}
fn setup_animations_marker_for_player(
mut commands: Commands,
animation_handles: Query<Entity, Added<AnimationGraphHandle>>,

View File

@@ -188,6 +188,7 @@ pub enum GltfSceneRoot {
Projectile(String),
HeadDrop(String),
Key,
Cash,
}
pub fn spawn_gltf_scene_roots(
@@ -219,6 +220,7 @@ pub fn spawn_gltf_scene_roots(
get_scene(gltf, 0)
}
GltfSceneRoot::Key => assets.mesh_key.clone(),
GltfSceneRoot::Cash => assets.mesh_cash.clone(),
};
commands

View File

@@ -1,8 +1,7 @@
use crate::protocol::PlayerId;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
use crate::protocol::PlayerId;
// TODO: remove in favour of client side change detection
#[derive(Clone, Event, Serialize, Deserialize, PartialEq)]
pub struct ClientHeadChanged {

View File

@@ -6,7 +6,7 @@ use crate::{
animation::AnimationFlags,
backpack::{Backpack, BackpackSwapEvent},
camera::{CameraArmRotation, CameraTarget},
cash::CashInventory,
cash::{Cash, CashInventory},
character::{AnimatedCharacter, HedzCharacter},
control::{
CashHealPressed, ClientInputs, ControllerSettings, Inputs, SelectLeftPressed,
@@ -16,15 +16,14 @@ use crate::{
cutscene::StartCutscene,
global_observer,
head::ActiveHead,
heads::{ActiveHeads, heads_ui::UiActiveHeads},
heads::ActiveHeads,
hitpoints::Hitpoints,
npc::Npc,
platforms::ActivePlatform,
player::{Player, PlayerBodyMesh},
tick::GameTick,
utils::{
auto_rotate::AutoRotation, billboards::Billboard, squish_animation::SquishAnimation,
trail::SpawnTrail,
Billboard, auto_rotate::AutoRotation, squish_animation::SquishAnimation, trail::SpawnTrail,
},
};
use avian3d::prelude::{
@@ -107,7 +106,7 @@ pub fn plugin(app: &mut App) {
.replicate::<SquishAnimation>()
.replicate_once::<Transform>()
.replicate_once::<SpawnTrail>()
.replicate::<UiActiveHeads>()
.replicate_once::<Cash>()
.replicate_as::<Visibility, SerVisibility>();
app.replicate_once::<ThrownProjectile>()

View File

@@ -1,6 +1,5 @@
use crate::{
GameState,
cash::Cash,
loading_assets::GameAssets,
physics_layers::GameLayer,
protocol::{
@@ -152,30 +151,8 @@ impl EnemySpawn {
#[point_class(base(Transform), model({ "path": "models/cash.glb" }))]
#[derive(Default)]
#[component(on_add = Self::on_add)]
pub struct CashSpawn {}
impl CashSpawn {
fn on_add(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
let Some(assets) = world.get_resource::<GameAssets>() else {
return;
};
let mesh = assets.mesh_cash.clone();
world.commands().entity(entity).insert((
Name::new("cash"),
SceneRoot(mesh),
Cash,
Collider::cuboid(2., 3.0, 2.),
CollisionLayers::new(GameLayer::CollectibleSensors, LayerMask::ALL),
RigidBody::Static,
CollisionEventsEnabled,
Sensor,
));
}
}
#[point_class(base(Transform), model({ "path": "models/head_drop.glb" }))]
#[derive(Default)]
pub struct SecretHead {

View File

@@ -1,5 +1,4 @@
pub mod auto_rotate;
pub mod billboards;
pub mod cooldown;
pub mod debounce;
pub mod explosions;
@@ -14,7 +13,18 @@ use bevy::prelude::*;
pub use cooldown::Cooldown;
pub use debounce::Debounce;
pub(crate) use observers::global_observer;
use serde::{Deserialize, Serialize};
#[derive(Component, Reflect, Default, PartialEq, Eq, Serialize, Deserialize)]
#[reflect(Component)]
pub enum Billboard {
#[default]
All,
XZ,
}
pub fn plugin(app: &mut App) {
app.register_type::<Billboard>();
app.add_plugins(one_shot_force::plugin);
}