Ejemplo n.º 1
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
        }
    }