Skip to content

Commit

Permalink
Update to Bevy 0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tehlers committed Dec 1, 2024
1 parent c6a7644 commit 4dc177a
Show file tree
Hide file tree
Showing 10 changed files with 1,063 additions and 727 deletions.
1,410 changes: 890 additions & 520 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lto = "thin"
opt-level = 'z'

[dependencies.bevy]
version = "0.14.2"
version = "0.15.0"
default-features = false
features = [
# Bevy functionality:
Expand All @@ -34,6 +34,7 @@ features = [
"x11", # Linux: Support X11 windowing system
#"filesystem_watcher", # Asset hot-reloading
#"render", # Graphics Rendering
"default_font",

## "render" actually just includes:
## (feel free to use just a subset of these, instead of "render")
Expand All @@ -45,6 +46,7 @@ features = [
"bevy_text", # Text/font rendering
"bevy_ui", # UI toolkit
"bevy_state",
"bevy_window",

# File formats:
#"png",
Expand All @@ -56,7 +58,6 @@ features = [

# Bevy functionality:
"wayland", # Linux: Support Wayland windowing system
"subpixel_glyph_atlas", # Subpixel antialiasing for text/fonts
#"serialize", # Support for `serde` Serialize/Deserialize
#"bevy_dynamic_plugin", # Support for loading of `DynamicPlugin`s

Expand All @@ -82,7 +83,7 @@ features = [

[dependencies]
anyhow = "1"
bevy_embedded_assets = "0.11"
bevy_prototype_lyon = "0.12"
bevy_embedded_assets = "0.12"
bevy_prototype_lyon = "0.13"
directories = "5"
rand = "0.8.4"
6 changes: 3 additions & 3 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Plugin for GamePlugin {
control::game_over
.after(Phase::Movement)
.run_if(in_state(GameState::Game))
.run_if(on_event::<GameOver>()),
.run_if(on_event::<GameOver>),
),
)
.add_systems(
Expand All @@ -85,9 +85,9 @@ impl Plugin for GamePlugin {
.after(Phase::Input)
.in_set(Phase::Movement),
control::eat,
control::spawn_consumables.run_if(on_event::<SpawnConsumables>()),
control::spawn_consumables.run_if(on_event::<SpawnConsumables>),
graphics::show_message,
control::growth.run_if(on_event::<Growth>()),
control::growth.run_if(on_event::<Growth>),
)
.chain(),
(graphics::change_color, control::control_antidote_sound),
Expand Down
49 changes: 25 additions & 24 deletions src/game/systems/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn spawn_diplopod(
let shape = shapes::Rectangle {
extents: Vec2::splat(tile_size.0 as f32),
origin: shapes::RectangleOrigin::Center,
radii: None,
};

segments.0 = vec![commands
Expand Down Expand Up @@ -79,6 +80,7 @@ pub fn init_wall(
let shape = shapes::Rectangle {
extents: Vec2::splat(tile_size.0 as f32 * 2.0),
origin: shapes::RectangleOrigin::Center,
radii: None,
};

for x in 0..CONSUMABLE_WIDTH + 1 {
Expand Down Expand Up @@ -405,10 +407,10 @@ pub fn spawn_consumables(
&tile_size,
);

commands.spawn(AudioBundle {
source: sounds.special_spawn.clone(),
settings: PlaybackSettings::DESPAWN,
});
commands.spawn((
AudioPlayer(sounds.special_spawn.clone()),
PlaybackSettings::DESPAWN,
));
}
}
}
Expand Down Expand Up @@ -478,10 +480,10 @@ pub fn eat(
new_segments: 1,
});

commands.spawn(AudioBundle {
source: sounds.eat_food.clone(),
settings: PlaybackSettings::DESPAWN,
});
commands.spawn((
AudioPlayer(sounds.eat_food.clone()),
PlaybackSettings::DESPAWN,
));
}
}

Expand All @@ -503,10 +505,10 @@ pub fn eat(
new_segments,
});

commands.spawn(AudioBundle {
source: sounds.super_food.clone(),
settings: PlaybackSettings::DESPAWN,
});
commands.spawn((
AudioPlayer(sounds.super_food.clone()),
PlaybackSettings::DESPAWN,
));
}
}

