Exemplo n.º 1
0
 //Assignment important variables
 void Awake()
 {
     mainCamera    = Camera.main;
     rb            = GetComponent <Rigidbody2D> ();
     rb.bodyType   = RigidbodyType2D.Static;
     carriableProp = GetComponent <carriableBehaviour> ();
 }
Exemplo n.º 2
0
 //Assignment of important variables
 void Awake()
 {
     if (toggleTorchLighting)
     {
         flameTimeBar = GameObject.FindGameObjectWithTag("ftTimer").GetComponentInChildren <Slider> ();
         flameTimeBar.gameObject.SetActive(false);
         doesExtinguish = true;
     }
     carriableProp = GetComponent <carriableBehaviour> ();
     fullyFueled   = true;
     isHeld        = false;
 }
Exemplo n.º 3
0
 //Assignment of important variables
 void Awake()
 {
     Collider2D[] Colliders = GetComponents <Collider2D> ();
     carriedProp = GetComponent <carriableBehaviour> ();
     //Sets solidBody to appropriate collider
     foreach (Collider2D collider in Colliders)
     {
         if (!collider.isTrigger)
         {
             solidBody = collider;
         }
     }
 }
Exemplo n.º 4
0
    void FixedUpdate()
    {
        //Get Input
        float inputX = Input.GetAxisRaw("Horizontal");
        float inputY = Input.GetAxisRaw("Vertical");

        if (canMove)
        {
            //if key is pressed on Horizontal save time it was pressed
            if (inputX != 0)
            {
                if (timeDownX == 0.0f) //if there is no stored time for it
                {
                    timeDownX = Time.time;
                }
            }
            else
            {
                timeDownX = 0.0f; // reset time if no button is being pressed
            }

            //if key is pressed on vertical save time it was pressed
            if (inputY != 0)
            {
                if (timeDownY == 0.0f) //if there is no stored time for it
                {
                    timeDownY = Time.time;
                }
            }
            else
            {
                timeDownY = 0.0f; // reset time if no button is being pressed
            }

            //check which button was hit last to determin direction
            velocity = Vector2.zero;
            if (timeDownX > timeDownY)
            {
                velocity = Vector2.right * inputX;
            }
            if (timeDownX < timeDownY)
            {
                velocity = Vector2.up * inputY;
            }

            //velocity = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized * moveSpeed;

            //Orientation
            int Quadrant = -1;
            if (inputX > 0)
            {
                Orientation     = Vector3.right;
                objSpriteHolder = ObjSprites[0];
                Quadrant        = 2;
            }
            else if (inputX < 0)
            {
                Orientation     = -Vector3.right;
                objSpriteHolder = ObjSprites[1];
                Quadrant        = 4;
            }
            else if (inputY > 0)
            {
                Orientation     = Vector3.up;
                objSpriteHolder = ObjSprites[2];
                Quadrant        = 1;
            }
            else if (inputY < 0)
            {
                Orientation     = -Vector3.up;
                objSpriteHolder = ObjSprites[3];
                Quadrant        = 3;
            }

            // Animations
            playerMoving = (Mathf.Abs(inputX) + Mathf.Abs(inputY)) > 0;
            anim.SetBool("PlayerMoving", playerMoving);
            if (Mathf.Abs(inputX) > 0 && Mathf.Abs(inputY) > 0)
            {
                velocity = Vector2.zero;
                anim.SetBool("PlayerMoving", false);
                playerMoving = false;
            }

            if (playerMoving)
            {
                anim.SetFloat("MoveX", inputX);
                anim.SetFloat("MoveY", inputY);
                if (!shouldAdjust)
                {
                    shouldAdjust = true;
                }
                if (objOrientation != null)
                {
                    objOrientation.setPoles(Quadrant);
                }
            }

            // Setting the veloctiy based on input
            if (movementException)
            {
                rbody.MovePosition(rbody.position + (offsetVector * (Time.fixedDeltaTime / distRatio)));
            }
            else
            {
                rbody.MovePosition(rbody.position + (velocity * moveSpeed) * Time.fixedDeltaTime);
            }

            //Appropriating local offset values of carried objects
            if (velocity != Vector2.zero)
            {
                //Setting carriedObject offset
                if (isCarryingObj)
                {
                    SpriteRenderer ObjRenderer = carriedObject.GetComponent <SpriteRenderer>();
                    ObjRenderer.sprite = objSpriteHolder;

                    carriableBehaviour brlCarriable = carriedObject.GetComponent <carriableBehaviour> ();
                    Vector3            brlOffset    = Orientation * brlCarriable.carriedOffset;
                    carriedObject.transform.localPosition = brlOffset;
                }
                //Setting torch offset
                if (isCarryingTorch)
                {
                    carriableBehaviour torchCarriable = Torch.GetComponent <carriableBehaviour> ();
                    Vector3            torchOffset    = Orientation * torchCarriable.carriedOffset;
                    Torch.transform.localPosition = torchOffset;
                }
            }
        }

        // [PROGRAMMER] nQ's Script [PROGRAMMER] Start
        //Bit-World Simulation via Positioning Modulo 1/5 units
        if (inputX == 0 && inputY == 0 && shouldAdjust)
        {
            if (Mathf.Abs(transform.position.x) % 0.20f != 0 || Mathf.Abs(transform.position.y) % 0.20f != 0)
            {
                //Calling IEnumerator declared below
                StartCoroutine(adjustPos());
                shouldAdjust = false;
            }
        }
        // [PROGRAMMER] nQ's Script [PROGRAMMER] Finish
    }