summaryrefslogtreecommitdiff
path: root/src/entities/bug.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-05-01 11:35:17 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-05-01 11:35:17 +0200
commit7a8fe60eb17d66771b153280b76546bcf46a9c7e (patch)
tree1db9435341da9765e088b99f89f6bb38bb1c6fef /src/entities/bug.rs
parent934efcccaa5a82f993c13c91511afe1943caa3b4 (diff)
Vector times scalar and unit vectors
Diffstat (limited to 'src/entities/bug.rs')
-rw-r--r--src/entities/bug.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/entities/bug.rs b/src/entities/bug.rs
index 913253c..f64669d 100644
--- a/src/entities/bug.rs
+++ b/src/entities/bug.rs
@@ -5,31 +5,29 @@ use hitbox::*;
pub struct Bug {
pub pos: Vec2d,
pub rotation: f64,
+ pub velocity: Vec2d,
pub alive: bool
}
const SPEED: f64 = 175.;
impl Bug {
- pub fn new(x: f64, y: f64, facing: f64) -> Bug {
+ pub fn new(x: f64, y: f64) -> Bug {
+ let pos = Vec2d {
+ x: x,
+ y: y
+ };
+ let pos_unit = pos.unit();
Bug {
- pos: Vec2d {
- x: x,
- y: y
- },
- rotation: facing,
+ pos: pos,
+ rotation: (-pos).angle(),
+ velocity: -pos_unit * SPEED,
alive: true
}
}
pub fn advance(&mut self, seconds: f64) {
- self.rotation = (-self.pos).angle();
- let distance = SPEED*seconds;
- let delta_pos = Vec2d {
- x: distance * self.rotation.cos(),
- y: distance * self.rotation.sin()
- };
- self.pos = self.pos + delta_pos;
+ self.pos = self.pos + self.velocity * seconds;
}
}