summaryrefslogtreecommitdiff
path: root/src/entities/bug.rs
blob: d2d5c2ee0a3b9d5d6fe7f1138ca85ccd593d8e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use geometry::*;

pub struct Bug {
    pub pos: Vec2d,
    pub rotation: f64,
    pub alive: bool
}

const SPEED: f64 = 75.;

impl Bug {
    pub fn new(x: f64, y: f64, facing: f64) -> Bug {
        Bug {
            pos: Vec2d {
                x: x,
                y: y
            },
            rotation: facing,
            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;
    }

    pub fn click(&mut self, point: Vec2d) {
        if self.touches(point) {
            self.alive = false;
        }
    }

    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?
    }
}