Exemplo n.º 1
0
    void KeyboardInputCheck()
    {
        if (Input.GetKeyDown(KeyCode.Keypad7) || Input.GetKeyDown(KeyCode.Q))
        {
            //this.transform.position = new Vector3(this.transform.position.x - xFactor  , this.transform.position.y + yFactor, 0);
            Blocks block =
                FindBlockAtPosition(new Vector3(transform.position.x - xFactor, transform.position.y + yFactor, 0f));
            SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
            if (block != null)
            {
                //Debug.Log("I move to a block!");
                MoveAlongBezierCurve(this.transform.position,
                                     new Vector2(block.transform.position.x, block.transform.position.y + 0.5f));
                BlockMovingTo = block;
                SoundManagerReference.Play_QbertJump_Src();
            }
            else
            {
                //Debug.Log("No Block to move, checking for elevator");
                Elevator_Script Elevator = FindElevatorAtPosition();
                if (Elevator != null)
                {
                    MoveAlongBezierCurve(this.transform.position,
                                         new Vector2(Elevator.transform.position.x, Elevator.transform.position.y + 0.2f));
                    ElevatorMovingTo = Elevator;

                    // Activate Coily death here
                    CoilyBlockToDieFrom     = new Vector3(this.transform.position.x, this.transform.position.y - 0.2f, 0);
                    Coily_Script.CoilyDeath = true;
                    collider.enabled        = false;
                }
                else
                {
                    Debug.Log("Die elevator die left ");
                    Qbert_Dead  = true;
                    deathByFall = true;
                    tempPositionForJumpingEffect = new Vector2(transform.position.x - xFactor, transform.position.y + yFactor);
                    MoveAlongBezierCurve(transform.position, tempPositionForJumpingEffect);
                    deadPositionForBezierCurve = new Vector2(transform.position.x, deadzoneY);
                    // changing sorting order to make it look more realistic
                    this.spriteRenderer.sortingOrder = -1;
                    SoundManagerReference.Play_QbertFall_Src();
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.Keypad9) || Input.GetKeyDown(KeyCode.W))
        {
            // Debug.Log("Right Up");
            // this.transform.position = new Vector3(this.transform.position.x + xFactor, this.transform.position.y + yFactor, 0);

            Blocks block =
                FindBlockAtPosition(new Vector3(transform.position.x + xFactor, transform.position.y + yFactor, 0f));
            SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
            if (block != null)
            {
                //Debug.Log("I move to a block!");
                MoveAlongBezierCurve(this.transform.position,
                                     new Vector2(block.transform.position.x, block.transform.position.y + 0.5f));
                BlockMovingTo = block;
                SoundManagerReference.Play_QbertJump_Src();
            }
            else
            {
                //Debug.Log("No Block to move");
                Elevator_Script Elevator = FindElevatorAtPosition();
                if (Elevator != null)
                {
                    MoveAlongBezierCurve(this.transform.position,
                                         new Vector2(Elevator.transform.position.x, Elevator.transform.position.y + 0.2f));
                    ElevatorMovingTo = Elevator;

                    // Activate Coily death here
                    CoilyBlockToDieFrom     = new Vector3(this.transform.position.x, this.transform.position.y - 0.2f, 0);
                    Coily_Script.CoilyDeath = true;
                    collider.enabled        = false;
                }
                else
                {
                    Debug.Log("Die elevator die Right");
                    Qbert_Dead  = true;
                    deathByFall = true;
                    tempPositionForJumpingEffect = new Vector2(transform.position.x + xFactor, transform.position.y + yFactor);
                    MoveAlongBezierCurve(transform.position, tempPositionForJumpingEffect);
                    deadPositionForBezierCurve       = new Vector2(transform.position.x, deadzoneY);
                    this.spriteRenderer.sortingOrder = -1;
                    SoundManagerReference.Play_QbertFall_Src();
                }
            }

            //MoveAlongBezierCurve(this.transform.position,
            //   new Vector2(this.transform.position.x + xFactor, this.transform.position.y + yFactor));
            SpriteSwitchCase = SpriteJumpDirection.JumpTopRight;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad3) || Input.GetKeyDown(KeyCode.S))
        {
            Blocks block =
                FindBlockAtPosition(new Vector3(transform.position.x + xFactor, transform.position.y - yFactor, 0f));
            SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
            if (block != null)
            {
                //Debug.Log("I move to a block!");
                MoveAlongBezierCurve(this.transform.position,
                                     new Vector2(block.transform.position.x, block.transform.position.y + 0.5f));
                BlockMovingTo = block;
                SoundManagerReference.Play_QbertJump_Src();
            }
            else
            {
                Debug.Log("No Block to move Die Qbert");
                Qbert_Dead  = true;
                deathByFall = true;
                tempPositionForJumpingEffect = new Vector2(transform.position.x + xFactor, transform.position.y - yFactor);
                MoveAlongBezierCurve(transform.position, tempPositionForJumpingEffect);
                deadPositionForBezierCurve = new Vector2(transform.position.x, deadzoneY);
                SoundManagerReference.Play_QbertFall_Src();
            }


            //MoveAlongBezierCurve(this.transform.position,
            // new Vector2(this.transform.position.x + xFactor, this.transform.position.y - yFactor));
            SpriteSwitchCase = SpriteJumpDirection.JumpBottomRight;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad1) || Input.GetKeyDown(KeyCode.A))
        {
            //Debug.Log("Left Down");
            // this.transform.position = new Vector3(this.transform.position.x - xFactor, this.transform.position.y - yFactor, 0);

            Blocks block =
                FindBlockAtPosition(new Vector3(transform.position.x - xFactor, transform.position.y - yFactor, 0f));

            SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;

            if (block != null)
            {
                //Debug.Log("I move to a block!");
                MoveAlongBezierCurve(this.transform.position,
                                     new Vector2(block.transform.position.x, block.transform.position.y + 0.5f));
                BlockMovingTo = block;
                SoundManagerReference.Play_QbertJump_Src();
            }
            else
            {
                Debug.Log("No Block to move Die Qbert");
                Qbert_Dead  = true;
                deathByFall = true;
                tempPositionForJumpingEffect = new Vector2(transform.position.x - xFactor, transform.position.y - yFactor);
                MoveAlongBezierCurve(transform.position, tempPositionForJumpingEffect);
                deadPositionForBezierCurve = new Vector2(transform.position.x, deadzoneY);
                SoundManagerReference.Play_QbertFall_Src();
            }

            //MoveAlongBezierCurve(this.transform.position,
            //new Vector2(this.transform.position.x - xFactor, this.transform.position.y - yFactor));
            SpriteSwitchCase = SpriteJumpDirection.JumpBottomLeft;
        }
    }
    // Make Coily chase Qbert
    public void CoilyChase()
    {
        float newXPosition = 0f;
        float newYPosition = 0f;

        if (CoilyDeath && !GameManager.FreezeObjectsGreenBall)
        {
            // if coily death is active and not frozen state
            // make coily chase to the block before elevator and jump off it
            // similar to qbert's jump down probably
            //Debug.Log("Coily death state activated pos = " + Qbert_Script.CoilyBlockToDieFrom);
            if (Mathf.Abs(Qbert_Script.CoilyBlockToDieFrom.y - transform.position.y) < 0.15)
            {
                if (Mathf.Abs(Qbert_Script.CoilyBlockToDieFrom.x - transform.position.x) < 0.15)
                {
                    Debug.Log("Coily is at the death location");
                    //Debug.Log("Coily is moving to death position.");
                    if (transform.position.x > 0)
                    {
                        // isJumping = true;
                        // Debug.Log("Coily is at the death location +x" + new Vector3(this.transform.position.x + xFactor, -10f));
                        // MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + xFactor, -10f));

                        newXPosition     = xFactor;
                        newYPosition     = -10f;
                        SpriteSwitchCase = SpriteJumpDirection.JumpTopRight;
                    }
                    else
                    {
                        // isJumping = true;
                        // Debug.Log("Coily is at the death location -x"+ new Vector3(this.transform.position.x - xFactor, -10f));
                        // MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x - xFactor, -10f));
                        // SoundManagerReference.Play_CoilyJump_Src();

                        newXPosition     = xFactor * -1;
                        newYPosition     = -10f;
                        SpriteSwitchCase = SpriteJumpDirection.JumpBottomLeft;
                    }
                    this.spriteRenderer.sortingOrder = -1;
                    isJumping = true;
                    //Debug.Log("Coily is moving to death position.");
                    MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + newXPosition, this.transform.position.y + newYPosition));
                    SoundManagerReference.Play_CoilyFall_Src();
                    CancelInvoke("CoilyChase");
                }
                else        // Slightly buggy but to make sure coily doesn't stop when y matches
                {
                    if (transform.position.x > 0)
                    {
                        // isJumping = true;
                        // Debug.Log("Coily is at the death location +x" + new Vector3(this.transform.position.x + xFactor, -10f));
                        // MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + xFactor, -10f));
                        Debug.Log("In ++");
                        newXPosition = xFactor;
                        newYPosition = yFactor;
                        if (this.transform.position.y + newYPosition > this.transform.position.y)
                        {
                            SpriteSwitchCase = SpriteJumpDirection.JumpTopRight;
                        }
                        else
                        {
                            SpriteSwitchCase = SpriteJumpDirection.JumpBottomRight;
                        }
                    }
                    else
                    {
                        // isJumping = true;
                        // Debug.Log("Coily is at the death location -x"+ new Vector3(this.transform.position.x - xFactor, -10f));
                        // MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x - xFactor, -10f));
                        // SoundManagerReference.Play_CoilyJump_Src();

                        newXPosition = xFactor * -1;
                        newYPosition = -yFactor;
                        Debug.Log("In --");
                        if (this.transform.position.y + newYPosition > this.transform.position.y)
                        {
                            SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
                        }
                        else
                        {
                            SpriteSwitchCase = SpriteJumpDirection.JumpBottomLeft;
                        }
                    }
                    isJumping = true;
                    //Debug.Log("Coily is moving to death position.");
                    MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + newXPosition, this.transform.position.y + newYPosition));
                    SoundManagerReference.Play_CoilyJump_Src();
                }
            }
            else if (Qbert_Script.CoilyBlockToDieFrom.y >= this.transform.position.y)
            {
                // y is a negative factor, hence to make is positive  multiplying by -1
                newYPosition = (yFactor * -1);
                //Debug.Log("Moving Up");
                if (Qbert_Script.CoilyBlockToDieFrom.x >= this.transform.position.x)
                {
                    //Debug.Log("Moving Right Now");
                    //spriteRenderer.sprite = TopRight;
                    newXPosition     = xFactor;
                    SpriteSwitchCase = SpriteJumpDirection.JumpTopRight;
                }
                else
                {
                    //Debug.Log("Moving Left Now");
                    newXPosition     = xFactor * -1f;
                    SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
                }
                isJumping = true;
                //Debug.Log("Coily is moving to death position.");
                MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + newXPosition, this.transform.position.y + newYPosition));
                SoundManagerReference.Play_CoilyJump_Src();
            }
            else
            {
                newYPosition = (yFactor);
                //Debug.Log("Moving Downwards");
                if (Qbert_Script.CoilyBlockToDieFrom.x >= this.transform.position.x)
                {
                    //Debug.Log("Moving Right Now");
                    newXPosition     = xFactor;
                    SpriteSwitchCase = SpriteJumpDirection.JumpBottomRight;
                }
                else
                {
                    //Debug.Log("Moving Left Now");
                    newXPosition     = xFactor * -1;
                    SpriteSwitchCase = SpriteJumpDirection.JumpBottomLeft;
                }
                isJumping = true;
                //Debug.Log("Coily is moving to death position.");
                MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + newXPosition, this.transform.position.y + newYPosition));
                SoundManagerReference.Play_CoilyJump_Src();
            }
        }
        else if (!GameManager.FreezeObjectsGreenBall)
        {
            if (Qbert.transform.position.y >= this.transform.position.y)
            {
                // y is a negative factor, hence to make is positive  multiplying by -1
                newYPosition = (yFactor * -1);
                //Debug.Log("Moving Up");
                if (Qbert.transform.position.x >= this.transform.position.x)
                {
                    //Debug.Log("Moving Right Now");
                    //spriteRenderer.sprite = TopRight;
                    newXPosition     = xFactor;
                    SpriteSwitchCase = SpriteJumpDirection.JumpTopRight;
                }
                else
                {
                    //Debug.Log("Moving Left Now");
                    newXPosition     = xFactor * -1f;
                    SpriteSwitchCase = SpriteJumpDirection.JumpTopLeft;
                }
            }
            else
            {
                newYPosition = (yFactor);
                //Debug.Log("Moving Downwards");
                if (Qbert.transform.position.x >= this.transform.position.x)
                {
                    //Debug.Log("Moving Right Now");
                    newXPosition     = xFactor;
                    SpriteSwitchCase = SpriteJumpDirection.JumpBottomRight;
                }
                else
                {
                    //Debug.Log("Moving Left Now");
                    newXPosition     = xFactor * -1;
                    SpriteSwitchCase = SpriteJumpDirection.JumpBottomLeft;
                }
            }
            Blocks block =
                FindBlockAtPosition(new Vector3(transform.position.x + newXPosition, transform.position.y + newYPosition, 0f));
            if (block == null)
            {
                //Debug.Log("Coily is going to off pyramid position.");
                return;
            }
            isJumping = true;
            //Debug.Log("Coily is in pyramid position.");
            MoveAlongBezierCurve(this.transform.position, new Vector3(this.transform.position.x + newXPosition, this.transform.position.y + newYPosition));
            SoundManagerReference.Play_CoilyJump_Src();
        }
    }