Skip to content

Commit

Permalink
Fix errors in guide
Browse files Browse the repository at this point in the history
  • Loading branch information
leudz committed Jul 10, 2024
1 parent 1919bbb commit d73a8b5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
1 change: 0 additions & 1 deletion guide/master/src/learn-by-example/breather.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn collision(mut player: UniqueViewMut<Player>, v_friend: View<Friend>) {
We can also handle the game over a little cleaner.

```rust,noplaypen
enum GameOver {
Defeat,
}
Expand Down
9 changes: 5 additions & 4 deletions guide/master/src/learn-by-example/friends.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use shipyard::{Component, World};
#[macroquad::main("Square Eater")]
async fn main() {
rand::srand(macroquad::miniquad::date::now() as u64);
// -- SNIP --
let mut world = World::new();
for _ in 0..5 {
Expand All @@ -48,8 +51,6 @@ fn render(player: &Player, world: &World) {
impl Friend {
fn new() -> Friend {
rand::srand(macroquad::miniquad::date::now() as u64);
let width = screen_width();
let height = screen_height();
Expand Down Expand Up @@ -115,7 +116,7 @@ fn render(world: &World) {
friend.0.render(GREEN);
}
let player = world.get_unique::<Player>().unwrap();
let player = world.get_unique::<&Player>().unwrap();
player.square.render(BLUE);
}
Expand All @@ -124,7 +125,7 @@ fn move_player(world: &World) {
let width = screen_width();
let height = screen_height();
let (x, y) = mouse_position();
let mut player = world.get_unique_mut::<Player>().unwrap();
let mut player = world.get_unique::<&mut Player>().unwrap();
player.square.x = x.clamp(0.0, width - player.square.size);
player.square.y = y.clamp(0.0, height - player.square.size);
Expand Down
7 changes: 6 additions & 1 deletion guide/master/src/learn-by-example/spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Let's infuse a bit of life into our friends.
```rust,noplaypen
use shipyard::{Component, IntoIter, Unique, UniqueView, UniqueViewMut, View, ViewMut, World};
const GROWTH_RATE: f32 = 0.15;
const MAX_SIZE: f32 = 25.0;
async fn main() {
// -- SNIP --
Expand All @@ -31,6 +34,8 @@ fn grow(mut vm_friend: ViewMut<Friend>) {
It appears our `Friend`s want to come close to the `Player`, likely to give them a hug.

```rust,noplaypen
const SPEED: f32 = 1.5;
async fn main() {
// -- SNIP --
Expand Down Expand Up @@ -104,7 +109,7 @@ async fn main() {
world.run(move_player);
world.run(move_friends);
world.run(grow);
world.run(collide);
world.run(collision);
world.run(render);
// -- SNIP --
Expand Down
20 changes: 18 additions & 2 deletions guide/master/src/learn-by-example/true-victory.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Let's give the `Player` a little bit of help and a way to win again.
In many games whenever the player is hit they'll turn invincible for a few frames.

```rust,noplaypen
async fn main() {
// -- SNIP --
let player = Player {
// -- SNIP --
i_counter: 0,
};
// -- SNIP --
}
struct Player {
// -- SNIP --
i_counter: u32,
Expand All @@ -64,16 +75,17 @@ impl Player {
}
}
fn collision(
entities: EntitiesView,
mut player: UniqueViewMut<Player>,
v_friend: View<Friend>,
v_power_pellets: View<PowerPellet>,
mut vm_to_delete: ViewMut<ToDelete>,
) -> Result<(), GameOver> {
// -- SNIP --
// -- SNIP --
if player.powered_up() {
// -- SNIP --
} else if player.is_invincible() {
continue;
}
Expand Down Expand Up @@ -102,6 +114,10 @@ use shipyard::{
async fn main() {
// -- SNIP --
for _ in 0..5 {
let _entity_id = world.add_entity(Friend::new());
}
world.add_workload(main_loop);
loop {
Expand Down

0 comments on commit d73a8b5

Please sign in to comment.