summaryrefslogtreecommitdiff
path: root/src/npc.rs
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2022-02-02 19:08:44 +0100
committerTom Barrett <tom@tombarrett.xyz>2022-02-02 19:08:44 +0100
commitceb3eff116f9ddf8dcb71a0a77efb63531f75ab2 (patch)
treec818ad7241797fa72e0cb802f09c9a1b296e1fb0 /src/npc.rs
parent8cdbe7352c4846eb339358bcca6083f747e27721 (diff)
2022 updateHEADmaster
Diffstat (limited to 'src/npc.rs')
-rw-r--r--src/npc.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/npc.rs b/src/npc.rs
index 729aecd..bc95b6f 100644
--- a/src/npc.rs
+++ b/src/npc.rs
@@ -1,6 +1,6 @@
use ggez::graphics::spritebatch::SpriteBatch;
-use ggez::nalgebra::{distance, Point2};
use ggez::Context;
+use glam::*;
use rand::Rng;
use std::f32::consts::PI;
use std::time::Instant;
@@ -57,7 +57,7 @@ impl NPC {
character: Character,
context: &mut Context,
tileset: &Tileset,
- spawn: Point2<f32>,
+ spawn: glam::Vec2,
map_dimensions: (f32, f32),
) -> NPC {
NPC {
@@ -69,10 +69,10 @@ impl NPC {
}
}
- fn move_torwards(&mut self, destination: Point2<f32>) {
+ fn move_torwards(&mut self, destination: glam::Vec2) {
let position = self.entity.position;
- if distance(&position, &destination) < constants::INTERACT_DISTANCE {
+ if glam::f32::Vec2::distance(position, destination) < constants::INTERACT_DISTANCE {
self.entity.action = Action::IdleRight;
self.behavior = Behavior::Waiting(Instant::now());
} else if (position.x - destination.x).abs() < constants::INTERACT_DISTANCE {
@@ -149,11 +149,11 @@ impl NPC {
enum Behavior {
Talking,
Waiting(Instant),
- Wandering(Point2<f32>),
+ Wandering(glam::Vec2),
}
-pub fn random_nearby_point(origin: Point2<f32>, within_radius: f32) -> Point2<f32> {
+pub fn random_nearby_point(origin: glam::Vec2, within_radius: f32) -> glam::Vec2 {
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())
+ glam::Vec2::new(origin.x + w * t.cos(), origin.y + w * t.sin())
}