Browse Source

Merge branch 'mgedmin-patch-1'

Herbert Wolverson 4 years ago
parent
commit
7d3362950f

+ 2 - 0
book/src/SUMMARY.md

@@ -22,3 +22,5 @@
     - [Particle Effects](./chapter_18.md)
     - [Hunger Clock](./chapter_19.md)
     - [Magic Mapping](./chapter_20.md)
+
+[Contributors](./contributors.md)

+ 2 - 2
book/src/chapter_5.md

@@ -486,7 +486,6 @@ Our creation method also needs to know to add all false to it, just like before:
 
 ```rust
 if viewshed.dirty {
-    for t in map.visible_tiles.iter_mut() { *t = false };
     viewshed.dirty = false;
     viewshed.visible_tiles.clear();
     viewshed.visible_tiles = field_of_view(Point::new(pos.x, pos.y), viewshed.range, &*map);
@@ -494,6 +493,7 @@ if viewshed.dirty {
     // If this is the player, reveal what they can see
     let _p : Option<&Player> = player.get(ent);
     if let Some(_p) = _p {
+        for t in map.visible_tiles.iter_mut() { *t = false };
         for vis in viewshed.visible_tiles.iter() {
             let idx = map.xy_idx(vis.x, vis.y);
             map.revealed_tiles[idx] = true;
@@ -551,4 +551,4 @@ If you `cargo run` your project, you will now have visible tiles as slightly cya
 
 Copyright (C) 2019, Herbert Wolverson.
 
----
+---

+ 22 - 0
book/src/contributors.md

@@ -0,0 +1,22 @@
+# Contributors
+
+---
+
+***About this tutorial***
+
+*This tutorial is free and open source, and all code uses the MIT license - so you are free to do with it as you like. My hope is that you will enjoy the tutorial, and make great games!*
+
+*If you enjoy this and would like me to keep writing, please consider supporting [my Patreon](https://www.patreon.com/blackfuture).*
+
+---
+
+The following people have contributed to this project:
+
+* Herbert Wolverson, the primary author.
+* [Marius Gedminas](https://github.com/mgedmin) provided some fixes to the visibility system, and chapter 5.
+
+---
+
+Copyright (C) 2019, Herbert Wolverson.
+
+---

+ 1 - 1
chapter-05-fov/src/map.rs

@@ -115,7 +115,7 @@ impl BaseMap for Map {
     fn get_pathing_distance(&self, idx1:i32, idx2:i32) -> f32 {
         let p1 = Point::new(idx1 % self.width, idx1 / self.width);
         let p2 = Point::new(idx2 % self.width, idx2 / self.width);
-        rltk::distance2d(rltk::DistanceAlg::Pythagoras, p1, p2)
+        rltk::DistanceAlg::Pythagoras.distance2d(p1, p2)
     }
 }
 

+ 2 - 2
chapter-05-fov/src/visibility_system.rs

@@ -17,8 +17,7 @@ impl<'a> System<'a> for VisibilitySystem {
         let (mut map, entities, mut viewshed, pos, player) = data;
 
         for (ent,viewshed,pos) in (&entities, &mut viewshed, &pos).join() {
-            if viewshed.dirty {
-                for t in map.visible_tiles.iter_mut() { *t = false };
+            if viewshed.dirty {                
                 viewshed.dirty = false;
                 viewshed.visible_tiles.clear();
                 viewshed.visible_tiles = field_of_view(Point::new(pos.x, pos.y), viewshed.range, &*map);
@@ -26,6 +25,7 @@ impl<'a> System<'a> for VisibilitySystem {
                 // If this is the player, reveal what they can see
                 let _p : Option<&Player> = player.get(ent);
                 if let Some(_p) = _p {
+                    for t in map.visible_tiles.iter_mut() { *t = false };
                     for vis in viewshed.visible_tiles.iter() {
                         let idx = map.xy_idx(vis.x, vis.y);
                         map.revealed_tiles[idx] = true;

+ 1 - 1
chapter-06-monsters/src/map.rs

@@ -115,7 +115,7 @@ impl BaseMap for Map {
     fn get_pathing_distance(&self, idx1:i32, idx2:i32) -> f32 {
         let p1 = Point::new(idx1 % self.width, idx1 / self.width);
         let p2 = Point::new(idx2 % self.width, idx2 / self.width);
-        rltk::distance2d(rltk::DistanceAlg::Pythagoras, p1, p2)
+        rltk::DistanceAlg::Pythagoras.distance2d(p1, p2)
     }
 }