Update to bevy 0.15
This commit is contained in:
1167
Cargo.lock
generated
1167
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@@ -4,14 +4,14 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.13.0"
|
||||
itertools = "0.14.0"
|
||||
rand = "0.8.5"
|
||||
bevy_tweening = "0.11.0"
|
||||
leafwing-input-manager = "0.15.1"
|
||||
bevy_asset_loader = "0.21.0"
|
||||
bevy_tweening = "0.12.0"
|
||||
leafwing-input-manager = "0.16.0"
|
||||
bevy_asset_loader = "0.22.0"
|
||||
|
||||
[dependencies.bevy]
|
||||
version = "0.14"
|
||||
version = "0.15"
|
||||
features = ["wayland", "wav"]
|
||||
|
||||
# [profile.dev.package."*"]
|
||||
|
||||
@@ -120,12 +120,11 @@ const CANVAS_COLOR: Color = Color::srgb(0.075, 0.075, 0.075);
|
||||
// }
|
||||
|
||||
fn spawn_canvas(mut commands: Commands) {
|
||||
commands.spawn(SpriteBundle {
|
||||
sprite: Sprite {
|
||||
commands.spawn((
|
||||
Sprite {
|
||||
color: CANVAS_COLOR.into(),
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform::from_scale(Vec3::splat(grid::SEGMENT_SIZE * f32::from(grid::SIZE))),
|
||||
..Default::default()
|
||||
});
|
||||
Transform::from_scale(Vec3::splat(grid::SEGMENT_SIZE * f32::from(grid::SIZE))),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -56,15 +56,14 @@ fn spawn_fruit_system(mut commands: Commands, coordinate_query: Query<&grid::Coo
|
||||
.expect("Should always be found.");
|
||||
|
||||
commands
|
||||
.spawn(SpriteBundle {
|
||||
sprite: Sprite {
|
||||
.spawn((
|
||||
Sprite {
|
||||
color: Srgba::GREEN.into(),
|
||||
custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.6),
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform::from_translation(Vec2::from(fruit_coordinate).extend(Z_HEIGHT)),
|
||||
..Default::default()
|
||||
})
|
||||
Transform::from_translation(Vec2::from(fruit_coordinate).extend(Z_HEIGHT)),
|
||||
))
|
||||
.insert(fruit_coordinate)
|
||||
.insert(Fruit)
|
||||
// .insert(crate::canvas::EmissiveTile { intensity: 1.0 })
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -110,17 +110,17 @@ fn setup_camera_system(mut commands: Commands) {
|
||||
let grid_dimensions = f32::from(SIZE) * SEGMENT_SIZE * 1.2;
|
||||
|
||||
commands
|
||||
.spawn(Camera2dBundle {
|
||||
projection: OrthographicProjection {
|
||||
.spawn((
|
||||
Camera2d,
|
||||
OrthographicProjection {
|
||||
scaling_mode: ScalingMode::AutoMin {
|
||||
min_width: grid_dimensions,
|
||||
min_height: grid_dimensions,
|
||||
},
|
||||
near: -1000.,
|
||||
..Default::default()
|
||||
..OrthographicProjection::default_2d()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
))
|
||||
.insert(Name::new("Orthographic Camera"));
|
||||
}
|
||||
|
||||
|
||||
33
src/snake.rs
33
src/snake.rs
@@ -64,7 +64,7 @@ impl Plugin for SnakePlugin {
|
||||
.run_if(in_state(AppState::InGame(LevelState::Begin))),
|
||||
direction::change_direction_system.run_if(
|
||||
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::propagate_bulge_system,
|
||||
@@ -107,7 +107,8 @@ struct SnakeBundle {
|
||||
snake: Snake,
|
||||
collision: Collision,
|
||||
segments: Segments,
|
||||
spatial_bundle: SpatialBundle,
|
||||
transform: Transform,
|
||||
visibility: Visibility,
|
||||
}
|
||||
|
||||
#[derive(Component, Default, Debug)]
|
||||
@@ -127,15 +128,14 @@ fn create_snake_segment(
|
||||
color *= 0.99f32.powi(segment_number as _);
|
||||
|
||||
commands
|
||||
.spawn(SpriteBundle {
|
||||
sprite: Sprite {
|
||||
.spawn((
|
||||
Sprite {
|
||||
color: color.into(),
|
||||
custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE) * 0.9),
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform::from_translation(Vec2::from(grid_position).extend(Z_HEIGHT)),
|
||||
..Default::default()
|
||||
})
|
||||
Transform::from_translation(Vec2::from(grid_position).extend(Z_HEIGHT)),
|
||||
))
|
||||
.insert(SnakeSegment)
|
||||
.insert(grid_position)
|
||||
// .insert(crate::canvas::EmissiveTile { intensity: 1.0 })
|
||||
@@ -156,7 +156,8 @@ fn setup_snake_system(mut commands: Commands) {
|
||||
snake: Snake,
|
||||
collision: Default::default(),
|
||||
segments: Segments(vec![snake_head]),
|
||||
spatial_bundle: Default::default(),
|
||||
transform: Default::default(),
|
||||
visibility: Default::default(),
|
||||
})
|
||||
.insert(Name::new("Snake"))
|
||||
.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>) {
|
||||
commands.spawn(AudioBundle {
|
||||
source: audio_assets.collision.clone(),
|
||||
settings: PlaybackSettings::DESPAWN,
|
||||
});
|
||||
commands.spawn((
|
||||
AudioPlayer::<AudioSource>(audio_assets.collision.clone()),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
}
|
||||
|
||||
fn blip_sound_system(
|
||||
@@ -278,10 +279,10 @@ fn blip_sound_system(
|
||||
mut eaten_event_reader: EventReader<fruit::EatenEvent>,
|
||||
) {
|
||||
for _ in eaten_event_reader.read() {
|
||||
commands.spawn(AudioBundle {
|
||||
source: audio_assets.blip.clone(),
|
||||
settings: PlaybackSettings::DESPAWN,
|
||||
});
|
||||
commands.spawn((
|
||||
AudioPlayer::<AudioSource>(audio_assets.blip.clone()),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,10 @@ pub(super) fn change_direction_system(
|
||||
}
|
||||
|
||||
commands.entity(snake).insert(NextDirection(new_direction));
|
||||
commands.spawn(AudioBundle {
|
||||
source: audio_assets.tick.clone(),
|
||||
settings: PlaybackSettings::DESPAWN,
|
||||
});
|
||||
|
||||
commands.spawn((
|
||||
AudioPlayer::<AudioSource>(audio_assets.tick.clone()),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ pub struct UiPlugin;
|
||||
impl Plugin for UiPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,48 @@
|
||||
use crate::{level::Level, Score};
|
||||
use bevy::prelude::*;
|
||||
use bevy::{color::palettes::css::GOLD, prelude::*};
|
||||
|
||||
#[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>) {
|
||||
let font = asset_server.load("fonts/Audiowide-Regular.ttf");
|
||||
|
||||
commands.spawn((
|
||||
StatusText,
|
||||
TextBundle::from_sections([
|
||||
TextSection::new(
|
||||
"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 {
|
||||
commands
|
||||
.spawn((
|
||||
Text::default(),
|
||||
TextFont {
|
||||
font,
|
||||
font_size: 32.0,
|
||||
color: Color::WHITE,
|
||||
}),
|
||||
])
|
||||
.with_style(Style {
|
||||
..Default::default()
|
||||
},
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
left: Val::Px(10.0),
|
||||
bottom: Val::Px(10.0),
|
||||
..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(
|
||||
mut query: Query<&mut Text, With<StatusText>>,
|
||||
score: Res<Score>,
|
||||
pub(super) fn update_level_text(
|
||||
mut level_query: Query<&mut TextSpan, With<LevelValue>>,
|
||||
level: Res<Level>,
|
||||
) {
|
||||
let score = score.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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user