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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use geom::{Duration, Speed, Time};
use widgetry::{GeomBatch, GfxCtx};
pub struct Vehicle {
pub name: String,
pub normal_speed: Speed,
pub tired_speed: Speed,
pub max_energy: usize,
pub max_boost: Duration,
draw_frames: Vec<&'static str>,
scale: f64,
}
impl Vehicle {
pub fn get(name: &str) -> Vehicle {
match name {
"sleigh" => Vehicle {
name: "sleigh".to_string(),
normal_speed: Speed::miles_per_hour(30.0),
tired_speed: Speed::miles_per_hour(10.0),
max_energy: 80,
max_boost: Duration::seconds(5.0),
draw_frames: vec!["sleigh.svg"],
scale: 0.1,
},
"bike" => Vehicle {
name: "bike".to_string(),
normal_speed: Speed::miles_per_hour(40.0),
tired_speed: Speed::miles_per_hour(15.0),
max_energy: 50,
max_boost: Duration::seconds(8.0),
draw_frames: vec!["bike1.svg", "bike2.svg", "bike1.svg", "bike3.svg"],
scale: 0.05,
},
"cargo bike" => Vehicle {
name: "cargo bike".to_string(),
normal_speed: Speed::miles_per_hour(40.0),
tired_speed: Speed::miles_per_hour(5.0),
max_energy: 150,
max_boost: Duration::seconds(10.0),
draw_frames: vec![
"cargo_bike1.svg",
"cargo_bike2.svg",
"cargo_bike1.svg",
"cargo_bike3.svg",
],
scale: 0.05,
},
x => panic!("Don't know vehicle {}", x),
}
}
pub fn animate(&self, g: &mut GfxCtx, time: Time) -> GeomBatch {
let rate = 0.1;
let frame = (time.inner_seconds() / rate) as usize;
let path = format!(
"system/assets/santa/{}",
self.draw_frames[frame % self.draw_frames.len()]
);
GeomBatch::load_svg(g.prerender, &path).scale(self.scale)
}
}