From fb7752427b32012b316872a3fb4e2554b0ca9b02 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Mon, 25 Dec 2023 22:40:59 +0000
Subject: [PATCH] Added drilling animation

---
 Assets/Scripts/PlayerController.cs |   94 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 81 insertions(+), 13 deletions(-)

diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
index 37838d6..953e277 100644
--- a/Assets/Scripts/PlayerController.cs
+++ b/Assets/Scripts/PlayerController.cs
@@ -25,12 +25,12 @@
     TouchingDirections touchingDirections;
 
     // Time it takes to drill
-    public float drillingTime = 1f;
+    private float drillingTime = 1f;
     private float timeSinceDrill = 0f;
     private bool drillToPosition;
     private Vector3 drillTilePosition;
     private Vector3 drillOriginalPosition;
-    
+
     [SerializeField]
     private bool _isMoving;
     public bool IsMoving
@@ -55,15 +55,63 @@
             animator_rotor.SetBool(AnimationStrings.Player.isFlying, value);
         }
     }
-    [SerializeField]
-    private bool _isDrilling;
     public bool IsDrilling
     {
-        get { return _isDrilling; }
+        get { return IsDrillingDown || IsDrillingLeftRight; }
         set
         {
-            _isDrilling = value;
-            //animator.SetBool(AnimationStrings.Player.isDrilling, value);
+            if (value)
+            {
+                Debug.Assert(false, "Can't set IsDrilling this way, use IsDrillingLeftRight or IsDrillingDown!");
+            }
+            if (IsDrillingDown)
+            {
+                IsDrillingDown = false;
+            }
+            if (IsDrillingLeftRight)
+            {
+                IsDrillingLeftRight = false;
+            }
+        }
+    }
+    [SerializeField]
+    private bool _isDrillingLeftRight;
+    public bool IsDrillingLeftRight
+    {
+        get { return _isDrillingLeftRight; }
+        set
+        {
+            _isDrillingLeftRight = value;
+            animator.SetBool(AnimationStrings.Player.isDrillingLeftRight, value);
+            animator_rotor.SetBool(AnimationStrings.Player.isFlying, false);
+            if (value)
+            {
+                animator.speed = 1 / drillingTime;
+            }
+            else
+            {
+                animator.speed = 1f;
+            }
+        }
+    }
+    [SerializeField]
+    private bool _isDrillingDown;
+    public bool IsDrillingDown
+    {
+        get { return _isDrillingDown; }
+        set
+        {
+            _isDrillingDown = value;
+            animator.SetBool(AnimationStrings.Player.isDrillingDown, value);
+            animator_rotor.SetBool(AnimationStrings.Player.isFlying, false);
+            if (value)
+            {
+                animator.speed = 1 / drillingTime;
+            }
+            else
+            {
+                animator.speed = 1f;
+            }
         }
     }
 
@@ -110,12 +158,17 @@
         boxCollider = GetComponent<BoxCollider2D>();
         if (SaveSystem.isGameLoaded)
         {
-            SaveData save = SaveSystem.LoadPlayer();
-            health.MaxHealth = save.maxHealth;
-            health.Health = save.health;
-            transform.position = VectorHelper.ConvertToVector3(save.position);
-            rb.velocity = VectorHelper.ConvertToVector2(save.velocity);
+            LoadPlayer();
         }
+    }
+
+    private void LoadPlayer()
+    {
+        SaveDataPlayer save = SaveSystem.LoadPlayer();
+        health.MaxHealth = save.maxHealth;
+        health.Health = save.health;
+        transform.position = VectorHelper.ConvertToVector3(save.position);
+        rb.velocity = VectorHelper.ConvertToVector2(save.velocity);
     }
 
     private void FixedUpdate()
@@ -240,12 +293,27 @@
             case DrillDirection.Down:
                 touchingDirections.groundHits[0].collider.GetContacts(contactPoints);
                 break;
+            default:
+                Debug.Assert(false, "Add DrillDirection here!");
+                break;
         }
         //Debug.Log(contactPoints[0].otherRigidbody?.gameObject.name);
         if (contactPoints[0].otherRigidbody?.name == "Tilemap")
         {
             boxCollider.enabled = false;
-            IsDrilling = true;
+            switch (drillDirection)
+            {
+                case DrillDirection.Left:
+                case DrillDirection.Right:
+                    IsDrillingLeftRight = true;
+                    break;
+                case DrillDirection.Down:
+                    IsDrillingDown = true;
+                    break;
+                default:
+                    Debug.Assert(false, "Add DrillDirection here!");
+                    break;
+            }
             CharacterEvents.characterDrill.Invoke(contactPoints[0], drillDirection);
         }
     }

--
Gitblit v1.9.3