<commit_before>﻿using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D rgBody;
    [SerializeField]
    private float movementSpeed;
    [SerializeField]
    private float jumpSpeed;
    [SerializeField]
    private Transform[] groundedPoints;
    [SerializeField]
    private float rotationIntensity = 20;

    private Vector2 originalPosition;
    private Quaternion originalRotation;
    private int score;

    private bool rotating;

    void Start()
    {
        originalPosition = transform.position;
        originalRotation = transform.rotation;
        rgBody = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        float horizontalDirection = GetHorizontalDirection();
        HandleHorizontalMovement(horizontalDirection);
        HandleJump(horizontalDirection);
        if(rotating)
        {
            transform.Rotate(Vector3.forward * rotationIntensity);
        }
    }


    public void ResetPosition()
    {
        transform.position = originalPosition;
        transform.rotation = originalRotation;
        rotating = false;
    }

    public void Rotate()
    {
        rotating = true;
    }

    private float GetHorizontalDirection()
    {
        return Input.GetAxis("Horizontal") != 0 ? Input.GetAxis("Horizontal") : GetVimKeysIfPressed();
    }

    private float GetVimKeysIfPressed()
    {
        if(Input.GetKey("h"))
            return -1;
        return Input.GetKey("l") ? 1 : 0;
    }

    private void HandleHorizontalMovement(float horizontalDirection)
    {
        rgBody.velocity = new Vector2(horizontalDirection * movementSpeed, rgBody.velocity.y);
    }

    private void HandleJump(float horizontalDirection)
    {
        if(ShouldJump()){
            rgBody.velocity = new Vector2(horizontalDirection * movementSpeed, jumpSpeed);
        };
    }

    private bool ShouldJump()
    {
        return Input.GetButton("Jump") && rgBody.velocity.y == 0;
    }

    void OnTriggerEnter2D(Collider2D coll)
    {
        if (coll.gameObject.CompareTag(TagName.Coin))
        {
            score++;
            Destroy(coll.gameObject);
            GameObject.Find("Score").GetComponent<UnityEngine.UI.Text>().text = "Score: " + score;
        }
    }

}
<commit_msg>Player flips when turning<commit_after>﻿using UnityEngine;

public class PlayerController : MonoBehaviour
{
    private Rigidbody2D rgBody;
    [SerializeField]
    private float movementSpeed;
    [SerializeField]
    private float jumpSpeed;
    [SerializeField]
    private Transform[] groundedPoints;
    [SerializeField]
    private float rotationIntensity = 20;

    private Vector2 originalPosition;
    private Quaternion originalRotation;
    private int score;

    private bool rotating;
    private bool flipped = false;

    void Start()
    {
        originalPosition = transform.position;
        originalRotation = transform.rotation;
        rgBody = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        float horizontalDirection = GetHorizontalDirection();
        HandleHorizontalMovement(horizontalDirection);
        HandleJump(horizontalDirection);
        if(rotating)
        {
            transform.Rotate(Vector3.forward * rotationIntensity);
        }
    }


    public void ResetPosition()
    {
        transform.position = originalPosition;
        transform.rotation = originalRotation;
        rotating = false;
    }

    public void Rotate()
    {
        rotating = true;
    }

    private float GetHorizontalDirection()
    {
        return Input.GetAxis("Horizontal") != 0 ? Input.GetAxis("Horizontal") : GetVimKeysIfPressed();
    }

    private float GetVimKeysIfPressed()
    {
        if(Input.GetKey("h"))
            return -1;
        return Input.GetKey("l") ? 1 : 0;
    }

    private void HandleHorizontalMovement(float horizontalDirection)
    {
        HandleFlipping(horizontalDirection);
        rgBody.velocity = new Vector2(horizontalDirection * movementSpeed, rgBody.velocity.y);
    }

    private void HandleFlipping(float horizontalDirection)
    {
        if(horizontalDirection != 0)
        {
            bool facingRight = horizontalDirection >= 0;
            if(facingRight != flipped)
            {
                gameObject.GetComponent<SpriteRenderer>().flipX = !facingRight;
                flipped = facingRight;
            }
        }


    }

    private void HandleJump(float horizontalDirection)
    {
        if(ShouldJump()){
            rgBody.velocity = new Vector2(horizontalDirection * movementSpeed, jumpSpeed);
        };
    }

    private bool ShouldJump()
    {
        return Input.GetButton("Jump") && rgBody.velocity.y == 0;
    }

    void OnTriggerEnter2D(Collider2D coll)
    {
        if (coll.gameObject.CompareTag(TagName.Coin))
        {
            score++;
            Destroy(coll.gameObject);
            GameObject.Find("Score").GetComponent<UnityEngine.UI.Text>().text = "Score: " + score;
        }
    }

}

{'fraction_non_alphanumeric': 0.09278144371125775, 'fraction_numerical': 0.00639872025594881, 'mean_word_length': 2.419002050580998, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3932372', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1329, 'n_words': 272}