|
@@ -0,0 +1,73 @@
|
|
1
|
+// This file is generated automatically. Do not edit it directly.
|
|
2
|
+// See the Contributing section in README on how to make changes to it.
|
|
3
|
+use tcod::colors::*;
|
|
4
|
+use tcod::console::*;
|
|
5
|
+
|
|
6
|
+// actual size of the window
|
|
7
|
+const SCREEN_WIDTH: i32 = 80;
|
|
8
|
+const SCREEN_HEIGHT: i32 = 50;
|
|
9
|
+
|
|
10
|
+const LIMIT_FPS: i32 = 20; // 20 frames-per-second maximum
|
|
11
|
+
|
|
12
|
+struct Tcod {
|
|
13
|
+ root: Root,
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+fn handle_keys(tcod: &mut Tcod, player_x: &mut i32, player_y: &mut i32) -> bool {
|
|
17
|
+ use tcod::input::Key;
|
|
18
|
+ use tcod::input::KeyCode::*;
|
|
19
|
+
|
|
20
|
+ let key = tcod.root.wait_for_keypress(true);
|
|
21
|
+ match key {
|
|
22
|
+ Key {
|
|
23
|
+ code: Enter,
|
|
24
|
+ alt: true,
|
|
25
|
+ ..
|
|
26
|
+ } => {
|
|
27
|
+ // Alt+Enter: toggle fullscreen
|
|
28
|
+ let fullscreen = tcod.root.is_fullscreen();
|
|
29
|
+ tcod.root.set_fullscreen(!fullscreen);
|
|
30
|
+ }
|
|
31
|
+ Key { code: Escape, .. } => return true, // exit game
|
|
32
|
+
|
|
33
|
+ // movement keys
|
|
34
|
+ Key { code: Up, .. } => *player_y -= 1,
|
|
35
|
+ Key { code: Down, .. } => *player_y += 1,
|
|
36
|
+ Key { code: Left, .. } => *player_x -= 1,
|
|
37
|
+ Key { code: Right, .. } => *player_x += 1,
|
|
38
|
+
|
|
39
|
+ _ => {}
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ false
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+fn main() {
|
|
46
|
+ tcod::system::set_fps(LIMIT_FPS);
|
|
47
|
+
|
|
48
|
+ let root = Root::initializer()
|
|
49
|
+ .font("arial10x10.png", FontLayout::Tcod)
|
|
50
|
+ .font_type(FontType::Greyscale)
|
|
51
|
+ .size(SCREEN_WIDTH, SCREEN_HEIGHT)
|
|
52
|
+ .title("Rust/libtcod tutorial")
|
|
53
|
+ .init();
|
|
54
|
+
|
|
55
|
+ let mut tcod = Tcod { root };
|
|
56
|
+
|
|
57
|
+ let mut player_x = SCREEN_WIDTH / 2;
|
|
58
|
+ let mut player_y = SCREEN_HEIGHT / 2;
|
|
59
|
+
|
|
60
|
+ while !tcod.root.window_closed() {
|
|
61
|
+ tcod.root.set_default_foreground(WHITE);
|
|
62
|
+ tcod.root.clear();
|
|
63
|
+ tcod.root
|
|
64
|
+ .put_char(player_x, player_y, '@', BackgroundFlag::None);
|
|
65
|
+ tcod.root.flush();
|
|
66
|
+
|
|
67
|
+ // handle keys and exit game if needed
|
|
68
|
+ let exit = handle_keys(&mut tcod, &mut player_x, &mut player_y);
|
|
69
|
+ if exit {
|
|
70
|
+ break;
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+}
|