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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Terminal Games: a scene-based game loop with keys, mouse, drawing and
//! random numbers. Everything except [`run`] is plain Rust with no terminal
//! access, so games can be tested and played headless.
//!
//! A game is a [`Game`] trait object. `update` runs 60 times a second and
//! returns a [`Next`] (stay, switch, push a pause, pop, quit); `draw` paints a
//! [`Screen`]. Here is a menu that switches to a game, played headless so the
//! example runs without a terminal. In a real program, `run(Menu)` plays it.
//!
//! ```
//! use terminal_graphics_interactive::game::*;
//!
//! struct Menu;
//! struct Play { score: u32 }
//!
//! impl Game for Menu {
//! fn update(&mut self, ctx: &mut Context<'_>) -> Next {
//! if ctx.keys.pressed(KeyCode::Enter) { Next::switch(Play { score: 0 }) } else { Next::stay() }
//! }
//! fn draw(&self, screen: &mut Screen) {
//! screen.text_centred(screen.height() / 2, "press Enter", Colour::White);
//! }
//! }
//!
//! impl Game for Play {
//! fn update(&mut self, _ctx: &mut Context<'_>) -> Next {
//! self.score += 1;
//! Next::stay()
//! }
//! fn draw(&self, screen: &mut Screen) {
//! screen.text(0, 0, &format!("score {}", self.score), Colour::Yellow);
//! }
//! }
//!
//! // In a real program: fn main() -> std::io::Result<()> { run(Menu) }
//! let mut game = Headless::new(Menu).size(20, 3);
//! assert!(game.text().contains("press Enter"));
//! game.tap(KeyCode::Enter);
//! game.step(60);
//! assert!(game.text().contains("score 61"));
//! ```
//!
//! The pieces:
//!
//! - [`Game`], [`Next`] and [`Context`]: a screen of your game, what happens
//! next, and what an update is given (keys, pointer, size, seed).
//! - [`run`]: the real loop on a terminal. Ctrl+C always quits; `q` and Esc
//! belong to the game.
//! - [`Headless`]: the same loop with no terminal, for tests and AI agents.
//! It reads what the game drew as text.
//! - [`Screen`] and [`Sprite`]: drawing. Text, fills, bars and pictures, all
//! clipped to the screen.
//! - [`Keys`] and [`Controls`]: which keys are pressed, held or released, and
//! named actions that players can rebind.
//! - [`Rng`], [`Timer`], [`Pool`] and [`Hit`]: random numbers, cooldowns,
//! fixed-size object lists and collision tests.
//! - [`Tuning`]: numbers a game exposes so they can be changed while it runs
//! (sliders on the website).
//!
//! The art modules are in scope too (`use terminal_graphics_interactive::game::*`
//! brings in `Palette`, `Pointer`, `sketch_frame`, `World`, `Display`, `Colour`
//! and the rest of the prelude).
pub use crate*;
pub use crate::;
pub use Context;
pub use Controls;
pub use Headless;
pub use Hit;
pub use Keys;
pub use ;
pub use ;
pub use PixelArt;
pub use Pool;
pub use Rng;
pub use run;
pub use ;
pub use Screen;
pub use Sprite;
pub use Timer;
pub use ;
pub use ;