Skip to content

Commit ae0e650

Browse files
committed
some fixes
1 parent 44ee81e commit ae0e650

File tree

10 files changed

+46
-22
lines changed

10 files changed

+46
-22
lines changed

bevy-workshop/src/1-intro/progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Progress Report
22

3-
Let's review what was done: <https://github.com/vleue/bevy_workshop-rustweek-2025/compare/before-05..05-intro-to-bevy>
3+
Let's review what was done: <https://github.com/vleue/bevy_workshop-rustweek-2025/compare/0-zero..05-intro-to-bevy>
44

55
## What You've learned
66

bevy-workshop/src/2-basics/actual-physics.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ Let's pick a physics engine that's easy to use with Bevy. There are two options:
2323

2424
We'll use Avian in this workshop, but you could use Rapier and get similar results.
2525

26-
First we'll add a dependency on `avian2d` to our `Cargo.toml` file:
26+
First we'll add a dependency on `avian2d` to our project:
2727

2828
```toml
29-
[dependencies]
30-
avian2d = "0.3"
29+
cargo add avian2d
3130
```
3231

3332
To finish the setup, we need to add the `PhysicsPlugins::default()` to our app. And as we're in space, let's remove gravity! This can be done by adding the resource `Gravity::ZERO`.
3433

3534
## Asteroid Movements
3635

37-
Asteroids are the easiest to do! First remove the `inertia` system, as that will now be handled by the physics engine.
36+
Asteroids are the easiest to do! First remove the `inertia` system, and the fields of the `Asteroid` component, as that will now be handled by the physics engine.
3837

3938
When spawning an asteroid, we'll need to add the following components:
4039

