blob: 5e2ea1223460d8eb9c6ba7b7a8faf0a0f6064aaa (
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::*;
use hitbox::*;
use asset_id::*;
#[derive(Clone)]
pub struct Home {
pub pos: Vec2d,
pub animation_time: f64,
pub sprite: SpriteId
}
impl Home {
pub fn new(x: f64, y: f64) -> Home {
Home {
pos: Vec2d::new(x, y),
animation_time: 0.,
sprite: SpriteId::Sleepypug1
}
}
pub fn advance(&mut self, seconds: f64) {
let scale = 0.5;
self.animation_time = (self.animation_time + scale * seconds).fract();
self.sprite = if self.animation_time < 0.3 {
SpriteId::Sleepypug1
} else if self.animation_time < 0.4 {
SpriteId::Sleepypug2
} else if self.animation_time < 0.5 {
SpriteId::Sleepypug3
} else if self.animation_time < 0.8 {
SpriteId::Sleepypug4
} else if self.animation_time < 0.9 {
SpriteId::Sleepypug3
} else {
SpriteId::Sleepypug2
} ;
}
pub fn hitbox(&self) -> Hitbox {
Hitbox::Circle(CircleHitbox{
pos: self.pos, radius: 100.
})
}
}
|