- commit
- cd5b337f2dd727dee5fa32279f55a3668a057cd5
- parent
- 8a3074b5fb0209454190dc6a2e8a53570b6daf97
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-02-19 17:03
read all available input on each loop
Diffstat
| M | src/main.rs | 28 | +++++++++++++++------------- |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
@@ -37,20 +37,22 @@ fn main() {
37 37 while RUNNING.load(Ordering::Relaxed) {
38 38 let time1 = time::Instant::now();
39 39
40 -1 match input.getch() {
41 -1 Some(b'w' | b'A') => game.player.dir = game::Dir::Up,
42 -1 Some(b'a' | b'D') => {
43 -1 game.player.dir = game::Dir::Left;
44 -1 game.player.face = game::Dir::Left
-1 40 while let Some(c) = input.getch() {
-1 41 match c {
-1 42 b'w' | b'A' => game.player.dir = game::Dir::Up,
-1 43 b'a' | b'D' => {
-1 44 game.player.dir = game::Dir::Left;
-1 45 game.player.face = game::Dir::Left
-1 46 }
-1 47 b's' | b'B' => game.player.dir = game::Dir::Down,
-1 48 b'd' | b'C' => {
-1 49 game.player.dir = game::Dir::Right;
-1 50 game.player.face = game::Dir::Right
-1 51 }
-1 52 b' ' => game.player.dir = game::Dir::Stop,
-1 53 b'q' => quit(0),
-1 54 _ => {}
45 55 }
46 -1 Some(b's' | b'B') => game.player.dir = game::Dir::Down,
47 -1 Some(b'd' | b'C') => {
48 -1 game.player.dir = game::Dir::Right;
49 -1 game.player.face = game::Dir::Right
50 -1 }
51 -1 Some(b' ') => game.player.dir = game::Dir::Stop,
52 -1 Some(b'q') => quit(0),
53 -1 _ => {}
54 56 }
55 57
56 58 game.step((time1 - time0).as_secs_f32());