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
use error::AsteroidResult;
use graphics::Graphics;
use std::collections::HashMap;
pub struct Args {
dt: f64,
fps: f64,
keys: HashMap<::Keycode, bool>,
}
impl Args {
pub fn new() -> Self {
Args {
dt: 0.,
fps: 0.,
keys: HashMap::new(),
}
}
pub fn is_down(&self, key: ::Keycode) -> bool {
*self.keys.get(&key).unwrap_or(&false)
}
pub fn set_key_down(&mut self, key: ::Keycode) {
self.keys.insert(key, true);
}
pub fn set_key_up(&mut self, key: ::Keycode) {
self.keys.insert(key, false);
}
pub fn set_fps(&mut self, fps: f64) {
self.fps = fps;
}
pub fn set_dt(&mut self, dt: f64) {
self.dt = dt;
}
pub fn fps(&self) -> f64 {
self.fps
}
pub fn dt(&self) -> f64 {
self.dt
}
}
pub trait GameState {
fn update(&mut self, args: &Args) -> AsteroidResult;
fn render(&self, args: &Args, graphics: &mut Graphics) -> AsteroidResult;
#[allow(unused_variables)]
fn keyboard_input(&mut self, key: ::Keycode) -> AsteroidResult { AsteroidResult::Ok }
#[allow(unused_variables)]
fn mouse_move(&mut self, position: (f64, f64)) -> AsteroidResult { AsteroidResult::Ok }
#[allow(unused_variables)]
fn mouse_wheel(&mut self, scroll: f64) -> AsteroidResult { AsteroidResult::Ok }
fn mouse_input(&mut self ) -> AsteroidResult { AsteroidResult::Ok }
fn analog_input(&mut self ) -> AsteroidResult { AsteroidResult::Ok }
}