Adjust code for Bevy 0.14 -> 0.16 upgrade

Now the program builds again.
This commit is contained in:
2025-08-20 14:06:01 -05:00
parent feeeb15d22
commit e85114c4c8
2 changed files with 17 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; use bevy::prelude::*;
use bevy_spatial::{ use bevy_spatial::{
kdtree::KDTree2, AutomaticUpdate, SpatialAccess, SpatialStructure, TransformMode, kdtree::KDTree2, AutomaticUpdate, SpatialAccess, SpatialStructure, TransformMode,
}; };
@@ -76,7 +76,7 @@ impl BoidBundle {
} }
fn spawn_camera(mut commands: Commands) { fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera2dBundle::default()); commands.spawn(Camera2d);
} }
fn spawn_boids( fn spawn_boids(
@@ -90,26 +90,17 @@ fn spawn_boids(
let vel = Vec3::new(frac.cos() * 1.0, frac.sin() * 1.0, 0.0) * 10.0; let vel = Vec3::new(frac.cos() * 1.0, frac.sin() * 1.0, 0.0) * 10.0;
commands.spawn(( commands.spawn((
BoidBundle::new(vel), BoidBundle::new(vel),
MaterialMesh2dBundle { Mesh2d(meshes.add(Circle::default())),
mesh: meshes.add(Circle::default()).into(), MeshMaterial2d(materials.add(Color::srgb(1.0, 1.0, 1.0))),
material: materials.add(Color::srgb(1.0, 1.0, 1.0)), Transform::from_translation(vel * 20.0),
transform: Transform {
translation: vel * 20.0,
..default()
},
..default()
},
)); ));
} }
commands.spawn(( commands.spawn((
BoidBundle::new(Vec3::new(0.0, 0.0, 0.0)), BoidBundle::new(Vec3::new(0.0, 0.0, 0.0)),
PlayerBoid, PlayerBoid,
MaterialMesh2dBundle { Mesh2d(meshes.add(Triangle2d::default())),
mesh: meshes.add(Triangle2d::default()).into(), MeshMaterial2d(materials.add(PLAYERBOID_COLOR)),
material: materials.add(PLAYERBOID_COLOR),
..default()
},
)); ));
} }
@@ -124,7 +115,7 @@ fn turn_if_edge(
mut query: Query<(&mut Transform, &mut Velocity), With<Boid>>, mut query: Query<(&mut Transform, &mut Velocity), With<Boid>>,
window: Query<&Window>, window: Query<&Window>,
) { ) {
if let Ok(window) = window.get_single() { if let Ok(window) = window.single() {
let (width, height) = (window.resolution.width(), window.resolution.height()); let (width, height) = (window.resolution.width(), window.resolution.height());
for (transform, mut velocity) in &mut query { for (transform, mut velocity) in &mut query {
let boid_pos = transform.translation.xy(); let boid_pos = transform.translation.xy();
@@ -147,9 +138,9 @@ fn turn_if_edge(
fn apply_velocity(mut query: Query<(&mut Transform, &Velocity, &mut Force)>, time: Res<Time>) { fn apply_velocity(mut query: Query<(&mut Transform, &Velocity, &mut Force)>, time: Res<Time>) {
for (mut transform, velocity, mut acceleration) in &mut query { for (mut transform, velocity, mut acceleration) in &mut query {
let delta_v = **acceleration * time.delta_seconds(); let delta_v = **acceleration * time.delta_secs();
**acceleration = Vec3::ZERO; **acceleration = Vec3::ZERO;
let delta_position = (**velocity + delta_v) * time.delta_seconds(); let delta_position = (**velocity + delta_v) * time.delta_secs();
transform.translation += delta_position; transform.translation += delta_position;
} }
} }
@@ -163,7 +154,9 @@ fn check_keyboard(
app_exit_events.send(bevy::app::AppExit::Success); app_exit_events.send(bevy::app::AppExit::Success);
} }
let mut pvelocity = query.single_mut(); let mut pvelocity = query
.single_mut()
.expect("[birdoids_plugin::check_keyboard()] ->> There seems to be more than one player... How did that happen?");
let mut dir = Vec2::ZERO; let mut dir = Vec2::ZERO;
if keyboard_input.pressed(KeyCode::ArrowLeft) { if keyboard_input.pressed(KeyCode::ArrowLeft) {
dir.x -= 1.0; dir.x -= 1.0;

View File

@@ -1,4 +1,4 @@
use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::PrimaryWindow}; use bevy::{prelude::*, window::PrimaryWindow};
use bevy_spatial::{kdtree::KDTree2, SpatialAccess}; use bevy_spatial::{kdtree::KDTree2, SpatialAccess};
use crate::birdoids_plugin::{ use crate::birdoids_plugin::{
@@ -22,13 +22,10 @@ fn setup(
) { ) {
commands.spawn(( commands.spawn((
ScannerWidget::default(), ScannerWidget::default(),
MaterialMesh2dBundle { Mesh2d(meshes
mesh: meshes
.add(Annulus::new(SCANRADIUS - 1.0, SCANRADIUS)) .add(Annulus::new(SCANRADIUS - 1.0, SCANRADIUS))
.into(), ),
material: materials.add(Color::srgb(0.0, 0.0, 0.0)), MeshMaterial2d(materials.add(Color::srgb(0.0, 0.0, 0.0))),
..default()
},
)); ));
} }