summaryrefslogtreecommitdiff
path: root/src/entities/bug.rs
blob: b29930539ae1f4af2a79a2f4805c3077bc8c5008 (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
use geometry::*;
use hitbox::*;

#[derive(Debug, Clone)]
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) -> Bug {
        let pos = Vec2d::new(x, y);
        let pos_unit = pos.unit();
        Bug {
            pos,
            rotation: (-pos).angle(),
            velocity: -pos_unit * SPEED,
            alive: true
        }
    }

    pub fn advance(&mut self, seconds: f64) {
        self.pos = self.pos + self.velocity * seconds;
    }

    pub fn hitbox(&self) -> Hitbox {
        Hitbox::Circle(CircleHitbox{
          pos: self.pos, radius: 75.  
        })
    }
}