summaryrefslogtreecommitdiff
path: root/src/npc.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-05 02:50:38 -0500
committertom barrett <spalf0@gmail.com>2019-07-05 02:50:38 -0500
commit6589e5e3df63d5abf85313c4d21097432257f453 (patch)
treed53635ead10c9fa9dc951045eff9e31977457f8c /src/npc.rs
parent83ff2ad49e6d3bf83fd85fcfee68a454372bf22a (diff)
removed math, operable to map and layers, on the way to merging tile and frame
Diffstat (limited to 'src/npc.rs')
-rw-r--r--src/npc.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/npc.rs b/src/npc.rs
index 9316e69..c31f305 100644
--- a/src/npc.rs
+++ b/src/npc.rs
@@ -1,5 +1,7 @@
use ggez::graphics::spritebatch::SpriteBatch;
use ggez::nalgebra::Point2;
+use rand::Rng;
+use std::f32::consts::PI;
use crate::animations::Animations;
use crate::entity::{Entity, Operable};
@@ -83,3 +85,9 @@ enum Behavior {
//Waiting(Instant),
Wandering(Option<Point2<f32>>),
}
+
+pub fn random_nearby_point(origin: Point2<f32>, within_radius: f32) -> Point2<f32> {
+ let w = within_radius * rand::thread_rng().gen_range(0.0, 1.0);
+ let t = 2.0 * PI * rand::thread_rng().gen_range(0.0, 1.0);
+ Point2::new(origin.x + w * t.cos(), origin.y + w * t.sin())
+}