From 314d4ec589295b44b46509a3672c78584bd7bbe2 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Mon, 26 Jul 2021 11:01:45 +0200
Subject: [PATCH] left/right animation

---
 .cargo/config.toml    |  2 +-
 .vscode/settings.json |  3 ++-
 src/main.rs           | 23 +++++++++++++++++++++--
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/.cargo/config.toml b/.cargo/config.toml
index 78a2572..d16c96b 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -14,7 +14,7 @@ rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y"]
 
 [target.x86_64-pc-windows-msvc]
 linker = "rust-lld.exe"
-rustflags = ["-Zshare-generics=y"]
+rustflags = ["-Zshare-generics=n"]
 
 # Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
 # In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
diff --git a/.vscode/settings.json b/.vscode/settings.json
index b3b64d4..819fe81 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,7 @@
 {
     "cSpell.ignoreWords": [
         "fixed",
-        "timestep"
+        "timestep",
+        "vsync"
     ]
 }
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 37c1d56..9111059 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,7 +8,9 @@ fn main() {
         .insert_resource(WindowDescriptor {
             title: "My Little Zombie".to_string(),
             width: 1920.,
-            height: 1081.,
+            height: 1080.,
+            vsync: true,
+            resizable: false,
             ..Default::default()
         })
         .add_startup_system(setup.system())
@@ -63,7 +65,7 @@ impl Default for Player {
     fn default() -> Self {
         Player {
             state: State::Idle,
-            index: 0,
+            index: 3,
         }
     }
 }
@@ -75,6 +77,7 @@ fn player_movement(
 ) {
     if let Ok((mut player, mut transform, mut sprite)) = query.single_mut() {
         let (index, state, dir) = if keyboard_input.pressed(KeyCode::Right) {
+            sprite.flip_x = false;
             match player.state {
                 // already walking
                 State::Right => {
@@ -89,6 +92,22 @@ fn player_movement(
                     (index, State::Right, 2.)
                 }
             }
+        } else if keyboard_input.pressed(KeyCode::Left) {
+            sprite.flip_x = true;
+            match player.state {
+                // already walking
+                State::Left => {
+                    let index = (player.index + 1) % 32;
+                    sprite.index = (4 * 9) + index / 4;
+                    (index, State::Left, -2.)
+                }
+                // starting walking
+                _ => {
+                    let index = 3 * 4;
+                    sprite.index = (4 * 9) + index / 4;
+                    (index, State::Left, -2.)
+                }
+            }
         } else {
             sprite.index = 0;
             (0, State::Idle, 0.)
-- 
GitLab