From 448b5092206ccd9db760b00aeb9ab2233270bd6e Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Fri, 15 Dec 2023 17:55:59 +0000
Subject: [PATCH] Added damageable script + death animations

---
 Assets/Scripts/PlayerController.cs |   60 ++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
index 3381b36..4bf68d8 100644
--- a/Assets/Scripts/PlayerController.cs
+++ b/Assets/Scripts/PlayerController.cs
@@ -10,6 +10,12 @@
     public float maxFallSpeed = -20f;
     Vector2 moveInput;
 
+    Rigidbody2D rb;
+    Animator animator;
+    Animator animator_rotor;
+    public GameObject rotorGO;
+    TouchingDirections touchingDirections;
+
     [SerializeField]
     private bool _isMoving;
     public bool IsMoving
@@ -18,7 +24,7 @@
         private set
         {
             _isMoving = value;
-            animator.SetBool(AnimationStrings.Player.IsMoving, value);
+            animator.SetBool(AnimationStrings.Player.isMoving, value);
         }
     }
 
@@ -30,8 +36,8 @@
         private set
         {
             _isFlying = value;
-            animator.SetBool(AnimationStrings.Player.IsFlying, value);
-            rotorSprite.enabled = value;
+            animator.SetBool(AnimationStrings.Player.isFlying, value);
+            animator_rotor.SetBool(AnimationStrings.Player.isFlying, value);
         }
     }
 
@@ -40,37 +46,30 @@
     public bool IsFacingRight
     {
         get { return _isFacingRight; }
-        set { 
+        set
+        {
             if (_isFacingRight != value)
             {
                 transform.localScale *= new Vector2(-1, 1);
             }
-            _isFacingRight = value; }
+            _isFacingRight = value;
+        }
+    }
+
+    public bool CanMove { get
+        {
+            return animator.GetBool(AnimationStrings.canMove);
+        }
     }
 
 
-    Rigidbody2D rb;
-    Animator animator;
-    public GameObject rotorGO;
-    SpriteRenderer rotorSprite;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
         animator = GetComponent<Animator>();
-        rotorSprite = rotorGO.GetComponent<SpriteRenderer>();
-    }
-
-    // Start is called before the first frame update
-    void Start()
-    {
-
-    }
-
-    // Update is called once per frame
-    void Update()
-    {
-
+        animator_rotor = rotorGO.GetComponent<Animator>();
+        touchingDirections = GetComponent<TouchingDirections>();
     }
 
     private void FixedUpdate()
@@ -105,13 +104,22 @@
 
     public void OnMove(InputAction.CallbackContext context)
     {
-        moveInput = context.ReadValue<Vector2>();
+        if (CanMove)
+        {
+            moveInput = context.ReadValue<Vector2>();
 
-        IsMoving = moveInput.x != 0;
-        IsFlying = moveInput.y != 0;
+            IsMoving = moveInput.x != 0;
 
-        SetFacingDirection(moveInput);
+            IsFlying = (moveInput.y != 0);
 
+            SetFacingDirection(moveInput);
+        }
+        else
+        {
+            IsMoving = false;
+            IsFlying = false;
+            moveInput = Vector2.zero;
+        }
     }
 
     private void SetFacingDirection(Vector2 moveInput)

--
Gitblit v1.9.3