Bevy 0.16 upgrade (#24)

This commit is contained in:
extrawurst
2025-04-29 00:14:25 +02:00
committed by GitHub
parent b4bfa53df4
commit 11568d57ed
40 changed files with 932 additions and 699 deletions

View File

@@ -7,15 +7,14 @@ use crate::{
loading_assets::GameAssets,
physics_layers::GameLayer,
sounds::PlaySound,
utils::{global_observer, sprite_3d_animation::AnimationTimer},
utils::{global_observer, sprite_3d_animation::AnimationTimer, trail::Trail},
};
use avian3d::prelude::*;
use bevy::{pbr::NotShadowCaster, prelude::*};
use bevy_polyline::prelude::*;
use bevy_sprite3d::{Sprite3dBuilder, Sprite3dParams};
use std::f32::consts::PI;
const MAX_SHOT_AGES: f32 = 5.;
const MAX_SHOT_AGES: f32 = 15.;
#[derive(Component)]
struct MissileProjectile {
@@ -66,7 +65,7 @@ fn on_explosion(
};
for entity in intersections.iter() {
if let Some(mut e) = commands.get_entity(*entity) {
if let Ok(mut e) = commands.get_entity(*entity) {
e.trigger(Hit {
damage: explosion.damage,
});
@@ -89,11 +88,10 @@ fn on_trigger_missile(
mut commands: Commands,
query_transform: Query<&Transform>,
time: Res<Time>,
mut polyline_materials: ResMut<Assets<PolylineMaterial>>,
mut polylines: ResMut<Assets<Polyline>>,
heads_db: Res<HeadsDatabase>,
assets: Res<GameAssets>,
gltf_assets: Res<Assets<Gltf>>,
mut gizmo_assets: ResMut<Assets<GizmoAsset>>,
) {
let state = trigger.event().0;
@@ -111,7 +109,7 @@ fn on_trigger_missile(
let head = heads_db.head_stats(state.head);
let mut t = Transform::from_translation(state.pos).with_rotation(rotation);
t.translation += t.forward().as_vec3() * 3.0;
t.translation += t.forward().as_vec3() * 2.0;
let mesh = assets.projectiles["missile.glb"].clone();
let asset = gltf_assets.get(&mesh).unwrap();
@@ -123,12 +121,13 @@ fn on_trigger_missile(
time: time.elapsed_secs(),
damage: head.damage,
},
Collider::capsule_endpoints(0.5, Vec3::new(0., 0., 0.), Vec3::new(0., 0., -3.)),
Collider::capsule_endpoints(0.4, Vec3::new(0., 0., 2.), Vec3::new(0., 0., -2.)),
CollisionLayers::new(
LayerMask(GameLayer::Projectile.to_bits()),
LayerMask(state.target_layer.to_bits() | GameLayer::Level.to_bits()),
),
Sensor,
CollisionEventsEnabled,
Visibility::default(),
t,
))
@@ -137,18 +136,17 @@ fn on_trigger_missile(
.with_scale(Vec3::splat(0.04)),
SceneRoot(asset.scenes[0].clone()),
))
.with_child(PolylineBundle {
polyline: PolylineHandle(polylines.add(Polyline {
vertices: vec![Vec3::Z * 4., Vec3::Z * 0.],
})),
material: PolylineMaterialHandle(polyline_materials.add(PolylineMaterial {
width: 12.0,
color: LinearRgba::rgb(0.9, 0.9, 0.),
perspective: false,
.with_child((
Trail::new(t.translation, LinearRgba::rgb(0.9, 0.9, 0.)),
Gizmo {
handle: gizmo_assets.add(GizmoAsset::default()),
line_config: GizmoLineConfig {
width: 10.,
..default()
},
..default()
})),
..default()
});
},
));
}
fn update(mut query: Query<&mut Transform, With<MissileProjectile>>) {
@@ -163,7 +161,7 @@ fn timeout(mut commands: Commands, query: Query<(Entity, &MissileProjectile)>, t
for (e, MissileProjectile { time, .. }) in query.iter() {
if current_time > time + MAX_SHOT_AGES {
commands.entity(e).despawn_recursive();
commands.entity(e).despawn();
}
}
}
@@ -191,7 +189,7 @@ fn shot_collision(
commands.trigger(PlaySound::MissileExplosion);
commands.entity(shot_entity).despawn_recursive();
commands.entity(shot_entity).despawn();
commands.trigger(Explosion {
damage,