From ae8026588b54576c060bbdcc564117063f337a4e Mon Sep 17 00:00:00 2001 From: extrawurst Date: Tue, 8 Apr 2025 10:51:46 +0200 Subject: [PATCH] support multiple thrown projectiles --- assets/models/head_misc/hammer.glb | Bin 0 -> 2928 bytes assets/models/head_misc/molotov_cocktail.glb | Bin 14864 -> 14864 bytes src/abilities/mod.rs | 4 ++ src/abilities/thrown.rs | 70 +++++++++++-------- src/ai/mod.rs | 1 + src/loading_assets.rs | 3 + src/movables.rs | 2 - 7 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 assets/models/head_misc/hammer.glb diff --git a/assets/models/head_misc/hammer.glb b/assets/models/head_misc/hammer.glb new file mode 100644 index 0000000000000000000000000000000000000000..1ac7c7198669c188f1f55e0d45f39904acf9812b GIT binary patch literal 2928 zcmb7ETW=dh6h18_EiLrMoff)GDNtCuv)-H664JHR032Kc_~R15_wCl^ znE6Q}QdS$Yz6eF^r%}vm?1%k03Zq2pV~X~8Ai|!AwY5hr?a(TlWy@tcI}~veL?MDJ zWzLRtmUNMT)p({QthO^|p+7_)Ys;9GCS~T+g)JO2tFh3`|xU`l*Nme=upP7mYdt(GGf| z$7*Rj64=V5&y5UM=G?&Q2c39Br2b$Kbhn~We?JrnGK^WrPed~sMDbIe#lwsN+|z#$B?0*VUf7pq#Yd}aHH21a9&^LsVe=BOi7vvDvC(%>)y_-Pskol#2W znElvluWhfjHsz2vTU#5e>#SzzZ2QSi%~oscyPr9$RqzsnuorYG#l&jaFfivxPSNjT zD2d|96g#86JrO?(#4nPx8x0SlP=x9Bivzqd+o(7?>qesxAD2}nwqNlcowDgvxy`v( zwG7XwdbV!pX4y4t*K<6}wOp@aRq3b!KCPY79DK>pOY<^PS(iO~(lqfo;w9z!!;_xX z-?H?||4FaRRL5D)R+mmW9T(}d>h0$0`sx;=yFP6{KW;hd&Wlv6i?E;KZ^m|U%;ae8 z?a3c9zMs^O`}CVOEziMARiijNSCXAK+pJpCl?}tDlbo}-VHMMD6OWQlH&5q~%^-Jh z1K$xoOHI>$TLE~ywu%32$MtNzJVU3r!YtD3IgUlT;-L6EUHM2Z(^Y(#tY`fw9Thvz()0^d|Wh5WhwD9kdRLQI`+s+PhO|D$o9*umsit^;!iN7cb zcZ{*3BpmsRl5h=NySM0 l5ch}hIeZ3Rz#ZK0zz1*-zJ>?5KY$OR3=Hn#eiy!k{{VmGv$OyJ literal 0 HcmV?d00001 diff --git a/assets/models/head_misc/molotov_cocktail.glb b/assets/models/head_misc/molotov_cocktail.glb index b82177510950c15e985f4764e36deab8bb84a59c..f4790cfd0bc453f1b555e922ef6aafa679418d63 100644 GIT binary patch delta 134 zcmWm4u?@mN425B(LShO!C_?n?J3reMGq4Bfgmhw#L=3hD_5{^0>J@C` Q7qUu%i6l$K``O*{3tE{V$^ZZW diff --git a/src/abilities/mod.rs b/src/abilities/mod.rs index 17d984b..6518472 100644 --- a/src/abilities/mod.rs +++ b/src/abilities/mod.rs @@ -44,6 +44,7 @@ pub struct TriggerData { rot: Quat, pos: Vec3, target_layer: GameLayer, + head: usize, } impl TriggerData { @@ -53,6 +54,7 @@ impl TriggerData { rot: Quat, pos: Vec3, target_layer: GameLayer, + head: usize, ) -> Self { Self { target, @@ -60,6 +62,7 @@ impl TriggerData { rot, pos, target_layer, + head, } } } @@ -135,6 +138,7 @@ fn on_trigger_state( pos: transform.translation, target: target.0, target_layer: GameLayer::Npc, + head: state.head, }; active_heads.use_ammo(time.elapsed_secs()); diff --git a/src/abilities/thrown.rs b/src/abilities/thrown.rs index 1e304a6..b0a2261 100644 --- a/src/abilities/thrown.rs +++ b/src/abilities/thrown.rs @@ -15,7 +15,9 @@ use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams}; use std::f32::consts::PI; #[derive(Component)] -struct ThrownProjectile; +struct ThrownProjectile { + impact_animation: bool, +} #[derive(Component, Reflect)] #[reflect(Component)] @@ -113,10 +115,17 @@ fn on_trigger_thrown( let t = Transform::from_translation(state.pos); + let (mesh, explosion_animation) = match state.head { + 8 => (assets.hammer.clone(), false), + _ => (assets.molotov.clone(), true), + }; + commands .spawn(( Name::new("projectile-thrown"), - ThrownProjectile, + ThrownProjectile { + impact_animation: explosion_animation, + }, Collider::sphere(0.5), CollisionLayers::new( LayerMask(GameLayer::Projectile.to_bits()), @@ -130,8 +139,7 @@ fn on_trigger_thrown( )) .with_child(( AutoRotation(Quat::from_rotation_x(0.4) * Quat::from_rotation_z(0.3)), - Transform::from_scale(Vec3::splat(10.)), - SceneRoot(assets.molotov.clone()), + SceneRoot(mesh), )); } @@ -149,7 +157,10 @@ fn shot_collision( let shot_entity = if query_shot.contains(*e1) { *e1 } else { *e2 }; - let Ok(shot_pos) = query_shot.get(shot_entity).map(|(_, t)| t.translation) else { + let Ok((shot_pos, animation)) = query_shot + .get(shot_entity) + .map(|(projectile, t)| (t.translation, projectile.impact_animation)) + else { continue; }; @@ -164,29 +175,32 @@ fn shot_collision( radius: 5., }); - commands - .spawn( - Sprite3dBuilder { - image: assets.image.clone(), - pixels_per_metre: 32., - alpha_mode: AlphaMode::Blend, - unlit: true, - ..default() - } - .bundle_with_atlas( - &mut sprite_params, - TextureAtlas { - layout: assets.layout.clone(), - index: 0, - }, - ), - ) - .insert(( - Billboard, - Transform::from_translation(shot_pos), - NotShadowCaster, - AnimationTimer::new(Timer::from_seconds(0.02, TimerMode::Repeating)), - )); + //TODO: support different impact animations + if animation { + commands + .spawn( + Sprite3dBuilder { + image: assets.image.clone(), + pixels_per_metre: 32., + alpha_mode: AlphaMode::Blend, + unlit: true, + ..default() + } + .bundle_with_atlas( + &mut sprite_params, + TextureAtlas { + layout: assets.layout.clone(), + index: 0, + }, + ), + ) + .insert(( + Billboard, + Transform::from_translation(shot_pos), + NotShadowCaster, + AnimationTimer::new(Timer::from_seconds(0.02, TimerMode::Repeating)), + )); + } } } diff --git a/src/ai/mod.rs b/src/ai/mod.rs index dca42cd..5b3d628 100644 --- a/src/ai/mod.rs +++ b/src/ai/mod.rs @@ -39,6 +39,7 @@ fn update( t.rotation, t.translation, crate::physics_layers::GameLayer::Player, + npc.head, ))); } } diff --git a/src/loading_assets.rs b/src/loading_assets.rs index 1ebd135..5d92a79 100644 --- a/src/loading_assets.rs +++ b/src/loading_assets.rs @@ -78,6 +78,9 @@ pub struct GameAssets { #[asset(path = "models/head_misc/molotov_cocktail.glb#Scene0")] pub molotov: Handle, + #[asset(path = "models/head_misc/hammer.glb#Scene0")] + pub hammer: Handle, + #[asset(path = "models/alien_naked.glb#Scene0")] pub mesh_alien: Handle, diff --git a/src/movables.rs b/src/movables.rs index 85bd534..2f0b03e 100644 --- a/src/movables.rs +++ b/src/movables.rs @@ -79,9 +79,7 @@ fn move_active( let t = (elapsed - active.start_time) / active.duration; transform.rotation = active.start.rotation.lerp(active.target.rotation, t); } else { - info!("movable done"); *transform = active.target; - commands.entity(e).remove::<(ActiveMovable, Movable)>(); } }