Skip to content

Commit 40da51b

Browse files
committed
completed the upgrade to bevy 0.11
1 parent de0f496 commit 40da51b

File tree

10 files changed

+65
-41
lines changed

10 files changed

+65
-41
lines changed

CHANGELOG.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77
- You must new add `#[derive(Resource)]` above your `GameState` struct.
88
- It is no longer possible to use the unit type `()` instead of a `GameState` struct. Always create a `GameState` struct (it can be an empty struct with no fields).
99
- The `Timer` now takes a `TimerMode` enum variant instead of a `bool`. Use `TimerMode::Once` for a timer that runs once, or `TimerMode::Repeating` for a repeating timer.
10+
- The following `KeyCode` variants have been renamed:
11+
- `LShift` -> `ShiftLeft`
12+
- `RShift` -> `ShiftRight`
13+
- `LAlt` -> `AltLeft`
14+
- `RAlt` -> `AltRight`
15+
- `LBracket` -> `BracketLeft`
16+
- `RBracket` -> `BracketRight`
17+
- `LControl` -> `ControlLeft`
18+
- `RControl` -> `ControlRight`
19+
- `LShift` -> `ShiftLeft`
20+
- `LWin` -> `SuperLeft`
21+
- `RWin` -> `SuperRight`
22+
1023

1124
### Improved
1225

13-
- Update bevy from 0.8 to 0.10
14-
- Update bevy_prototype_lyon from 0.6 to 0.8
26+
- Update bevy from 0.8 to 0.11
27+
- Update bevy_prototype_lyon from 0.6 to 0.9
1528
- Update ron from 0.7 to 0.8
1629
- Fixed some inconsistent parameter names in examples
30+
- Some examples' audio was turned down lower
1731

1832

1933
## [5.2.1] - 2022-11-15

