Example #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;
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (isOnElevator)
        {
            return;
        }

        if (GameManager.WinTrigerred)
        {
            return;
        }

        if (!isJumping && !Qbert_Dead)
        {
            //Debug.Log("KeyPress Active");
            KeyboardInputCheck();
            return;
        }

        if (tParamBezierParameter < 1.0)
        {
            this.tParamBezierParameter += BezierCurveFactor * Time.deltaTime;
            this.transform.position     = Vector3.Lerp(Vector3.Lerp(this.position0, this.position1, tParamBezierParameter),
                                                       Vector3.Lerp(this.position1, this.position2, tParamBezierParameter), tParamBezierParameter);
        }

        if (isJumping)
        {
            switch (SpriteSwitchCase)
            {
            case SpriteJumpDirection.JumpBottomLeft:
                spriteRenderer.sprite = JumpBottomLeft;
                break;

            case SpriteJumpDirection.JumpBottomRight:
                spriteRenderer.sprite = JumpBottomRight;
                break;

            case SpriteJumpDirection.JumpTopLeft:
                spriteRenderer.sprite = JumpTopLeft;
                break;

            case SpriteJumpDirection.JumpTopRight:
                spriteRenderer.sprite = JumpTopRight;
                break;

            default:
                spriteRenderer.sprite = BottomLeft;
                break;
            }
        }


        if (this.transform.position == this.position2)
        {
            if (BlockMovingTo != null)
            {
                BlockMovingTo.Activate();
                BlockMovingTo = null;
            }
            else if (ElevatorMovingTo != null)
            {
                ElevatorMovingTo.ActivateElevator = true;
                ElevatorMovingTo = null;
            }

            isJumping             = false;
            tParamBezierParameter = 0;
            if (SpriteSwitchCase == SpriteJumpDirection.JumpTopLeft)
            {
                spriteRenderer.sprite = TopLeft;
            }
            else if (SpriteSwitchCase == SpriteJumpDirection.JumpTopRight)
            {
                spriteRenderer.sprite = TopRight;
            }
            else if (SpriteSwitchCase == SpriteJumpDirection.JumpBottomLeft)
            {
                spriteRenderer.sprite = BottomLeft;
            }
            else if (SpriteSwitchCase == SpriteJumpDirection.JumpBottomRight)
            {
                spriteRenderer.sprite = BottomRight;
            }

            // If Qbert is dead, get the bezier curve movement to fall down, and reset
            if (Qbert_Dead && deathByFall)
            {
                //Debug.Log("In DeathbyFallQbert");
                float tempCurveFactor = BezierCurveFactor;
                MoveAlongBezierCurve(this.transform.position, deadPositionForBezierCurve);
                if (transform.position.y == deadzoneY)
                {
                    tParamBezierParameter = 1;
                    GameManager.ResetGame = true;
                }
            }
            else if (Qbert_Dead && deathByEnemy)
            {
                //Time.timeScale = 0;
                tParamBezierParameter = 1;
                Debug.Log("In DeathbyEnemyQbert (Update)");
                GameManager.ResetGame = true;
            }
        }

        //this.GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0);
    }