@@ -152,7 +151,7 @@ fn control_player(
152151
>,
153152
mut visibility: Query<&mut Visibility>,
154153
) -> Result {
155-
let Ok((transform, mut angular_velocity, mut linear_velocity, children)) = player.single_mut()
154+
let Ok((player_transform, mut angular_velocity, mut linear_velocity, children)) = player.single_mut()
156155
else {
157156
// No player at the moment, skip control logic
158157
return Ok(());
@@ -164,8 +163,9 @@ fn control_player(
164163
angular_velocity.0 -= 0.2;
165164
}
166165
if keyboard_input.pressed(KeyCode::KeyW) {
167-
linear_velocity.0 += transform.local_y().xy() * 2.0;
168-
linear_velocity.0 = linear_velocity.0.clamp_length_max(200.0);
166+
let forward = player_transform.local_y();
167+
linear_velocity.0 += forward.xy() * 2.0;
168+
linear_velocity.0 = linear_velocity.0.clamp_length_max(300.0);
169169
*visibility.get_mut(children[0])? = Visibility::Visible;
170170
} else {
171171
visibility

bevy-workshop/src/2-basics/controls.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
We'll control our player with the `A` and `D` keys on the keyboard to turn, and `W` for thrust.
44

5+
Let's start by handling rotation:
6+
57
```rust,no_run
68
# extern crate bevy;
79
# use bevy::prelude::*;
@@ -11,17 +13,18 @@ We'll control our player with the `A` and `D` keys on the keyboard to turn, and
1113
fn control_player(
1214
keyboard_input: Res<ButtonInput<KeyCode>>,
1315
mut player: Query<&mut Transform, With<Player>>,
16+
time: Res<Time>,
1417
) -> Result {
1518
let mut player_transform = player.single_mut()?;
19+
20+
let fixed_rotation_rate = 0.2;
21+
let rotation_rate = fixed_rotation_rate / (1.0 / (60.0 * time.delta().as_secs_f32()));
22+
1623
if keyboard_input.pressed(KeyCode::KeyA) {
17-
player_transform.rotate_z(FRAC_PI_8 / 4.0);
24+
player_transform.rotate_z(rotation_rate);
1825
}
1926
if keyboard_input.pressed(KeyCode::KeyD) {
20-
player_transform.rotate_z(-FRAC_PI_8 / 4.0);
21-
}
22-
if keyboard_input.pressed(KeyCode::KeyW) {
23-
let forward = player_transform.local_y();
24-
player_transform.translation += forward * 5.0;
27+
player_transform.rotate_z(-rotation_rate);
2528
}
2629
Ok(())
2730
}
@@ -57,6 +60,10 @@ Bevy exposes helper methods to manipulate the `Transform`:
5760

5861
As Bevy doesn't specialize for 2D, `Transform` has all the needed part for 3D and can be a bit hard to use in 2D.
5962

63+
## Time Delta
64+
65+
TODO
66+
6067
## Error handling in systems
6168

6269
Bevy systems can return a [`Result`](https://docs.rs/bevy/0.16.0/bevy/ecs/error/type.Result.html) (an alias to `Result<(), BevyError>`) to be able to use error handling, like `?`.

bevy-workshop/src/2-basics/display.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Displaying Something
22

3+
Let's start building a game! First step is to add a new `Game` variant to the `GameState` enum, and change to it in the menu instead of just printing something.
4+
35
We'll just display blocks of color for now, as placeholders. Red is the player, blue is an asteroid.
46

57
```rust,no_run
@@ -8,7 +10,7 @@ We'll just display blocks of color for now, as placeholders. Red is the player,
810
# enum GameState { #[default] Game }
911
use bevy::prelude::*;
1012
11-
fn game_plugin(app: &mut App) {
13+
pub fn game_plugin(app: &mut App) {
1214
app.add_systems(OnEnter(GameState::Game), display_level);
1315
}
1416

bevy-workshop/src/2-basics/exercises2.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
It's very easy to avoid collisions with the asteroids as they don't move... Let's make this game a bit harder!
44

5+
You can continue from your code, or get the branch with the workshop up till now:
6+
7+
```sh
8+
git checkout 06-basic-game-mid
9+
```
10+
11+
Let's review what was changed: <https://github.com/vleue/bevy_workshop-rustweek-2025/compare/06-basic-game..06-basic-game-mid>
12+
513
## Moving the Asteroids
614

715
Make the asteroids move in random directions, at random speeds.
816

917
Tips:
1018

1119
- Add information about direction and speed to the `Asteroid` component.
20+
- Add the rand crate (`cargo add rand@0.8`) to set them to random values with [`Rng::gen_range`](https://docs.rs/rand/0.8.5/rand/trait.Rng.html#method.gen_range)
1221
- Add a system to update the position of the asteroids based on their direction and speed.
1322

1423
## Losing the Game
@@ -17,7 +26,7 @@ Let's go back to the menu when colliding with an asteroid.
1726

1827
Tips:
1928

20-
- Use the `ResMut<NextState<GameStates>>` system parameter to change the current state on collision
29+
- Use the `ResMut<NextState<GameState>>` system parameter to change the current state on collision
2130

2231
## Explosion Effect on Collision
2332

bevy-workshop/src/2-basics/physics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn collision(
6262
.translation
6363
.distance(player_transform.translation);
6464
if distance < (asteroid_radius + player_radius) {
65-
info!("Collision detected!");
65+
println!("Collision detected!");
6666
}
6767
}
6868
@@ -112,7 +112,7 @@ fn collision(
112112
.translation
113113
.distance(player_transform.translation);
114114
if distance < (asteroid_radius + player_radius) {
115-
info!("Collision detected!");
115+
println!("Collision detected!");
116116
}
117117
}
118118

bevy-workshop/src/3-level/loading.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ pub struct Level {
2626

2727
## Asset Loader
2828

29+
Let's add `thiserror` as a dependency, this will help us when declaring the kind of errors that can happen when loading our file.
30+
31+
```sh
32+
cargo add thiserror
33+
```
34+
2935
To load this format, we'll read the file character by character, then choose the right tile depending on the character. Bevy expects custom asset loader to implement the trait [`AssetLoader`](https://docs.rs/bevy/0.16.0/bevy/asset/trait.AssetLoader.html).
3036

3137
```rust
@@ -108,7 +114,7 @@ Custom asset formats and loaders must be initiated in the application with [`App
108114
# async fn load(&self, reader: &mut dyn Reader, _settings: &(), _load_context: &mut LoadContext<'_>) -> Result<Self::Asset, Self::Error> { unimplemented!() }
109115
# fn extensions(&self) -> &[&str] { &["bw"] }
110116
# }
111-
fn level_loader_plugin(app: &mut App) {
117+
pub fn level_loader_plugin(app: &mut App) {
112118
app.init_asset::<Level>().init_asset_loader::<LevelLoader>();
113119
}
114120
```

bevy-workshop/src/5-sound/firing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn fire_laser(
7171

7272
To receive an event, we must use the [`EventReader`](https://docs.rs/bevy/0.16.0/bevy/ecs/event/struct.EventReader.html) system parameter, and by calling [`EventReader::read`](https://docs.rs/bevy/0.16.0/bevy/ecs/event/struct.EventReader.html#method.read) we can iterate over events.
7373

74-
To play audio, we must spawn an entity with the [`AudioStart`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioStart.html) component that will contain an [`Handle`](https://docs.rs/bevy/0.16.0/bevy/asset/enum.Handle.html) to the [`AudioSource`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioSource.html) asset.
74+
To play audio, we must spawn an entity with the [`AudioPlayer`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioPlayer.html) component that will contain an [`Handle`](https://docs.rs/bevy/0.16.0/bevy/asset/enum.Handle.html) to the [`AudioSource`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioSource.html) asset.
7575

7676
By default, audio entities remain present once the audio is done playing. You can change this behaviour with the component [`PlaybackSettings::DESPAWN`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.PlaybackSettings.html#associatedconstant.DESPAWN).
7777

bevy-workshop/src/5-sound/progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Playing a sound reacting to an action by the user
66
- Loading audio assets of the [`AudioSource`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioSource.html) asset type
7-
- And playing them by spawning the [`AudioStart`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioStart.html) component
7+
- And playing them by spawning the [`AudioPlayer`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioPlayer.html) component
88
- Controlling playback settings with the [`PlaybackSettings`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.PlaybackSettings.html) component
99
- How events work
1010
- With [`App::add_event`](https://docs.rs/bevy/0.16.0/bevy/app/struct.App.html#method.add_event) to register an event

bevy-workshop/src/6-visuals/particles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bevy_hanabi uses the GPU through compute shaders, while bevy_enoki does it all o
1313

1414
Let's add the plugin to our project:
1515

16-
```bash
16+
```sh
1717
cargo add bevy_enoki
1818
```
1919

0 commit comments

Comments
 (0)