예제 #1
0
    // Update is called once per frame
    private void Update()
    {
        //todo change stuff later to an observer pattern
        PlayerController playerController = m_player.GetComponent <PlayerController>();
        CameraController cameraController = m_camera.GetComponent <CameraController>();

        //check if the back button has been pressed
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            MemoryCard.LoadMenu();
        }

        //has the player beaten the level / fallen outside the level / still playing
        if (playerController.isFinished())
        {
            //remove player control because he has beaten the level
            p_levelControl.GetComponent <LevelTilt>().m_playerHasControl = false;

            //update the highscore if the player was faster
            if (p_timeInSeconds < p_bestTimeInSeconds || p_bestTimeInSeconds == 0)
            {
                MemoryCard.SaveHighscore(new Highscore(MemoryCard.GetScene(), p_timeInSeconds));
                m_bestTime.text = p_timeInSeconds.ToString("f2");
            }

            //start cameranimation once player is out of bounds
            if (playerController.isOutOfBounds())
            {
                p_lookAtPosition.transform.position = new Vector3(m_endCamera, 0, 0);
                m_camera.GetComponent <CameraController>().m_lookAt     = p_lookAtPosition.transform;
                m_camera.GetComponent <CameraController>().m_smoothTime = p_cameraSmoothTime * 4;

                if (m_camera.transform.position.x > m_endCamera / 2)
                {
                    MemoryCard.LoadNextLevel();
                }
            }
        }
        else if (playerController.isOutOfBounds())
        {
            ResetLevel();
            playerController.setOutOfBounds(false);
        }
        else
        {
            //start the timer once the player has control
            if (p_levelControl.GetComponent <LevelTilt>().m_playerHasControl)
            {
                p_timeInSeconds   += Time.deltaTime;
                m_currentTime.text = p_timeInSeconds.ToString("f2");
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    private void Update()
    {
        if (gameStart)
        {
            //animation for letting the turtle fall down
            m_turtle.transform.Translate(0, p_velocityTurtle * Time.deltaTime, 0, Space.World);
            m_turtle.transform.Rotate(70 * Time.deltaTime, -170 * Time.deltaTime, 0, Space.World);
            p_velocityTurtle -= Time.deltaTime * 80;

            //follow the turtle with the camera after a certain time
            if (p_velocityTurtle < -20)
            {
                m_camera.transform.position = Vector3.SmoothDamp(m_camera.transform.position, new Vector3(0, m_turtle.transform.position.y, -10), ref p_velocityCamera, m_smoothTime);
            }

            //if camera doesnt see gui elements anymore, change scene
            if (m_camera.transform.position.y < -15)
            {
                MemoryCard.CheckNewGame();
                MemoryCard.LoadMenu();
            }
        }
        else
        {
            //Animation to wobble the title and turtle up and down
            float sinUpDown      = Mathf.Sin(Time.time * 3);
            float sinTitleUpDown = Mathf.Sin((Time.time + 1.8f) * 3);
            TranslateGameObjects(m_turtle, p_turtleOriginalPosition, sinUpDown);
            TranslateGameObjects(m_title, p_titleOriginalPosition, sinTitleUpDown);

            //animation to wobble the title and turtle left to right
            float sinLeftRight = Mathf.Sin(Time.time * 0.8f);
            RotateGameObjects(m_turtle, p_turtleOriginalRotation, sinLeftRight);
            RotateGameObjects(m_title, p_titleOriginalRotation, sinLeftRight);

            //animation to scale the "drop down" button up and down
            float sinButtonScale = Mathf.Sin(Time.time * 3.1f);
            m_buttonText.transform.localScale = new Vector3(0.7f, 0.8f, 1) * (sinButtonScale * sinButtonScale * 0.05f + 1f);
        }
    }
예제 #3
0
    // Update is called once per frame
    private void Update()
    {
        //return key pressed?
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            p_nextScene   = true;
            p_returnScene = true;
        }

        //check touch controls
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            //save the touch and swipe positions
            switch (touch.phase)
            {
            case TouchPhase.Began:
                p_startPos = touch.position;
                break;

            case TouchPhase.Moved:
                p_direction = touch.position - p_startPos;
                break;

            case TouchPhase.Ended:
                p_direction.x = 0;
                p_direction.y = 0;
                break;
            }
        }

        //if the player swiped for a certain distance, start to load new map
        if (Mathf.Abs(p_direction.x) > p_triggerDistance)
        {
            //dont change map to frequently
            if (Time.time - p_lastLevelChange > 0.3f)
            {
                p_lastLevelChange = Time.time;

                //change to next or previous map and set animatin accordingly
                if (p_direction.x < 0)
                {
                    MemoryCard.AddToSelectedLevel(+1);
                    p_mapGoToThisPosition = p_mapLeftPosition;
                }
                else
                {
                    MemoryCard.AddToSelectedLevel(-1);
                    p_mapGoToThisPosition = p_mapRightPosition;
                }
            }
        }

        //change scene once the camera finished animation
        if (p_nextScene && m_camera.transform.position.x < -19)
        {
            if (p_returnScene)
            {
                MemoryCard.LoadMenu();
            }
            else
            {
                MemoryCard.LoadSelectedLevel();
            }
        }

        //animate
        AnimateScreenTransitions();
        AnimateMapTransition();
        AnimateScreen();

        //if the map has finished animation, load a new map
        if (p_currentMapPreview.transform.position.x < -19 || p_currentMapPreview.transform.position.x > 19)
        {
            LoadPreview(MemoryCard.GetSelectedLevelIndex()); //load currently selected level
        }
    }