Exemple #1
0
    private static GameObject addTileSpring(Vector3 v)
    {
        TileSpring.addLoc(v);
        GameObject temp = null;

        temp = (GameObject)Instantiate(sTileSprings, v, Quaternion.Euler(new Vector3(0, 0, 0)));
        if (TileSpring.currWorld != currWorld)
        {
            spriteTileSprings = (Sprite)Resources.Load("Tile/" + currWorld + "/TileSpring", typeof(Sprite));
            temp.GetComponentInChildren <TileSpring>().setSprite(new Sprite[] { spriteTileSprings }, currWorld);
        }
        if (currWorld > 1)
        {
            temp = addTileNormal(v);
        }
        return(temp);
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Level.isFinish || Level.isPaused || Dillo.isTransforming)
        {
            return;
        }

        if (Input.touchCount > 0 && IsAbleToMove())
        {
            foreach (Touch touch in Input.touches)
            {
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    isSwipe         = true;
                    fingerStartTime = Time.time;
                    fingerStartPos  = touch.position;
                    break;

                case TouchPhase.Canceled:
                    isSwipe = false;

                    break;

                case TouchPhase.Ended:
                    float gestureTime = Time.time - fingerStartTime;
                    float gestureDist = (touch.position - fingerStartPos).magnitude;

                    if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist)
                    {
                        Vector2 swipeDirection = touch.position - fingerStartPos;
                        Vector2 swipeType      = Vector2.zero;

                        if (Mathf.Abs(swipeDirection.x) > Mathf.Abs(swipeDirection.y))
                        {
                            swipeType = Vector2.right * Mathf.Sign(swipeDirection.x);
                        }
                        else
                        {
                            swipeType = Vector2.up * Mathf.Sign(swipeDirection.y);
                        }

                        if (swipeType.x == -Vector2.right.x)
                        {
                            speedX        = -Level.rollSpeed;
                            isStartMoving = true;
                            direction     = DILO_LEFT;

                            if (thisTransform.localScale.x < 0)
                            {
                                thisTransform.localScale = new Vector3(thisTransform.localScale.x * -1, thisTransform.localScale.y, thisTransform.localScale.z);
                            }
                        }
                        else if (swipeType.x == Vector2.right.x)
                        {
                            speedX        = Level.rollSpeed;
                            isStartMoving = true;
                            direction     = DILO_RIGHT;

                            if (thisTransform.localScale.x >= 0)
                            {
                                thisTransform.localScale = new Vector3(thisTransform.localScale.x * -1, thisTransform.localScale.y, thisTransform.localScale.z);
                            }
                        }
                        else if (swipeType.y == Vector2.up.y)
                        {
                            speedY        = Level.rollSpeed;
                            direction     = DILO_UP;
                            isStartMoving = true;
                        }
                        else if (swipeType.y == -Vector2.up.y)
                        {
                            speedY        = -Level.rollSpeed;
                            direction     = DILO_DOWN;
                            isStartMoving = true;
                        }
                    }
                    else
                    {
                        if (startTapTime != 0)
                        {
                            if ((Time.time - startTapTime) < maxTapTime)
                            {
                                changeVersion();
                            }
                        }
                        startTapTime = Time.time;
                    }
                    break;
                }
            }
        }

        if (IsAbleToMove())
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (startTapTime != 0)
                {
                    if ((Time.time - startTapTime) < maxTapTime)
                    {
                        changeVersion();
                    }
                }
                startTapTime = Time.time;
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                speedX        = -Level.rollSpeed;
                isStartMoving = true;
                direction     = DILO_LEFT;

                if (thisTransform.localScale.x < 0)
                {
                    thisTransform.localScale = new Vector3(thisTransform.localScale.x * -1, thisTransform.localScale.y, thisTransform.localScale.z);
                }
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                speedX        = Level.rollSpeed;
                isStartMoving = true;
                direction     = DILO_RIGHT;

                if (thisTransform.localScale.x >= 0)
                {
                    thisTransform.localScale = new Vector3(thisTransform.localScale.x * -1, thisTransform.localScale.y, thisTransform.localScale.z);
                }
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                speedY        = Level.rollSpeed;
                direction     = DILO_UP;
                isStartMoving = true;
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                speedY        = -Level.rollSpeed;
                direction     = DILO_DOWN;
                isStartMoving = true;
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.S))
            {
                speedX        = 0;
                speedY        = 0;
                isMoving      = false;
                isStartMoving = false;
            }
        }
        if (isMoving && !IsJumping())
        {
            thisTransform.position += new Vector3(speedX, speedY, 0f);
        }


        // level border
        if (Level.BORDER)
        {
            if (thisTransform.position.x > Level.SCENE_WIDTH / 2)
            {
                thisTransform.position = new Vector3(Level.SCENE_WIDTH / 2 - PrefabController.TILESIZE / 2, thisTransform.position.y, -1);
                stop();
                AudioController.playSFX(AudioController.SFX.Bump);
            }
            else if (thisTransform.position.x < -Level.SCENE_WIDTH / 2)
            {
                thisTransform.position = new Vector3(-Level.SCENE_WIDTH / 2 + PrefabController.TILESIZE / 2, thisTransform.position.y, -1);
                stop();
                AudioController.playSFX(AudioController.SFX.Bump);
            }
            else if (thisTransform.position.y > Level.SCENE_HEIGHT / 2 + DILO_INTERVAL)
            {
                thisTransform.position = new Vector3(thisTransform.position.x, Level.SCENE_HEIGHT / 2 + PrefabController.TILESIZE / 2, -1);
                AudioController.playSFX(AudioController.SFX.Bump);
                stop();
            }
            else if (thisTransform.position.y < -Level.SCENE_HEIGHT / 2)
            {
                thisTransform.position = new Vector3(thisTransform.position.x, -Level.SCENE_HEIGHT / 2 + PrefabController.TILESIZE / 2, -1);
                AudioController.playSFX(AudioController.SFX.Bump);
                stop();
            }
        }

        AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);

        if (isStartMoving && (stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloSideRoll") ||
                              stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloDownRoll") ||
                              stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloUpRoll") ||
                              stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloSideRollMetal") ||
                              stateInfo.nameHash == Animator.StringToHash("Base Layer.DilloDownRollMetal") ||
                              stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloUpRollMetal")))
        {
            isStartMoving = false;
            AudioController.playSFX(AudioController.SFX.Slide);
            isMoving = true;
            Level.movesDone++;
            Level.updateMovesDone();
        }

        if (dying && (stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloFinish")))
        {
            print("finish dying");
            dying = false;
            Level.gameOver();
        }

        if (anim.GetBool("Jumping") && (stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloIdle") ||
                                        stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloIdleMetal")))
        {
            setPosition(jumpNewPos + new Vector3(0, Dillo.DILO_INTERVAL, 0));
            anim.SetBool("Jumping", false);
            int tempDirection = direction;
            if (!TileSpring.isSpring(jumpNewPos))
            {
                stop();
            }
            thisTransform.collider2D.enabled = true;
        }

        if (isReverting && (stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloIdle") ||
                            stateInfo.nameHash == Animator.StringToHash("Base Layer.dilloIdleMetal")))
        {
            isMoving      = false;
            isStartMoving = false;
            isReverting   = false;
        }

        anim.SetInteger("Direction", direction);
        anim.SetBool("IsMoving", isMoving);
        anim.SetBool("IsStartMoving", isStartMoving);
        anim.SetBool("IsReverting", isReverting);
    }