From db44f47368a1517faa8df4f4b5f0ff7ead3647ee Mon Sep 17 00:00:00 2001
From: ENGO150 <v.smejkal06@gmail.com>
Date: Wed, 17 May 2023 10:51:32 +0200
Subject: [PATCH] made turn right button avaible

---
 index.html    |  1 +
 res/script.js | 20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/index.html b/index.html
index 0827804..be3c9a5 100644
--- a/index.html
+++ b/index.html
@@ -16,5 +16,6 @@
     </div>
 
     <button onclick="turn_left()">Turn Left</button>
+    <button onclick="turn_right()">Turn Right</button>
 </body>
 </html>
\ No newline at end of file
diff --git a/res/script.js b/res/script.js
index c8358f9..ee02061 100644
--- a/res/script.js
+++ b/res/script.js
@@ -37,7 +37,7 @@ function turn_left()
     x1 -= WIDTH * MOVE_PIECES;
     x2 -= WIDTH * MOVE_PIECES;
 
-    if ((Math.abs(turn) - (1/MOVE_PIECES / 2)) >= 0)
+    if (turn < 0 && (Math.abs(turn) - (1/MOVE_PIECES / 2)) >= 0)
     {
         //ctx.drawImage(img, img.width - WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), 0, img.width, img.height, 0, 0, WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), WIDTH * ASPECT_RATIO); //DRAW RIGHT PART ON THE LEFT SIDE //TODO
 
@@ -47,4 +47,22 @@ function turn_left()
     ctx.drawImage(img, x1, 0, img.width - WIDTH * MOVE_PIECES, img.height, 0, 0, WIDTH, WIDTH * ASPECT_RATIO); //DRAW
 
     turn--;
+}
+
+function turn_right()
+{
+    //MOVE AN 8th TO LEFT
+    x1 += WIDTH * MOVE_PIECES;
+    x2 += WIDTH * MOVE_PIECES;
+
+    if (turn > 0 && (Math.abs(turn) - (1/MOVE_PIECES / 2)) >= 0)
+    {
+        //ctx.drawImage(img, img.width - WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), 0, img.width, img.height, 0, 0, WIDTH * MOVE_PIECES * (Math.abs(turn) - (1/MOVE_PIECES / 2)), WIDTH * ASPECT_RATIO); //DRAW RIGHT PART ON THE LEFT SIDE //TODO
+
+        return;
+    }
+
+    ctx.drawImage(img, x1, 0, img.width + WIDTH * MOVE_PIECES, img.height, 0, 0, WIDTH, WIDTH * ASPECT_RATIO); //DRAW
+
+    turn++;
 }
\ No newline at end of file