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
pub const SURFACE_WIDTH:      usize = 512;
pub const SURFACE_HEIGHT:     usize = 512;
pub const SURFACE_PIXELS:     usize = SURFACE_WIDTH * SURFACE_HEIGHT;
pub const FRAMES_PER_SECOND:  usize = 60;

#[derive(Copy, Clone)]
pub struct Pixel {
  pub red:   u8,
  pub blue:  u8,
  pub green: u8,
}

pub struct Surface {
  pub pixels: [Pixel; SURFACE_PIXELS],
}

#[derive(Copy, Clone)]
pub enum Button {
  Left,
  Right,
  Up,
  Down,
  Action,
}

#[derive(Copy, Clone)]
pub enum Event {
  Down{button: Button},
  Up{button: Button},
}

pub struct Input {
  pub events: Vec<Event>,
}

pub struct Output {
  pub surface: Surface,
}

pub trait Game {
  fn new() -> Self;
  fn frame(&mut self, input: Input) -> Output;
}