summaryrefslogtreecommitdiff
path: root/src/entities/bug.rs
diff options
context:
space:
mode:
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;
}
}