From 05ae9cd13fee07e7653e3d616e812ccedba8f1b9 Mon Sep 17 00:00:00 2001 From: curly Date: Thu, 18 Aug 2022 11:56:43 -0600 Subject: input feels good + small tweaks --- src/lib.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 4c13b5f..2508f18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,8 +67,10 @@ impl Game { pub fn game_loop(&mut self) { // Textures - let background = Texture::from_file("assets/background.png").expect("Cannot load texture"); - let bit = Texture::from_file("assets/bit.png").expect("Cannot load texture"); + let mut background = Texture::from_file("assets/background.png").expect("Cannot load texture"); + background.set_smooth(false); + let mut bit = Texture::from_file("assets/bit.png").expect("Cannot load texture"); + bit.set_smooth(false); // Objects let mut background = RectangleShape::with_texture(&background); @@ -83,6 +85,7 @@ impl Game { // Timing let mut tick = Instant::now(); let mut fpscap = Instant::now(); + let mut key_count = 0; // Game setup let mut tetris = tetris::Tetris::new(); @@ -126,16 +129,34 @@ impl Game { // Reset the clock fpscap = Instant::now(); + // Process keys + // Limited keys + if key_count == 0 { + match key { + Some(Key::A) => {piece.r#move(tetris::piece::Dir::Left, &tetris)}, + Some(Key::D) => {piece.r#move(tetris::piece::Dir::Right, &tetris)}, + _ => () + } + } + //Process keys + // Unlimited keys match key { - Some(Key::A) => {piece.r#move(tetris::piece::Dir::Left, &tetris); key = None}, Some(Key::S) => piece.r#move(tetris::piece::Dir::Down, &tetris), - Some(Key::D) => {piece.r#move(tetris::piece::Dir::Right, &tetris); key = None}, Some(Key::Q) => {piece.rotate(tetris::piece::Rotate::Left, &tetris); key = None}, Some(Key::E) => {piece.rotate(tetris::piece::Rotate::Right, &tetris); key = None}, Some(Key::Escape) => break, _ => () } + // Make the limit feel good + if key != None { + key_count += 1; + } else { + key_count = 0; + } + if key_count > 2 { + key_count = 0; + } // Draw the background self.window.draw(&background); -- cgit v1.2.3