Esempio n. 1
0
    void HandleInput()
    {
        if (_canTap && Input.touchCount > 0 && EventSystem.current.currentSelectedGameObject == null)
        {
            var touch = Input.GetTouch(0);

            switch (touch.phase)
            {
            case TouchPhase.Began:

                for (int j = LastNearDrop; j < LastNearDrop + dropsCountPerPhase; j++)
                {
                    if (PhaseAlpha <= dropsLineInterval[j].right)
                    {
                        if (PhaseAlpha >= dropsLineInterval[j].left)
                        {
                            _tapDropId = j;
                        }
                        else
                        {
                            _tapDropId = -1;
                        }
                        break;
                    }
                }

                if (_tapDropId > -1)
                {
                    dropsLinePos[_tapDropId].DropObject.SetActive(false);
                }

                break;
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (_canMove && Input.touchCount > 0 && EventSystem.current.currentSelectedGameObject == null)
        {
            var touch = Input.GetTouch(0);

            switch (touch.phase)
            {
            case TouchPhase.Began:
                touchStartPos = touch.position;

                touchStartXPos = transform.localPosition.x;

                break;

            case TouchPhase.Moved:
                var         currentPosition = touch.position;
                var         delta           = currentPosition - touchStartPos;
                const float xref            = 180.0f;
                float       scale           = width / xref;

                //delta

                var xToSet = touchStartXPos + delta.x / scale;
                if (xToSet > 46)
                {
                    xToSet = 46;
                }
                else if (xToSet < -46)
                {
                    xToSet = -46;
                }

                transform.localPosition = new Vector3(xToSet, -65f, 0f);
                break;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (timeForTutorial > 0.0f)
        {
            timeForTutorial -= Time.deltaTime;
            if (timeForTutorial <= 0.0f)
            {
                Time.timeScale = 0.0f;
                if (needPortalTutorial)
                {
                    tutorialSuck.SetActive(true);
                }
                else
                {
                    tutorialShoot.SetActive(true);
                    LastTutorialShown = true;
                }
            }
        }


        if (currentOrbit == null)
        {
            return;
        }

        var currentAngleInDegrees = GetCurrentAngleInDegrees();

        if (nextObstacleAngle < 0 || (isNextObstacleDestroyed && currentAngleInDegrees > nextObstacleAngle && !afterCircle))
        {
            nextObstacleAngle = currentOrbit.GetNextObstacleAngle(currentAngleInDegrees);
            if (nextObstacleAngle < currentAngleInDegrees)
            {
                afterCircle = true;
            }
            isNextObstacleDestroyed = false;
        }

        if (coolDownCounter > 0.0f)
        {
            coolDownCounter -= Time.deltaTime;
        }

        if (Input.touchCount > 0 && !needHandlePortalShot && !isDead)
        {
            var touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Ended)
            {
                needHandleLaserShot = true;
            }
        }

        if (!hasPortal &&
            destroyedObstacles >= currentOrbit.obstaclesCount &&
            currentOrbit.IsInPortalInterval(currentAngleInDegrees) &&
            !isInPortal)
        {
            ActivateCapsule(true);
            isInPortal = true;
        }

        if (isInPortal &&
            !currentOrbit.IsInPortalInterval(currentAngleInDegrees))
        {
            //ActivateCapsule(false);
            isInPortal = false;
        }

        if (needHandlePortalShot)
        {
            needHandlePortalShot = false;

            if (destroyedObstacles >= currentOrbit.obstaclesCount)
            {
                if (currentOrbit.TryCreatePortal(currentAngleInDegrees))
                {
                    destroyedObstacles -= currentOrbit.obstaclesCount;
                    particleSystem.Clear();
                    hasPortal = true;
                    ActivateCapsule(false);
                    var meshRenderer = capsule.GetComponent <MeshRenderer>();
                    meshRenderer.material = lightupCapsule;
                    speed *= gameController.accelerationMultiplier;
                    StartCoroutine(AnimateCameraPos(cameraPos, cameraPos - new Vector3(0.0f, 0.0f, 0.5f), 60.0f, 70.0f, cameraInterpolationTime));
                    speedMode = true;
                    SpeedPS.gameObject.SetActive(true);
                    ShipTrail.SetActive(true);
                }
            }
        }

        if (currentOrbit.IsAroundPortal(gameObject.transform.position))
        {
            currentScore += GetScore(true, false, GetLap(), speed, currentLevel);
            gameController.hudController.SetScore(currentScore);
            AudioManager.StaticPlay("enter-portal");
            SetNextOrbit(gameController.GetNextOrbit(), currentAngleInDegrees);

            camera.GetComponent <Skybox>().material = skyMat;
        }

        if (UnityEngine.Input.GetKeyDown(KeyCode.Space) || needHandleLaserShot)
        {
            needHandleLaserShot = false;
            Debug.Log("Pressed shot");
            if (coolDownCounter <= 0.0f)
            {
                Debug.Log("Shooting");
                Shoot(currentAngleInDegrees);
            }
            else
            {
                Debug.Log("Can't shoot");
            }
        }

        var distance = currentOrbit.GetDistanceBetweenAngles(currentAngleInDegrees, nextObstacleAngle);

        Debug.Log("Angle: " + currentAngleInDegrees + " Next Obstacle Angle: " + nextObstacleAngle + " Is Destroyed: " + isNextObstacleDestroyed + " Distance: " + distance);

        if (!isNextObstacleDestroyed && distance < criticalDistance && !isDead)
        {
            speed = 0;
            this.spacecraftSpeed = 0;
            SpaceShipModel.SetActive(false);
            Explosion.gameObject.SetActive(true);
            gameController.hudController.ShowEndGameScreen();
            AudioManager.StaticPlay("died");
            isDead = true;
        }

        alpha += speed * Time.deltaTime;
        if (GetCurrentAngleInDegrees() < currentAngleInDegrees)
        {
            afterCircle = false;
        }
        gameObject.transform.position = GetSpacecraftPosition(alpha);
        gameObject.transform.LookAt(GetSpacecraftPosition(alpha + 1), currentOrbit.transform.up);
    }
Esempio n. 4
0
    void FixedUpdate()
    {
        if (isStarted != PlayerPrefs.GetInt("isStarted")) //If the variable changes
        {
            isStarted = PlayerPrefs.GetInt("isStarted");

            if (isStarted == 1)
            {
                if (Ground == true) //If on the ground, it means running
                {
                    animator.Play("run");
                }
            }
            else
            {
                if (PlayerPrefs.GetInt("isDeaded") != 1 & Finish != true) //If the player has not lost and is not at the finish line, then he simply stands
                {
                    animator.Play("idle");
                }
            }
        }

        if (isStarted == 1)           // If game is not started
        {
            if (Input.touchCount > 0) //Controlling the character left-right
            {
                touch = Input.GetTouch(0);

                if (touch.phase == TouchPhase.Moved)
                {
                    if (Finish != true)
                    {
                        if (Ground == true)
                        {
                            if (Stretch == false)
                            {
                                Vector3 newPos = new Vector3(Mathf.Clamp(transform.position.x + touch.deltaPosition.x * nowSpeed, -1.9f, 1.9f), transform.position.y, transform.position.z); //The player's position change is limited, maximum -1.9f and 1.9f by x
                                transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * smooth);                                                                      //We change the coordinates of the player, to those that we just calculated
                            }
                            else
                            {
                                Vector3 newPos = new Vector3(Mathf.Clamp(transform.position.x + touch.deltaPosition.x * nowSpeed, -4.2f, 4.2f), transform.position.y, transform.position.z); //The player's position change is limited, maximum -4.2f and 4.2f by x
                                transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * smooth);                                                                      //We change the coordinates of the player, to those that we just calculated
                            }
                        }
                        else
                        {
                            Vector3 newPos = new Vector3(Mathf.Clamp(transform.position.x + touch.deltaPosition.x * nowSpeed, -4.2f, 4.2f), transform.position.y, transform.position.z); //The player's position change is limited, maximum -4.2f and 4.2f by x
                            transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * smooth);                                                                      //We change the coordinates of the player, to those that we just calculated
                        }
                    }
                }
            }

            transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.World); //Forward movement

            if (Scale != PlayerPrefs.GetFloat("Scale"))                                 //If the cylinder size has changed
            {
                Scale = PlayerPrefs.GetFloat("Scale");                                  //Get it

                if (Scale <= 0)
                {
                    if (cylindersNum > 1) //If there are more than 1 cylinders, then delete the last one
                    {
                        cylinders[cylinders.Count - 1].transform.localScale = new Vector3(0, 0.6f, 0);
                        ClearLastCylinder();
                    }
                    else //if he is alone
                    {
                        if (Stretch == false) //If the road spawns
                        {
                            IsDeadForScale();
                        }
                        else
                        {
                            IsDeadForScaleTwo();
                            Stretch = false;
                        }
                    }
                }
                ChangeScale(); //Change Scale
            }
            if (Spawn == true) //If spawn = true, spawn block
            {
                SpawnBl();
            }
            if (Stretch == true) //If the road is every 0.0625f we decrease the cylinder by minusScale
            {
                if (zDistance - hasDistance >= 0.0625f)
                {
                    PlayerPrefs.SetFloat("Scale", Scale - minusScale);

                    if (zDistance - hasDistance >= 0.0625f)
                    {
                        PlayerPrefs.SetFloat("Scale", Scale - minusScale);

                        if (zDistance - hasDistance >= 0.0625f)
                        {
                            PlayerPrefs.SetFloat("Scale", Scale - minusScale);

                            if (zDistance - hasDistance >= 0.0625f)
                            {
                                PlayerPrefs.SetFloat("Scale", Scale - minusScale);

                                if (zDistance - hasDistance >= 0.0625f)
                                {
                                    PlayerPrefs.SetFloat("Scale", Scale - minusScale);
                                }
                                else
                                {
                                    hasDistance = zDistance;
                                }
                            }
                            else
                            {
                                hasDistance = zDistance;
                            }
                        }
                        else
                        {
                            hasDistance = zDistance;
                        }
                    }
                    else
                    {
                        hasDistance = zDistance;
                    }
                }

                if (transform.position.x < xPosM || transform.position.x > xPosA) //If the player leaves the road to the right or left, the road is no longer built
                {
                    Stretch = false;
                }

                if (transform.position.z >= posWill) //If the player has built a road to the end, turn off road building
                {
                    Stretch = false;
                }
                if (transform.position.z > posStart) //We calculate the coordinates of where to spawn the road
                {
                    zDistance = transform.position.z - posStart;
                    if (zDistance > distance)
                    {
                        zDistance = distance;
                    }
                    spawnedBlocks[spawnedBlocks.Count - 1].transform.position   = new Vector3(spawnedBlocks[spawnedBlocks.Count - 1].transform.position.x, spawnedBlocks[spawnedBlocks.Count - 1].transform.position.y, posStart + zDistance / 2);
                    spawnedBlocks[spawnedBlocks.Count - 1].transform.localScale = new Vector3(1.2f, 0.1f, zDistance);
                }
            }

            yPos = transform.position.y + transform.localScale.z / 2; //Player position y

            if (playerrb.transform.position.y <= yPos)
            {
                playerrb.transform.position = new Vector3(playerrb.transform.position.x, yPos, playerrb.transform.position.z);
            }
            if (Finish == true) //Increased speed at the finish
            {
                speed = 16;
            }
            if (Ground == false) //If there is more than one cylinder and the value Ground! = The value of the last cylinder,
                                 //we get this value and if Ground = true, turn on the running animation.
            {
                if (cylindersNum > 1)
                {
                    if (Ground != cylinders[cylinders.Count - 1].Ground && animator.GetCurrentAnimatorStateInfo(0).IsName("run"))
                    {
                        Ground = cylinders[cylinders.Count - 1].Ground;
                        if (Ground == true)
                        {
                            Ground = true;
                            animator.Play("run");
                            playerrb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
                        }
                    }
                }
            }
            else
            {
                if (cylindersNum > 1) //If Ground = false, check if after timeMax seconds Ground = true does not become, then the player has lost
                {
                    if (cylinders[cylinders.Count - 1].Dead == true)
                    {
                        timerOn = true;
                        time    = 0;
                    }
                }
            }
            if (timerOn == true) //After the last cylinder Ground has become false, we wait for the time and delete it,
            //so that if the player jumps and some of the cylinders fall off the house, he will not lose
            {
                time++;
                if (time > timeMax)
                {
                    if (cylinders[cylinders.Count - 2].Dead == true)
                    {
                        if (cylinders[cylinders.Count - 3].Dead == true)
                        {
                            if (cylinders[cylinders.Count - 4].Dead == true)
                            {
                                if (cylinders[cylinders.Count - 5].Dead == true)
                                {
                                    if (cylinders[cylinders.Count - 6].Dead == true)
                                    {
                                        if (cylinders[cylinders.Count - 7].Dead == true)
                                        {
                                            if (cylinders[cylinders.Count - 8].Dead == true)
                                            {
                                                IsDeadForFall();
                                                timerOn = false;
                                                time    = 0;
                                            }
                                            else
                                            {
                                                timerOn = false;
                                                time    = 0;
                                                ClearLastCylinder();
                                                ClearLastCylinder();
                                                ClearLastCylinder();
                                                ClearLastCylinder();
                                                ClearLastCylinder();
                                                ClearLastCylinder();
                                            }
                                        }
                                        else
                                        {
                                            timerOn = false;
                                            time    = 0;
                                            ClearLastCylinder();
                                            ClearLastCylinder();
                                            ClearLastCylinder();
                                            ClearLastCylinder();
                                            ClearLastCylinder();
                                            ClearLastCylinder();
                                        }
                                    }
                                    else
                                    {
                                        timerOn = false;
                                        time    = 0;
                                        ClearLastCylinder();
                                        ClearLastCylinder();
                                        ClearLastCylinder();
                                        ClearLastCylinder();
                                        ClearLastCylinder();
                                    }
                                }
                                else
                                {
                                    timerOn = false;
                                    time    = 0;
                                    ClearLastCylinder();
                                    ClearLastCylinder();
                                    ClearLastCylinder();
                                    ClearLastCylinder();
                                }
                            }
                            else
                            {
                                timerOn = false;
                                time    = 0;
                                ClearLastCylinder();
                                ClearLastCylinder();
                                ClearLastCylinder();
                            }
                        }
                        else
                        {
                            timerOn = false;
                            time    = 0;
                            ClearLastCylinder();
                            ClearLastCylinder();
                        }
                    }
                    else
                    {
                        timerOn = false;
                        time    = 0;
                        ClearLastCylinder();
                    }
                }
                if (score != (int)PlayerPrefs.GetFloat("Score"))
                {
                    score = (int)PlayerPrefs.GetFloat("Score");
                }
                if (animator.GetCurrentAnimatorStateInfo(0).IsName("dead"))
                {
                    PlayerPrefs.SetInt("isDeaded", 1);
                    PlayerPrefs.SetInt("isStarted", 0);
                }
            }

            switch (cylindersNum) //Depending on the number of cylinders, we set coordinates for them so that they are always together
            {
            case 2:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Main
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Second
                break;

            case 3:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Главный
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Второй
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);    //Третий
                break;

            case 4:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Главный
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Второй
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);    //Третий
                cylinders[4].transform.position = new Vector3(transform.position.x, cylinders[4].transform.position.y, transform.position.z);    //Четвертый
                break;

            case 5:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Главный
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Второй
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);    //Третий
                cylinders[4].transform.position = new Vector3(transform.position.x, cylinders[4].transform.position.y, transform.position.z);    //Четвертый
                cylinders[5].transform.position = new Vector3(transform.position.x, cylinders[5].transform.position.y, transform.position.z);
                break;

            case 6:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Главный
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Второй
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);    //Третий
                cylinders[4].transform.position = new Vector3(transform.position.x, cylinders[4].transform.position.y, transform.position.z);    //Четвертый
                cylinders[5].transform.position = new Vector3(transform.position.x, cylinders[5].transform.position.y, transform.position.z);
                cylinders[6].transform.position = new Vector3(transform.position.x, cylinders[6].transform.position.y, transform.position.z);
                break;

            case 7:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);    //Главный
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);    //Второй
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);    //Третий
                cylinders[4].transform.position = new Vector3(transform.position.x, cylinders[4].transform.position.y, transform.position.z);    //Четвертый
                cylinders[5].transform.position = new Vector3(transform.position.x, cylinders[5].transform.position.y, transform.position.z);
                cylinders[6].transform.position = new Vector3(transform.position.x, cylinders[6].transform.position.y, transform.position.z);
                cylinders[7].transform.position = new Vector3(transform.position.x, cylinders[7].transform.position.y, transform.position.z);
                break;

            case 8:
                cylinders[1].transform.position = new Vector3(transform.position.x, cylinders[1].transform.position.y, transform.position.z);
                cylinders[2].transform.position = new Vector3(transform.position.x, cylinders[2].transform.position.y, transform.position.z);
                cylinders[3].transform.position = new Vector3(transform.position.x, cylinders[3].transform.position.y, transform.position.z);
                cylinders[4].transform.position = new Vector3(transform.position.x, cylinders[4].transform.position.y, transform.position.z);
                cylinders[5].transform.position = new Vector3(transform.position.x, cylinders[5].transform.position.y, transform.position.z);
                cylinders[6].transform.position = new Vector3(transform.position.x, cylinders[6].transform.position.y, transform.position.z);
                cylinders[7].transform.position = new Vector3(transform.position.x, cylinders[7].transform.position.y, transform.position.z);
                cylinders[8].transform.position = new Vector3(transform.position.x, cylinders[8].transform.position.y, transform.position.z);
                break;
            }
        }
    }