Skip to content

Commit 75d2d3f

Browse files
committed
big round of doc updates
1 parent f21878e commit 75d2d3f

File tree

11 files changed

+117
-91
lines changed

11 files changed

+117
-91
lines changed

CHANGELOG.md

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

44
### Improved
55

6-
- Clarified the audio sections of the tutorial.
6+
- Made a pass through the API documentation and Tutorials, clarifying, correcting, and filling in blanks.
77

88
## [5.0.5] - 2022-05-10
99

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
If you like Rusty Engine, please sponsor me [on GitHub] or [on Patreon], or [take one of my courses](https://agileperception.com). 💖
2-
31
# Rusty Engine
42

53
Rusty Engine is a simple, 2D game engine for those who are learning Rust. Create simple game prototypes using straightforward Rust code without needing to learning difficult game engine concepts! It works on macOS, Linux, and Windows. Rusty Engine is a simplification wrapper over [Bevy], which I encourage you to use directly for more serious game engine needs.
@@ -8,6 +6,13 @@ Rusty Engine is a simple, 2D game engine for those who are learning Rust. Create
86

97
https://user-images.githubusercontent.com/5838512/122880590-651bae00-d2f7-11eb-8e5c-4810b3777828.mp4
108

9+
## Documentation
10+
11+
- [Tutorial](https://cleancut.github.io/rusty_engine/)
12+
- [API Reference](https://docs.rs/rusty_engine/latest/rusty_engine/)
13+
- [Code Examples](https://github.com/CleanCut/rusty_engine/tree/main/examples)
14+
- [Game Scenarios](https://github.com/CleanCut/rusty_engine/tree/main/scenarios)
15+
1116
## Features
1217

1318
- Asset pack included (sprites, music, sound effects, and fonts)
@@ -26,28 +31,25 @@ https://user-images.githubusercontent.com/5838512/122880590-651bae00-d2f7-11eb-8
2631

2732
## Courses
2833

34+
If you like Rusty Engine, please sponsor me [on GitHub] or [on Patreon], or take one of my courses below!
35+
2936
The following courses use Rusty Engine in their curriculum:
3037

3138
- [Ultimate Rust 2: Intermediate Concepts](https://www.udemy.com/course/ultimate-rust-2/?referralCode=8ED694EBE5637F954414) on Udemy (the sequel to [Ultimate Rust Crash Course](https://www.udemy.com/course/ultimate-rust-crash-course/?referralCode=AF30FAD8C6CCCC2C94F0))
3239
- [Rust in 3 Weeks](https://agileperception.com) conducted live on O'Reilly Online approximately once each quarter.
3340

34-
## Documentation
35-
36-
- [Rusty Engine Tutorial](https://cleancut.github.io/rusty_engine/)
37-
- [Rusty Engine API Reference](https://docs.rs/rusty_engine/latest/rusty_engine/)
38-
- [Game Scenarios](https://github.com/CleanCut/rusty_engine/tree/main/scenarios)
39-
4041
## Linux Dependencies (Including WSL 2)
4142

4243
If you are using Linux or Windows Subsystem for Linux 2, please visit Bevy's [Installing Linux Dependencies](https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md) page and follow the instructions to install needed dependencies.
4344

4445
## Quick Start
4546

4647
### You MUST download the assets separately!!!
48+
4749
Here are three different ways to download the assets (pick any of them--it should end up the same in the end):
4850
- Clone the `rusty_engine` repository and copy/move the `assets/` directory over to your own project
4951
- Download a [zip file](https://github.com/CleanCut/rusty_engine/archive/refs/heads/main.zip) or [tarball](https://github.com/CleanCut/rusty_engine/archive/refs/heads/main.tar.gz) of the `rusty_engine` repository, extract it, and copy/move the `assets/` directory over to your own project.
50-
- On a posix compatible shell, run this command inside your project directory:
52+
- (My favorite!) On a posix compatible shell, run this command inside your project directory:
5153
```shell
5254
curl -L https://github.com/CleanCut/rusty_engine/archive/refs/heads/main.tar.gz | tar -zxv --strip-components=1 rusty_engine-main/assets
5355
```
@@ -73,7 +75,7 @@ Write your game!
7375
fn main() {
7476
// Create a game
7577
let mut game = Game::new();
76-
// Set up your game. `Game` exposes all of the methods (but not fields) of `Engine` as well.
78+
// Set up your game. `Game` exposes all of the methods and fields of `Engine`.
7779
let sprite = game.add_sprite("player", SpritePreset::RacingCarBlue);
7880
sprite.scale = 2.0;
7981
game.audio_manager.play_music(MusicPreset::Classy8Bit, 1.0);
@@ -87,7 +89,7 @@ Write your game!
8789

8890
// Your game logic functions can be named anything, but the first parameter is always a
8991
// `&mut Engine`, and the second parameter is a mutable reference to your custom game
90-
// state struct (`&mut GameState` in this case). The function returns a `bool`.
92+
// state struct (`&mut GameState` in this case).
9193
//
9294
// This function will be run once each frame.
9395
fn game_logic(engine: &mut Engine, game_state: &mut GameState) {
@@ -101,15 +103,14 @@ Write your game!
101103
game_state.health -= 1;
102104
}
103105
}
104-
105106
```
106107

107108
Run your game with `cargo run --release`!
108109

109110
<img width="1348" alt="example screenshot" src="https://user-images.githubusercontent.com/5838512/146858022-1d91c7f4-8b21-4f85-a72a-c4b93edcabc6.png">
110111

111112

112-
See also the [game scenarios](https://github.com/CleanCut/rusty_engine/tree/main/scenarios), [code examples](https://github.com/CleanCut/rusty_engine/tree/main/examples) and the [API documentation](https://docs.rs/rusty_engine/latest/rusty_engine/)
113+
See also the [tutorial](https://cleancut.github.io/rusty_engine/), [game scenarios](https://github.com/CleanCut/rusty_engine/tree/main/scenarios), [code examples](https://github.com/CleanCut/rusty_engine/tree/main/examples) and the [API documentation](https://docs.rs/rusty_engine/latest/rusty_engine/)
113114

114115
## Contribution
115116

src/audio.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Facilities for interacting with audio, including: [`AudioManager`], [`MusicPreset`], and
22
//! [`SfxPreset`]
33
//!
4-
//! You may add your own sound files to the `assets/audio` directory or any of its subdirectories
4+
//! You may add your own sound files to the `assets/` directory or any of its subdirectories
55
//! and play them as sound effects or music by providing the relative path to the file. For example,
6-
//! if you place a file named `my_sound_effect.mp3` in this directory, you could play it with:
6+
//! if you place a file named `my_sound_effect.mp3` in `assets/`, you can play it with:
77
//!
88
//! ```rust,no_run
99
//! # use rusty_engine::prelude::*;
@@ -16,7 +16,8 @@
1616
//! # }
1717
//! ```
1818
//!
19-
//! Or, if you create a `my_game/` subdirectory and place a file named `spooky_loop.ogg`, you could play it as continuous music with:
19+
//! Or, if you create a `assets/my_game/` subdirectory and place a file named `spooky_loop.ogg`, you
20+
//! could play it as continuous music with:
2021
//!
2122
//! ```rust,no_run
2223
//! # use rusty_engine::prelude::*;
@@ -29,7 +30,8 @@
2930
//! # }
3031
//! ```
3132
//!
32-
//! The sound effects provided in this asset pack have convenient `enum`s defined that you can use instead of a path to the file: `SfxPreset` and `MusicPreset`. For example:
33+
//! The sound effects provided in this asset pack have convenient `enum`s defined that you can use
34+
//! instead of a path to the file: `SfxPreset` and `MusicPreset`. For example:
3335
//!
3436
//! ```rust,no_run
3537
//! // Import the enums into scope first
@@ -60,9 +62,10 @@ impl Plugin for AudioManagerPlugin {
6062
}
6163
}
6264

63-
/// You will interact with a [`AudioManager`] for all audio needs in Rusty Engine. It is exposed
65+
/// You will interact with the [`AudioManager`] for all audio needs in Rusty Engine. It is exposed
6466
/// through the [`Engine`](crate::prelude::Engine) struct provided to your logic function
65-
/// each frame as the [`audio_manager`](crate::prelude::Engine::audio_manager) field.
67+
/// each frame as the [`audio_manager`](crate::prelude::Engine::audio_manager) field. It is also
68+
/// accessible through the [`Game`](crate::prelude::Game) struct in your `main` function.
6669
#[derive(Default)]
6770
pub struct AudioManager {
6871
sfx_queue: Vec<(String, f32)>,
@@ -83,7 +86,7 @@ impl Debug for AudioManager {
8386

8487
impl AudioManager {
8588
/// Play a sound effect. `volume` ranges from `0.0` to `1.0`. `sfx` can be an [`SfxPreset`] or a
86-
/// string containing the relative path/filename of a sound file within the `assets/audio`
89+
/// string containing the relative path/filename of a sound file within the `assets/`
8790
/// directory. Sound effects are "fire and forget". They will play to completion and then stop.
8891
/// Multiple sound effects will be mixed and play simultaneously.
8992
pub fn play_sfx<S: Into<String>>(&mut self, sfx: S, volume: f32) {
@@ -92,7 +95,7 @@ impl AudioManager {
9295
/// Play looping music. `volume` ranges from `0.0` to `1.0`. Music will loop until stopped with
9396
/// [`stop_music`](AudioManager::stop_music). Playing music stops any previously playing music.
9497
/// `music` can be a [`MusicPreset`] or a string containing the relative path/filename of a
95-
/// sound file within the `assets/audio` directory.
98+
/// sound file within the `assets/` directory.
9699
pub fn play_music<S: Into<String>>(&mut self, music: S, volume: f32) {
97100
self.music_playing = true;
98101
self.music_queue
@@ -224,7 +227,7 @@ impl From<MusicPreset> for String {
224227
}
225228
}
226229

227-
// The Bevy system that checks and see if there is any audio management that needs to be done.
230+
/// The Bevy system that checks to see if there is any audio management that needs to be done.
228231
#[doc(hidden)]
229232
pub fn queue_managed_audio_system(
230233
asset_server: Res<AssetServer>,

src/game.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,21 @@ use crate::{
3131
// Public re-export
3232
pub use bevy::window::{WindowDescriptor, WindowMode, WindowResizeConstraints};
3333

34-
/// Engine is the primary way that you will interact with Rusty Engine. Every frame this struct
35-
/// is provided to the "logic" function (or closure) that you provided to [`Game::run`]. The
34+
/// Engine is the primary way that you will interact with Rusty Engine. Each frame this struct
35+
/// is provided to the "logic" functions (or closures) that you provided to [`Game::add_logic`]. The
3636
/// fields in this struct are divided into two groups:
3737
///
3838
/// 1. `SYNCED` fields.
3939
///
4040
/// These fields are marked with `SYNCED`. These fields are shared between you and the engine. Each
4141
/// frame Rusty Engine will populate these fields, then provide them to the user's game logic
4242
/// function, and then examine any changes the user made and sync those changes back to the engine.
43-
/// There are dedicated methods to create items for these fields.
4443
///
4544
/// 2. `INFO` fields
4645
///
4746
/// INFO fields are provided as fresh, readable information to you each frame. Since information in
48-
/// these fields are overwritten every frame, any changes are ignored. Thus, you can feel free to,
49-
/// e.g. consume all the events out of the `collision_events` vector.
47+
/// these fields are overwritten every frame, any changes to them are ignored. Thus, you can feel
48+
/// free to, e.g. consume all the events out of the `collision_events` vector.
5049
#[derive(Default, Debug)]
5150
pub struct Engine {
5251
/// SYNCED - The state of all sprites this frame. To add a sprite, use the
@@ -62,8 +61,10 @@ pub struct Engine {
6261
// so we can tell if the value changed this frame
6362
last_show_colliders: bool,
6463
/// INFO - All the collision events that occurred this frame. For collisions to be generated
65-
/// between sprites, both sprites must have [`Sprite.collision`] set to `true`. Collision events
66-
/// are generated when two sprites' colliders begin or end overlapping in 2D space.
64+
/// between sprites, both sprites must have [`Sprite.collision`] set to `true` and both sprites
65+
/// must have colliders (use the collider example to create a collider for your own images).
66+
/// Collision events are generated when two sprites' colliders begin or end overlapping in 2D
67+
/// space.
6768
pub collision_events: Vec<CollisionEvent>,
6869
/// INFO - The current state of mouse location and buttons. Useful for input handling that only
6970
/// cares about the final state of the mouse each frame, and not the intermediate states.
@@ -105,15 +106,17 @@ pub struct Engine {
105106
pub time_since_startup_f64: f64,
106107
/// A struct with methods to play sound effects and music
107108
pub audio_manager: AudioManager,
108-
/// INFO - Window dimensions in logical pixels
109+
/// INFO - Window dimensions in logical pixels. On high DPI screens, there will often be four
110+
/// physical pixels per logical pixel. On low DPI screens, one logical pixel is one physical
111+
/// pixel.
109112
pub window_dimensions: Vec2,
110113
}
111114

112115
impl Engine {
113116
#[must_use]
114-
/// Add an [`Sprite`]. Use the `&mut Sprite` that is returned to set the translation, rotation,
115-
/// etc. Use a unique label for each sprite. Attempting to add two sprites with the same label
116-
/// will crash.
117+
/// Create and add a [`Sprite`] to the game. Use the `&mut Sprite` that is returned to adjust
118+
/// the translation, rotation, etc. Use a *unique* label for each sprite. Attempting to add two
119+
/// sprites with the same label will cause a crash.
117120
pub fn add_sprite<T: Into<String>, P: Into<PathBuf>>(
118121
&mut self,
119122
label: T,
@@ -127,9 +130,9 @@ impl Engine {
127130
}
128131

129132
#[must_use]
130-
/// Add a [`Text`]. Use the `&mut Text` that is returned to set the translation, rotation, etc.
131-
/// Use a unique label for each text. Attempting to add two texts with the same label will
132-
/// crash.
133+
/// Create and add a [`Text`] to the game. Use the `&mut Text` that is returned to adjust the
134+
/// translation, rotation, etc. Use a *unique* label for each text. Attempting to add two texts
135+
/// with the same label will cause a crash.
133136
pub fn add_text<T, S>(&mut self, label: T, text: S) -> &mut Text
134137
where
135138
T: Into<String>,
@@ -148,13 +151,14 @@ impl Engine {
148151
}
149152
}
150153

151-
// startup system - grab window settings, initialize all the starting sprites
154+
/// startup system - grab window settings, initialize all the starting sprites
152155
#[doc(hidden)]
153156
pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut engine: ResMut<Engine>) {
154157
add_sprites(&mut commands, &asset_server, &mut engine);
155158
add_texts(&mut commands, &asset_server, &mut engine);
156159
}
157160

161+
/// Add visible lines representing a collider
158162
fn add_collider_lines(commands: &mut Commands, sprite: &mut Sprite) {
159163
// Add the collider lines, a visual representation of the sprite's collider
160164
let points = sprite.collider.points(); // will be empty vector if NoCollider
@@ -180,7 +184,7 @@ fn add_collider_lines(commands: &mut Commands, sprite: &mut Sprite) {
180184
sprite.collider_dirty = false;
181185
}
182186

183-
// helper function: Add Bevy components for all the sprites in engine.sprites
187+
/// helper function: Add Bevy components for all the sprites in engine.sprites
184188
#[doc(hidden)]
185189
pub fn add_sprites(commands: &mut Commands, asset_server: &Res<AssetServer>, engine: &mut Engine) {
186190
for (_, sprite) in engine.sprites.drain() {
@@ -223,7 +227,7 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
223227
}
224228
}
225229

226-
// system - update current window dimensions in the engine, because people resize windows
230+
/// system - update current window dimensions in the engine, because people resize windows
227231
#[doc(hidden)]
228232
pub fn update_window_dimensions(windows: Res<Windows>, mut engine: ResMut<Engine>) {
229233
// Unwrap: If we can't access the primary window...there's no point to running Rusty Engine
@@ -235,7 +239,7 @@ pub fn update_window_dimensions(windows: Res<Windows>, mut engine: ResMut<Engine
235239
}
236240
}
237241

238-
// Component to add to the collider lines visualizations to link them to the sprite they represent
242+
/// Component to add to the collider lines visualizations to link them to the sprite they represent
239243
#[derive(Component)]
240244
#[doc(hidden)]
241245
pub struct ColliderLines {
@@ -244,11 +248,11 @@ pub struct ColliderLines {
244248

245249
/// A [`Game`] represents the entire game and its data.
246250
/// By default the game will spawn an empty window, and exit upon Esc or closing of the window.
247-
/// Under the hood, Rusty Engine syncs the game data to Bevy to power most of the underlying
248-
/// functionality.
251+
/// Under the hood, Rusty Engine syncs the game data to [Bevy](https://bevyengine.org/) to power
252+
/// most of the underlying functionality.
249253
///
250254
/// [`Game`] forwards method calls to [`Engine`] when it can, so you should be able to use all
251-
/// of the methods in [`Engine`] on [`Game`] during your game setup in your `main()` function.
255+
/// of the methods from [`Engine`] on [`Game`] during your game setup in your `main()` function.
252256
pub struct Game<S: Send + Sync + 'static> {
253257
app: App,
254258
engine: Engine,
@@ -271,7 +275,7 @@ impl<S: Send + Sync + 'static> Default for Game<S> {
271275
}
272276

273277
impl<S: Send + Sync + 'static> Game<S> {
274-
/// Create an empty [`Game`] with an empty [`Engine`]
278+
/// Create an new, empty [`Game`] with an empty [`Engine`]
275279
pub fn new() -> Self {
276280
if std::fs::read_dir("assets").is_err() {
277281
println!("FATAL: Could not find assets directory. Have you downloaded the assets?\nhttps://github.com/CleanCut/rusty_engine#you-must-download-the-assets-separately");
@@ -323,18 +327,17 @@ impl<S: Send + Sync + 'static> Game<S> {
323327
self.app.run();
324328
}
325329

326-
/// `logic_function` is a function or closure that takes two parameters:
330+
/// `logic_function` is a function or closure that takes two parameters and returns nothing:
327331
///
328332
/// - `engine: &mut Engine`
329-
/// - `game_state`, which is a mutable reference (`&mut`) to the game state struct you defined, or `&mut ()` if you didn't define one.
330-
///
331-
/// If `false` is returned, no more logic functions are processed this frame.
333+
/// - `game_state`, which is a mutable reference (`&mut`) to the game state struct you defined,
334+
/// or `&mut ()` if you didn't define one.
332335
pub fn add_logic(&mut self, logic_function: fn(&mut Engine, &mut S)) {
333336
self.logic_functions.push(logic_function);
334337
}
335338
}
336339

337-
// system - the magic that connects Rusty Engine to Bevy, frame by frame
340+
/// system - the magic that connects Rusty Engine to Bevy, frame by frame
338341
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
339342
fn game_logic_sync<S: Send + Sync + 'static>(
340343
mut commands: Commands,
@@ -359,15 +362,6 @@ fn game_logic_sync<S: Send + Sync + 'static>(
359362
engine.time_since_startup = time.time_since_startup();
360363
engine.time_since_startup_f64 = time.seconds_since_startup();
361364

362-
// TODO: Transfer any changes to the Bevy components by the physics system over to the Sprites
363-
// for (mut sprite, mut transform) in sprite_query.iter_mut() {
364-
// sprite.translation = Vec2::from(transform.translation);
365-
// sprite.layer = transform.translation.z;
366-
// // transform.rotation = Quat::from_axis_angle(Vec3::Z, sprite.rotation);
367-
// sprite.rotation = ???
368-
// sprite.scale = transform.scale.x;
369-
// }
370-
371365
// Copy keyboard state over to engine to give to users
372366
engine.keyboard_state = keyboard_state.clone();
373367

0 commit comments

Comments
 (0)