From ceb3eff116f9ddf8dcb71a0a77efb63531f75ab2 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Wed, 2 Feb 2022 19:08:44 +0100 Subject: 2022 update --- src/npc.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/npc.rs') 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, + spawn: glam::Vec2, map_dimensions: (f32, f32), ) -> NPC { NPC { @@ -69,10 +69,10 @@ impl NPC { } } - fn move_torwards(&mut self, destination: Point2) { + 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), + Wandering(glam::Vec2), } -pub fn random_nearby_point(origin: Point2, within_radius: f32) -> Point2 { +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()) } -- cgit v1.2.3