Update to bevy 0.15

This commit is contained in:
2025-01-01 14:02:39 +01:00
parent d59aa18809
commit cd6408666f
9 changed files with 874 additions and 457 deletions

1167
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,14 +4,14 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
itertools = "0.13.0" itertools = "0.14.0"
rand = "0.8.5" rand = "0.8.5"
bevy_tweening = "0.11.0" bevy_tweening = "0.12.0"
leafwing-input-manager = "0.15.1" leafwing-input-manager = "0.16.0"
bevy_asset_loader = "0.21.0" bevy_asset_loader = "0.22.0"
[dependencies.bevy] [dependencies.bevy]
version = "0.14" version = "0.15"
features = ["wayland", "wav"] features = ["wayland", "wav"]
# [profile.dev.package."*"] # [profile.dev.package."*"]

View File

@@ -120,12 +120,11 @@ const CANVAS_COLOR: Color = Color::srgb(0.075, 0.075, 0.075);
// } // }
fn spawn_canvas(mut commands: Commands) { fn spawn_canvas(mut commands: Commands) {
commands.spawn(SpriteBundle { commands.spawn((
sprite: Sprite { Sprite {
color: CANVAS_COLOR.into(), color: CANVAS_COLOR.into(),
..Default::default() ..Default::default()
}, },
transform: Transform::from_scale(Vec3::splat(grid::SEGMENT_SIZE * f32::from(grid::SIZE))), Transform::from_scale(Vec3::splat(grid::SEGMENT_SIZE * f32::from(grid::SIZE))),
..Default::default() ));
});
} }

View File

@@ -56,15 +56,14 @@ fn spawn_fruit_system(mut commands: Commands, coordinate_query: Query<&grid::Coo
.expect("Should always be found."); .expect("Should always be found.");
commands commands
.spawn(SpriteBundle { .spawn((
sprite: Sprite { Sprite {
color: Srgba::GREEN.into(), color: Srgba::GREEN.into(),
custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.6), custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.6),
..Default::default() ..Default::default()
}, },
transform: Transform::from_translation(Vec2::from(fruit_coordinate).extend(Z_HEIGHT)), Transform::from_translation(Vec2::from(fruit_coordinate).extend(Z_HEIGHT)),
..Default::default() ))
})
.insert(fruit_coordinate) .insert(fruit_coordinate)
.insert(Fruit) .insert(Fruit)
// .insert(crate::canvas::EmissiveTile { intensity: 1.0 }) // .insert(crate::canvas::EmissiveTile { intensity: 1.0 })

View File

@@ -110,17 +110,17 @@ fn setup_camera_system(mut commands: Commands) {
let grid_dimensions = f32::from(SIZE) * SEGMENT_SIZE * 1.2; let grid_dimensions = f32::from(SIZE) * SEGMENT_SIZE * 1.2;
commands commands
.spawn(Camera2dBundle { .spawn((
projection: OrthographicProjection { Camera2d,
OrthographicProjection {
scaling_mode: ScalingMode::AutoMin { scaling_mode: ScalingMode::AutoMin {
min_width: grid_dimensions, min_width: grid_dimensions,
min_height: grid_dimensions, min_height: grid_dimensions,
}, },
near: -1000., near: -1000.,
..Default::default() ..OrthographicProjection::default_2d()
}, },
..Default::default() ))
})
.insert(Name::new("Orthographic Camera")); .insert(Name::new("Orthographic Camera"));
} }

View File