Expand All @@ -517,10 +519,8 @@ pub fn eat(
immunity_time.0 += 10;

commands.spawn((
AudioBundle {
source: sounds.antidote.clone(),
settings: PlaybackSettings::LOOP,
},
AudioPlayer(sounds.antidote.clone()),
PlaybackSettings::LOOP,
AntidoteSound,
OnGameScreen,
));
Expand All @@ -535,10 +535,10 @@ pub fn eat(
free_positions.shuffle();
growth_writer.send(Growth(1));

commands.spawn(AudioBundle {
source: sounds.eat_poison.clone(),
settings: PlaybackSettings::DESPAWN,
});
commands.spawn((
AudioPlayer(sounds.eat_poison.clone()),
PlaybackSettings::DESPAWN,
));
} else {
game_over_writer.send(GameOver);
}
Expand All @@ -564,6 +564,7 @@ pub fn growth(
let shape = shapes::Rectangle {
extents: Vec2::splat(tile_size.0 as f32),
origin: shapes::RectangleOrigin::Center,
radii: None,
};

if let Some(growth) = growth_reader.read().next() {
Expand Down Expand Up @@ -650,10 +651,10 @@ pub fn game_over(
mut highscore: ResMut<Highscore>,
) {
if reader.read().next().is_some() {
commands.spawn(AudioBundle {
source: sounds.game_over.clone(),
settings: PlaybackSettings::DESPAWN,
});
commands.spawn((
AudioPlayer(sounds.game_over.clone()),
PlaybackSettings::DESPAWN,
));

lastscore.0 = 0;
for _ in segments.iter() {
Expand Down
36 changes: 20 additions & 16 deletions src/game/systems/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ fn resize_consumables(
let shape = shapes::Rectangle {
extents: Vec2::splat(tile_size.0 as f32 * 2.0),
origin: shapes::RectangleOrigin::Center,
radii: None,
};

for mut path in paths.p3().iter_mut() {
Expand All @@ -131,6 +132,7 @@ fn resize_consumables(
let shape = shapes::Rectangle {
extents: Vec2::splat(tile_size.0 as f32),
origin: shapes::RectangleOrigin::Center,
radii: None,
};

for mut path in paths.p4().iter_mut() {
Expand Down Expand Up @@ -178,7 +180,7 @@ pub fn position_translation(

pub fn rotate_superfood(mut query: Query<&mut Transform, With<Superfood>>, time: Res<Time>) {
for mut transform in query.iter_mut() {
let delta = time.delta_seconds();
let delta = time.delta_secs();
transform.rotate(Quat::from_rotation_z(1.5 * delta));
}
}
Expand Down Expand Up @@ -210,9 +212,13 @@ pub fn change_color(
}
}

pub fn fade_text(mut commands: Commands, mut query: Query<(Entity, &mut Text, &mut FadingText)>) {
for (entity, mut text, mut fading_text) in query.iter_mut() {
text.sections[0].style.color.set_alpha(fading_text.0);
pub fn fade_text(
mut commands: Commands,
mut query: Query<(Entity, &mut FadingText)>,
mut writer: Text2dWriter,
) {
for (entity, mut fading_text) in query.iter_mut() {
writer.color(entity, 0).set_alpha(fading_text.0);
fading_text.0 -= 0.1;

if fading_text.0 <= 0.0 {
Expand All @@ -223,20 +229,18 @@ pub fn fade_text(mut commands: Commands, mut query: Query<(Entity, &mut Text, &m

pub fn show_message(mut commands: Commands, mut show_message_reader: EventReader<ShowMessage>) {
if let Some(show_message) = show_message_reader.read().next() {
let text_style = TextStyle {
font_size: 36.0,
color: Color::WHITE,
..default()
};

commands
.spawn(Text2dBundle {
text: Text::from_section(&show_message.text, text_style)
.with_justify(JustifyText::Center),
.spawn((
Text2d::new(&show_message.text),
TextFont {
font_size: 36.0,
..default()
},
TextColor::WHITE,
TextLayout::new_with_justify(JustifyText::Center),
// ensure that the text is drawn above the diplopod
transform: Transform::from_translation(Vec3::Z),
..default()
})
Transform::from_translation(Vec3::Z),
))
.insert(show_message.position)
.insert(OnGameScreen)
.insert(FadingText(1.0));
Expand Down
14 changes: 3 additions & 11 deletions src/game/systems/player_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ pub fn keyboard(keyboard_input: Res<ButtonInput<KeyCode>>, mut heads: Query<&mut
}
}

pub fn gamepad(
gamepads: Res<Gamepads>,
axes: Res<Axis<GamepadAxis>>,
mut heads: Query<&mut DiplopodHead>,
) {
pub fn gamepad(gamepads: Query<&Gamepad>, mut heads: Query<&mut DiplopodHead>) {
const TILT: f32 = 0.9;

if let Some(mut head) = heads.iter_mut().next() {
let mut direction = Vec2::ZERO;

for gamepad in gamepads.iter() {
if let Some(left_stick_x) =
axes.get(GamepadAxis::new(gamepad, GamepadAxisType::LeftStickX))
{
if let Some(left_stick_x) = gamepad.get(GamepadAxis::LeftStickX) {
if left_stick_x <= -TILT {
direction = Vec2::new(-1.0, 0.0);
}
Expand All @@ -51,9 +45,7 @@ pub fn gamepad(
}
}

if let Some(left_stick_y) =
axes.get(GamepadAxis::new(gamepad, GamepadAxisType::LeftStickY))
{
if let Some(left_stick_y) = gamepad.get(GamepadAxis::LeftStickY) {
if left_stick_y <= -TILT {
direction = Vec2::new(direction.x, -1.0);
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/systems/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn setup(
asset_server: Res<AssetServer>,
mut windows: Query<&mut Window, With<PrimaryWindow>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);

let sounds = Sounds {
eat_food: asset_server.load("audio/eat_food.ogg"),
Expand All @@ -24,7 +24,7 @@ pub fn setup(
commands.insert_resource(DefaultFontHandle(font));

if let Ok(mut window) = windows.get_single_mut() {
window.cursor.visible = false;
window.cursor_options.visible = false;
}
}

Expand All @@ -34,7 +34,7 @@ pub fn set_default_font(
default_font_handle: Res<DefaultFontHandle>,
) {
if let Some(font) = fonts.remove(&default_font_handle.0) {
fonts.insert(&TextStyle::default().font, font);
fonts.insert(&TextFont::default().font, font);
commands.remove_resource::<DefaultFontHandle>();
}
}
Loading

0 comments on commit 4dc177a

Please sign in to comment.