You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scenarios/car_shoot.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,18 +76,18 @@ In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-
76
76
1. Set `game_state.spawn_timer` to a new `Timer` with a random value between `0.1` and `1.25`
77
77
- Add the `rand` crate as a dependency in your `Cargo.toml`
78
78
- 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`
80
80
-[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`
81
81
1. If there are any cars left (check the value of `game_state.cars_left`), then:
82
82
1. Decrement `game_state.cars_left` by one
83
83
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"`
84
84
- Set the `value` to `format!("Cars left: {}", game_state.cars_left)`
85
85
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).
86
86
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()`
88
88
1. Actually create the sprite with the label and sprite preset selected above. Set the sprite's:
89
89
-`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)`
91
91
-`collision` to `true` so that the car will collide with marbles
92
92
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.
93
93
1. Define a `CAR_SPEED` constant and set it to `250.0`
Copy file name to clipboardExpand all lines: scenarios/road_race.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,8 +173,8 @@ Now it's time to add some obstacles. Interesting obstacles will be in random loc
173
173
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).
174
174
1. Set the sprite's `layer` to `5.0` so that the obstacle will be on top of road lines, but underneath the player.
175
175
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()`
0 commit comments