Made animated pug
[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 {
16                 x: x,
17                 y: y
18             },
19             animation_time: 0.,
20             sprite: SpriteId::Sleepypug1
21         }
22     }
23
24     pub fn advance(&mut self, seconds: f64) {
25         let scale = 0.5;
26         self.animation_time = (self.animation_time + scale * seconds).fract();
27         self.sprite = if self.animation_time < 0.3 {
28             SpriteId::Sleepypug1
29         } else if self.animation_time < 0.4 {
30             SpriteId::Sleepypug2
31         } else if self.animation_time < 0.5 {
32             SpriteId::Sleepypug3
33         } else if self.animation_time < 0.8 {
34             SpriteId::Sleepypug4
35         } else if self.animation_time < 0.9 {
36             SpriteId::Sleepypug3
37         } else {
38             SpriteId::Sleepypug2
39         } ;
40     }
41 }
42
43 impl CircleHitbox for Home {
44     fn pos(&self) -> Vec2d {
45         self.pos
46     }
47     fn radius(&self) -> f64 {
48         100.
49     }
50 }