examples/collider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
154154
let location = (((location / game_state.scale) * 2.0).round() * 0.5) * game_state.scale;
155155
if engine
156156
.keyboard_state
157-
.pressed_any(&[KeyCode::RShift, KeyCode::LShift])
157+
.pressed_any(&[KeyCode::ShiftLeft, KeyCode::ShiftRight])
158158
{
159159
sprite.change_last_collider_point(location);
160160
} else {

examples/keyboard_events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn logic(engine: &mut Engine, _: &mut GameState) {
3333
scan_code: _,
3434
key_code: Some(key_code),
3535
state: ButtonState::Pressed,
36+
window: _,
3637
} = keyboard_event
3738
{
3839
// Handle various keypresses. The extra keys are for the Dvorak keyboard layout. ;-)

examples/level_creator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
9999
scan_code: _,
100100
key_code: Some(key_code),
101101
state,
102+
window: _,
102103
} = keyboard_event
103104
{
104105
if *state == ButtonState::Pressed {
105106
match key_code {
106107
KeyCode::Z | KeyCode::Semicolon => {
107108
print_level = true;
108109
}
109-
KeyCode::LShift | KeyCode::RShift => {
110+
KeyCode::ShiftLeft | KeyCode::ShiftRight => {
110111
game_state.shift_pressed = true;
111112
}
112113
KeyCode::R | KeyCode::P => {
@@ -128,7 +129,7 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
128129
}
129130
} else {
130131
match key_code {
131-
KeyCode::LShift | KeyCode::RShift => {
132+
KeyCode::ShiftLeft | KeyCode::ShiftRight => {
132133
game_state.shift_pressed = false;
133134
}
134135
_ => {}
@@ -140,7 +141,7 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
140141
// Print out the level?
141142
if print_level {
142143
println!(
143-
"---------------\n\nuse rusty_engine::prelude::*;\n\nstruct GameState {{}}\n\nfn main() {{\n let mut game = Game::new();\n"
144+
"---------------\n\nuse rusty_engine::prelude::*;\n\n#[derive(Resource)]\nstruct GameState {{}}\n\nfn main() {{\n let mut game = Game::new();\n"
144145
);
145146
for sprite in engine.sprites.values() {
146147
if sprite.label == game_state.current_label {

examples/scenarios/extreme_drivers_ed.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ fn main() {
806806
a.collision = true;
807807

808808
// Music!
809-
game.audio_manager.play_music(MusicPreset::Classy8Bit, 0.5);
809+
game.audio_manager.play_music(MusicPreset::Classy8Bit, 0.1);
810810

811811
// Stuff used to keep and display score
812812
let score_text = game.add_text("score_text", "Score: 0");
@@ -916,7 +916,7 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
916916
event.pair.1.clone()
917917
};
918918
engine.sprites.remove(&shiny_label);
919-
engine.audio_manager.play_sfx(SfxPreset::Confirmation1, 1.0);
919+
engine.audio_manager.play_sfx(SfxPreset::Confirmation1, 0.5);
920920
game_state.score += 1;
921921
score_text.value = format!("Score: {}", game_state.score);
922922
if game_state.score >= game_state.win_amount {
@@ -928,14 +928,14 @@ fn logic(engine: &mut Engine, game_state: &mut GameState) {
928928
// Crash!
929929
game_state.crashed = true;
930930
//game_state.add_text("crashed", "You crashed. You fail. :-(");
931-
engine.audio_manager.play_sfx(SfxPreset::Jingle3, 1.0);
931+
engine.audio_manager.play_sfx(SfxPreset::Jingle3, 0.5);
932932
engine.audio_manager.stop_music();
933933
}
934934

935935
if game_state.won {
936936
engine
937937
.audio_manager
938-
.play_sfx(SfxPreset::Congratulations, 1.0);
938+
.play_sfx(SfxPreset::Congratulations, 0.5);
939939
let you_win = engine.add_text("you win", "You Win!");
940940
you_win.font_size = 120.0;
941941
you_win.translation.y = -50.0;

src/audio.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct AudioManagerPlugin;
6161

6262
impl Plugin for AudioManagerPlugin {
6363
fn build(&self, app: &mut bevy::prelude::App) {
64-
app.add_system(queue_managed_audio_system);
64+
app.add_systems(Update, queue_managed_audio_system);
6565
}
6666
}
6767

@@ -231,7 +231,7 @@ impl From<MusicPreset> for String {
231231
}
232232

233233
#[derive(Component)]
234-
struct Music;
234+
pub struct Music;
235235

236236
/// The Bevy system that checks to see if there is any audio management that needs to be done.
237237
#[doc(hidden)]
@@ -271,6 +271,7 @@ pub fn queue_managed_audio_system(
271271
..Default::default()
272272
},
273273
})
274+
.insert(Music)
274275
.id();
275276
game_state.audio_manager.playing = Some(entity);
276277
}

src/game.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,24 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
316316
})
317317
.set(ImagePlugin::default_nearest()),
318318
)
319-
.add_system(close_on_esc)
319+
.add_systems(
320+
Update,
321+
(
322+
(close_on_esc),
323+
(update_window_dimensions, game_logic_sync::<S>),
324+
),
325+
)
320326
// External Plugins
321-
.add_plugin(ShapePlugin) // bevy_prototype_lyon, for displaying sprite colliders
327+
.add_plugins(ShapePlugin) // bevy_prototype_lyon, for displaying sprite colliders
322328
// Rusty Engine Plugins
323-
.add_plugin(AudioManagerPlugin)
324-
.add_plugin(KeyboardPlugin)
325-
.add_plugin(MousePlugin)
326-
.add_plugin(PhysicsPlugin)
329+
.add_plugins((
330+
AudioManagerPlugin,
331+
KeyboardPlugin,
332+
MousePlugin,
333+
PhysicsPlugin,
334+
))
327335
//.insert_resource(ReportExecutionOrderAmbiguities) // for debugging
328-
.add_system(update_window_dimensions)
329-
.add_system(game_logic_sync::<S>) // this should happen after all the rest of the systems
330-
.add_startup_system(setup);
336+
.add_systems(Startup, setup);
331337
self.app.world.spawn(Camera2dBundle::default());
332338
let engine = std::mem::take(&mut self.engine);
333339
self.app.insert_resource(engine);

src/keyboard.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pub(crate) struct KeyboardPlugin;
1111
impl Plugin for KeyboardPlugin {
1212
fn build(&self, app: &mut bevy::prelude::App) {
1313
app.insert_resource::<KeyboardState>(KeyboardState::default())
14-
.add_system(sync_keyboard_events)
15-
.add_system(sync_keyboard_state);
14+
.add_systems(Update, (sync_keyboard_events, sync_keyboard_state));
1615
}
1716
}
1817

@@ -264,20 +263,20 @@ const KEYCODEVARIANTS: [KeyCode; 163] = [
264263
Grave,
265264
Kana,
266265
Kanji,
267-
LAlt,
268-
LBracket,
269-
LControl,
270-
LShift,
271-
LWin,
266+
AltLeft,
267+
BracketLeft,
268+
ControlLeft,
269+
ShiftLeft,
270+
SuperLeft,
272271
Mail,
273272
MediaSelect,
274273
MediaStop,
275274
Minus,
276275
NumpadMultiply,
277276
Mute,
278277
MyComputer,
279-
NavigateForward, // also called "Prior"
280-
NavigateBackward, // also called "Next"
278+
NavigateForward,
279+
NavigateBackward,
281280
NextTrack,
282281
NoConvert,
283282
NumpadComma,
@@ -288,11 +287,11 @@ const KEYCODEVARIANTS: [KeyCode; 163] = [
288287
PlayPause,
289288
Power,
290289
PrevTrack,
291-
RAlt,
292-
RBracket,
293-
RControl,
294-
RShift,
295-
RWin,
290+
AltRight,
291+
BracketRight,
292+
ControlRight,
293+
ShiftRight,
294+
SuperRight,
296295
Semicolon,
297296
Slash,
298297
Sleep,

src/mouse.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ pub(crate) struct MousePlugin;
1717
impl Plugin for MousePlugin {
1818
fn build(&self, app: &mut bevy::prelude::App) {
1919
app.insert_resource(MouseState::default())
20-
.add_system(sync_mouse_state)
21-
.add_system(sync_mouse_events);
20+
.add_systems(Update, (sync_mouse_state, sync_mouse_events));
2221
}
2322
}
2423

@@ -199,7 +198,8 @@ fn sync_mouse_events(
199198
let mut new_event = ev.clone();
200199
// Convert from screen space to game space
201200
// TODO: Check to see if this needs to be adjusted for different DPIs
202-
new_event.position -= game_state.window_dimensions * 0.5;
201+
new_event.position.x -= game_state.window_dimensions.x * 0.5;
202+
new_event.position.y = -new_event.position.y + (game_state.window_dimensions.y * 0.5);
203203
game_state.mouse_location_events.push(new_event);
204204
}
205205
for ev in mouse_motion_events.iter() {
@@ -225,7 +225,9 @@ fn sync_mouse_state(
225225
// Only changes when we get a new event, otherwise we preserve the last location.
226226
if let Some(event) = cursor_moved_events.iter().last() {
227227
// Convert from bevy's window space to our game space
228-
let location = event.position - game_state.window_dimensions * 0.5;
228+
let mut location = event.position.clone();
229+
location.x -= game_state.window_dimensions.x * 0.5;
230+
location.y = -location.y + (game_state.window_dimensions.y * 0.5);
229231
mouse_state.location = Some(location);
230232
}
231233
// Sync the relative mouse motion. This is the cumulative relative motion during the last frame.

src/physics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) struct PhysicsPlugin;
1414
impl Plugin for PhysicsPlugin {
1515
fn build(&self, app: &mut App) {
1616
app.add_event::<CollisionEvent>()
17-
.add_system(collision_detection);
17+
.add_systems(Update, collision_detection);
1818
}
1919
}
2020

@@ -25,7 +25,7 @@ impl Plugin for PhysicsPlugin {
2525
/// [Sprite]s which:
2626
/// - have colliders (you can use the `collider` example to create your own colliders)
2727
/// - have their `collision` flags set to `true`.
28-
#[derive(Clone, Debug, PartialEq, Eq)]
28+
#[derive(Clone, Debug, PartialEq, Eq, Event)]
2929
pub struct CollisionEvent {
3030
pub state: CollisionState,
3131
pub pair: CollisionPair,

0 commit comments

Comments
 (0)