Changed hitboxed from an 'is a hitbox' to a 'has a hitbox'
[bug-basher.git] / src / entities / home.rs
1 use geometry::*;
2 use hitbox::*;
3 use asset_id::*;
4
5 #[derive(Clone)]
6 pub struct Home {
7     pub pos: Vec2d,
8     pub animation_time: f64,
9     pub sprite: SpriteId
10 }
11
12 impl Home {
13     pub fn new(x: f64, y: f64) -> Home {
14         Home {
15             pos: Vec2d::new(x, y),
16             animation_time: 0.,
17             sprite: SpriteId::Sleepypug1
18         }
19     }
20
21     pub fn advance(&mut self, seconds: f64) {
22         let scale = 0.5;
23         self.animation_time = (self.animation_time + scale * seconds).fract();
24         self.sprite = if self.animation_time < 0.3 {
25             SpriteId::Sleepypug1
26         } else if self.animation_time < 0.4 {
27             SpriteId::Sleepypug2
28         } else if self.animation_time < 0.5 {
29             SpriteId::Sleepypug3
30         } else if self.animation_time < 0.8 {
31             SpriteId::Sleepypug4
32         } else if self.animation_time < 0.9 {
33             SpriteId::Sleepypug3
34         } else {
35             SpriteId::Sleepypug2
36         } ;
37     }
38
39     pub fn hitbox(&self) -> Hitbox {
40         Hitbox::Circle(CircleHitbox{
41           pos: self.pos, radius: 100.  
42         })
43     }
44 }