diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-03-06 21:05:29 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-03-06 21:05:29 +0200 |
commit | 544c030b80d4d7b9a3b00711ff21b2592275a7e8 (patch) | |
tree | 2323fa63649fdaaec9e1cb5a278a81913969960c /src/entities/bug.rs | |
parent | 30df4064646fb429568474c0cdb2ee2ee08fd22e (diff) |
Bugs walking to the middle of the screen slowly
Diffstat (limited to 'src/entities/bug.rs')
-rw-r--r-- | src/entities/bug.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/entities/bug.rs b/src/entities/bug.rs index 6b39e8a..d2d5c2e 100644 --- a/src/entities/bug.rs +++ b/src/entities/bug.rs @@ -6,6 +6,8 @@ pub struct Bug { pub alive: bool } +const SPEED: f64 = 75.; + impl Bug { pub fn new(x: f64, y: f64, facing: f64) -> Bug { Bug { @@ -19,7 +21,13 @@ impl Bug { } pub fn advance(&mut self, seconds: f64) { - //TODO, add some motion + 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; } pub fn click(&mut self, point: Vec2d) { @@ -29,6 +37,8 @@ impl Bug { } fn touches(&self, point: Vec2d) -> bool { + let rx = 35.; + let ry = 16.; self.pos.distance(point) <= 45. // Some better hit box modelling might be nice? } } |