Skip to content

Commit 571b58a

Browse files
committed
update outdated references to rand in the scenarios
1 parent 09bf4cb commit 571b58a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

scenarios/car_shoot.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-
7676
1. Set `game_state.spawn_timer` to a new `Timer` with a random value between `0.1` and `1.25`
7777
- Add the `rand` crate as a dependency in your `Cargo.toml`
7878
- Add `use rand::prelude::*;` to the top of your `main.rs` file
79-
- Use `thread_rng().gen_range(0.1..1.25)` to obtain a random `f32` value between `0.1` and `1.25`
79+
- Use `rand::rng().random_range(0.1..1.25)` to obtain a random `f32` value between `0.1` and `1.25`
8080
- [Create a non-repeating `Timer`](https://cleancut.github.io/rusty_engine/250-timer.html#creation) and assign it as the value to `game_state.spawn_timer`
8181
1. If there are any cars left (check the value of `game_state.cars_left`), then:
8282
1. Decrement `game_state.cars_left` by one
8383
1. [Retrieve a mutable reference to the](https://cleancut.github.io/rusty_engine/165-text-placement.html#adjusting-an-existing-text) `Text` we labeled `"cars left"`
8484
- Set the `value` to `format!("Cars left: {}", game_state.cars_left)`
8585
1. Create a label for the current car that starts with `car`: `format!("car{}", game_state.cars_left)` (remember, a label starting with `car` is what the movement code is looking for).
8686
1. Create a vector of `SpritePreset`s of cars to randomly select from: `let car_choices = vec![SpritePreset::RacingCarBlack, SpritePreset::RacingCarBlue, SpritePreset::RacingCarGreen, SpritePreset::RacingCarRed, SpritePreset::RacingCarYellow];`
87-
1. Make a random sprite preset choice: `car_choices.iter().choose(&mut thread_rng()).unwrap().clone()`
87+
1. Make a random sprite preset choice: `car_choices.iter().choose(&mut rand::rng()).unwrap().clone()`
8888
1. Actually create the sprite with the label and sprite preset selected above. Set the sprite's:
8989
- `translation.x` to `-740.0`
90-
- `translation.y` to a random value from `-100.0` to `325.0` -- `thread_rng().gen_range(-100.0..325.0)`
90+
- `translation.y` to a random value from `-100.0` to `325.0` -- `rand::rng().random_range(-100.0..325.0)`
9191
- `collision` to `true` so that the car will collide with marbles
9292
1. Move cars right across the screen (in the positive X direction). The logic for this section is _very_ similar to the previous section that moved marbles.
9393
1. Define a `CAR_SPEED` constant and set it to `250.0`

scenarios/road_race.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ Now it's time to add some obstacles. Interesting obstacles will be in random loc
173173
1. Add a sprite with that preset and a label that starts with `"obstacle"`, and ends with the number value of `i`. (Use the `format!()` macro to construct the label string).
174174
1. Set the sprite's `layer` to `5.0` so that the obstacle will be on top of road lines, but underneath the player.
175175
1. set the sprite's `collision` to `true` so that it will generate collision events with the race car.
176-
1. Set the `x` location to a random value between `800.0` and `1600.0` using `thread_rng()`
177-
* `sprite.translation.x = thread_rng().gen_range(800.0..1600.0);`
176+
1. Set the `x` location to a random value between `800.0` and `1600.0` using `rand::rng()`
177+
* `sprite.translation.x = rand::rng().random_range(800.0..1600.0);`
178178
1. Do the same for `y`, only between `-300.0` and `300.0`
179179

180180
```rust
@@ -184,8 +184,8 @@ for (i, preset) in obstacle_presets.into_iter().enumerate() {
184184
let obstacle = game.add_sprite(format!("obstacle{}", i), preset);
185185
obstacle.layer = 5.0;
186186
obstacle.collision = true;
187-
obstacle.translation.x = thread_rng().gen_range(800.0..1600.0);
188-
obstacle.translation.y = thread_rng().gen_range(-300.0..300.0);
187+
obstacle.translation.x = rand::rng().random_range(800.0..1600.0);
188+
obstacle.translation.y = rand::rng().random_range(-300.0..300.0);
189189
}
190190
```
191191

@@ -201,8 +201,8 @@ The obstacles need to move, too, so they appear to be on the road! In the `game
201201
if sprite.label.starts_with("obstacle") {
202202
sprite.translation.x -= ROAD_SPEED * engine.delta_f32;
203203
if sprite.translation.x < -800.0 {
204-
sprite.translation.x = thread_rng().gen_range(800.0..1600.0);
205-
sprite.translation.y = thread_rng().gen_range(-300.0..300.0);
204+
sprite.translation.x = rand::rng().random_range(800.0..1600.0);
205+
sprite.translation.y = rand::rng().random_range(-300.0..300.0);
206206
}
207207
}
208208
```

0 commit comments

Comments
 (0)