@@ -64,7 +64,7 @@ impl Plugin for SnakePlugin {
.run_if(in_state(AppState::InGame(LevelState::Begin))), .run_if(in_state(AppState::InGame(LevelState::Begin))),
direction::change_direction_system.run_if( direction::change_direction_system.run_if(
in_state(AppState::InGame(LevelState::Begin)) in_state(AppState::InGame(LevelState::Begin))
.or_else(in_state(AppState::InGame(LevelState::InGame))), .or(in_state(AppState::InGame(LevelState::InGame))),
), ),
bulge::add_bulge_system, bulge::add_bulge_system,
bulge::propagate_bulge_system, bulge::propagate_bulge_system,
@@ -107,7 +107,8 @@ struct SnakeBundle {
snake: Snake, snake: Snake,
collision: Collision, collision: Collision,
segments: Segments, segments: Segments,
spatial_bundle: SpatialBundle, transform: Transform,
visibility: Visibility,
} }
#[derive(Component, Default, Debug)] #[derive(Component, Default, Debug)]
@@ -127,15 +128,14 @@ fn create_snake_segment(
color *= 0.99f32.powi(segment_number as _); color *= 0.99f32.powi(segment_number as _);
commands commands
.spawn(SpriteBundle { .spawn((
sprite: Sprite { Sprite {
color: color.into(), color: color.into(),
custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.9), custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.9),
..Default::default() ..Default::default()
}, },
transform: Transform::from_translation(Vec2::from(grid_position).extend(Z_HEIGHT)), Transform::from_translation(Vec2::from(grid_position).extend(Z_HEIGHT)),
..Default::default() ))
})
.insert(SnakeSegment) .insert(SnakeSegment)
.insert(grid_position) .insert(grid_position)
// .insert(crate::canvas::EmissiveTile { intensity: 1.0 }) // .insert(crate::canvas::EmissiveTile { intensity: 1.0 })
@@ -156,7 +156,8 @@ fn setup_snake_system(mut commands: Commands) {
snake: Snake, snake: Snake,
collision: Default::default(), collision: Default::default(),
segments: Segments(vec![snake_head]), segments: Segments(vec![snake_head]),
spatial_bundle: Default::default(), transform: Default::default(),
visibility: Default::default(),
}) })
.insert(Name::new("Snake")) .insert(Name::new("Snake"))
.insert(InputManagerBundle::<Direction> { .insert(InputManagerBundle::<Direction> {
@@ -266,10 +267,10 @@ fn game_over_system(mut next_state: ResMut<NextState<AppState>>) {
} }
fn collision_sound_system(mut commands: Commands, audio_assets: Res<audio::Assets>) { fn collision_sound_system(mut commands: Commands, audio_assets: Res<audio::Assets>) {
commands.spawn(AudioBundle { commands.spawn((
source: audio_assets.collision.clone(), AudioPlayer::<AudioSource>(audio_assets.collision.clone()),
settings: PlaybackSettings::DESPAWN, PlaybackSettings::DESPAWN,
}); ));
} }
fn blip_sound_system( fn blip_sound_system(
@@ -278,10 +279,10 @@ fn blip_sound_system(
mut eaten_event_reader: EventReader<fruit::EatenEvent>, mut eaten_event_reader: EventReader<fruit::EatenEvent>,
) { ) {
for _ in eaten_event_reader.read() { for _ in eaten_event_reader.read() {
commands.spawn(AudioBundle { commands.spawn((
source: audio_assets.blip.clone(), AudioPlayer::<AudioSource>(audio_assets.blip.clone()),
settings: PlaybackSettings::DESPAWN, PlaybackSettings::DESPAWN,
}); ));
} }
} }

View File

@@ -62,9 +62,10 @@ pub(super) fn change_direction_system(
} }
commands.entity(snake).insert(NextDirection(new_direction)); commands.entity(snake).insert(NextDirection(new_direction));
commands.spawn(AudioBundle {
source: audio_assets.tick.clone(), commands.spawn((
settings: PlaybackSettings::DESPAWN, AudioPlayer::<AudioSource>(audio_assets.tick.clone()),
}); PlaybackSettings::DESPAWN,
));
} }
} }

View File

@@ -7,6 +7,9 @@ pub struct UiPlugin;
impl Plugin for UiPlugin { impl Plugin for UiPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, status::spawn_status_text) app.add_systems(Startup, status::spawn_status_text)
.add_systems(Update, status::update_status_text); .add_systems(
Update,
(status::update_level_text, status::update_score_text),
);
} }
} }

View File

@@ -1,61 +1,48 @@
use crate::{level::Level, Score}; use crate::{level::Level, Score};
use bevy::prelude::*; use bevy::{color::palettes::css::GOLD, prelude::*};
#[derive(Component)] #[derive(Component)]
pub(super) struct StatusText; pub(super) struct LevelValue;
#[derive(Component)]
pub(super) struct ScoreValue;
pub(super) fn spawn_status_text(mut commands: Commands, asset_server: Res<AssetServer>) { pub(super) fn spawn_status_text(mut commands: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/Audiowide-Regular.ttf"); let font = asset_server.load("fonts/Audiowide-Regular.ttf");
commands.spawn(( commands
StatusText, .spawn((
TextBundle::from_sections([ Text::default(),
TextSection::new( TextFont {
"Level: ",
TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
},
),
TextSection::from_style(TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
}),
TextSection::new(
" Score: ",
TextStyle {
font: font.clone(),
font_size: 32.0,
color: Color::WHITE,
},
),
TextSection::from_style(TextStyle {
font, font,
font_size: 32.0, font_size: 32.0,
color: Color::WHITE, ..Default::default()
}), },
]) Node {
.with_style(Style { position_type: PositionType::Absolute,
position_type: PositionType::Absolute, left: Val::Px(10.0),
left: Val::Px(10.0), bottom: Val::Px(10.0),
bottom: Val::Px(10.0), ..Default::default()
..Default::default() },
}), ))
)); .with_child((TextSpan::new("Level: "), TextColor::WHITE))
.with_child((LevelValue, TextSpan::default(), TextColor(GOLD.into())))
.with_child((TextSpan::new(" Score: "), TextColor::WHITE))
.with_child((ScoreValue, TextSpan::default(), TextColor(GOLD.into())));
} }
pub(super) fn update_status_text( pub(super) fn update_level_text(
mut query: Query<&mut Text, With<StatusText>>, mut level_query: Query<&mut TextSpan, With<LevelValue>>,
score: Res<Score>,
level: Res<Level>, level: Res<Level>,
) { ) {
let score = score.0;
let level = level.0; let level = level.0;
level_query.single_mut().0 = format!("{level}");
for mut text in query.iter_mut() { }
text.sections[1].value = format!("{level}");
text.sections[3].value = format!("{score}"); pub(super) fn update_score_text(
} mut score_query: Query<&mut TextSpan, With<ScoreValue>>,
score: Res<Score>,
) {
let score = score.0;
score_query.single_mut().0 = format!("{score}");
} }