From d73a8b526de447a0534ee0a206f877353bba9f95 Mon Sep 17 00:00:00 2001 From: leudz Date: Wed, 10 Jul 2024 22:22:41 +0200 Subject: [PATCH] Fix errors in guide --- guide/master/src/learn-by-example/breather.md | 1 - guide/master/src/learn-by-example/friends.md | 9 +++++---- guide/master/src/learn-by-example/spark.md | 7 ++++++- .../src/learn-by-example/true-victory.md | 20 +++++++++++++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/guide/master/src/learn-by-example/breather.md b/guide/master/src/learn-by-example/breather.md index 98663ccc..90dd48fc 100644 --- a/guide/master/src/learn-by-example/breather.md +++ b/guide/master/src/learn-by-example/breather.md @@ -50,7 +50,6 @@ fn collision(mut player: UniqueViewMut, v_friend: View) { We can also handle the game over a little cleaner. ```rust,noplaypen - enum GameOver { Defeat, } diff --git a/guide/master/src/learn-by-example/friends.md b/guide/master/src/learn-by-example/friends.md index cda26e63..6a50ce49 100644 --- a/guide/master/src/learn-by-example/friends.md +++ b/guide/master/src/learn-by-example/friends.md @@ -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 { @@ -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(); @@ -115,7 +116,7 @@ fn render(world: &World) { friend.0.render(GREEN); } - let player = world.get_unique::().unwrap(); + let player = world.get_unique::<&Player>().unwrap(); player.square.render(BLUE); } @@ -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::().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); diff --git a/guide/master/src/learn-by-example/spark.md b/guide/master/src/learn-by-example/spark.md index 79596426..2f674c6b 100644 --- a/guide/master/src/learn-by-example/spark.md +++ b/guide/master/src/learn-by-example/spark.md @@ -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 -- @@ -31,6 +34,8 @@ fn grow(mut vm_friend: ViewMut) { 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 -- @@ -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 -- diff --git a/guide/master/src/learn-by-example/true-victory.md b/guide/master/src/learn-by-example/true-victory.md index 83716f23..3c405944 100644 --- a/guide/master/src/learn-by-example/true-victory.md +++ b/guide/master/src/learn-by-example/true-victory.md @@ -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, @@ -64,7 +75,6 @@ impl Player { } } - fn collision( entities: EntitiesView, mut player: UniqueViewMut, @@ -72,8 +82,10 @@ fn collision( v_power_pellets: View, mut vm_to_delete: ViewMut, ) -> Result<(), GameOver> { - // -- SNIP -- + // -- SNIP -- + if player.powered_up() { + // -- SNIP -- } else if player.is_invincible() { continue; } @@ -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 {