Ejemplo n.º 1
0
    static TurnBlockBase.StartPosition angleToStartPosition(TurnBlockBase.StartPosition direction, int rotateAngle)
    {
        int rotateCount = 0;

        switch (rotateAngle)
        {
        case 0:         rotateCount = 0;        break;

        case -90:       rotateCount = 3;        break;

        case 180:       rotateCount = 2;        break;

        case 90:        rotateCount = 1;        break;
        }

        return((TurnBlockBase.StartPosition)(((int)direction + rotateCount) % 4));
    }
Ejemplo n.º 2
0
    /// <summary>
    /// ゴールにブロックが接続されているかをチェックする
    /// </summary>
    /// <returns>接続されているか</returns>
    public static bool IsConnectToGoalBlock(Vector3 pos, TurnBlockBase.StartPosition direction)
    {
        if (PlayerController.IsTurnFromPrevBlock)
        {
            return(false);
        }
        float blockWidth = 1f;

        // pos.y -= kMapDepth + SphereController.transform.position.y;


        Vector3 newPos = new Vector3(
            (int)(pos.x + 0.5f),
            -PuzzleManager.CurrentStage * PuzzleManager.kMapDepth,
            ((int)(pos.z + 0.5f)) + 0.25f
            );

        // 無限ループ防止
        for (int i = 0; i < 100; ++i)
        {
            var objs = Physics.OverlapSphere(newPos, 0.1f, HeldBlockSlotUI.TargetLayer);

            if (objs.Length == 0)
            {
                break;
            }

            if (objs[0].GetComponent <GoalBlock>() != null)
            {
                return(true);
            }

            TurnBlockBase block = objs[0].GetComponent <TurnBlockBase>();
            if (block != null)
            {
                switch (direction)
                {
                case TurnBlockBase.StartPosition.North:
                    direction = angleToStartPosition(direction, (int)block.TargetFromSouth);        break;

                case TurnBlockBase.StartPosition.South:
                    direction = angleToStartPosition(direction, (int)block.TargetFromNorth);        break;

                case TurnBlockBase.StartPosition.East:
                    direction = angleToStartPosition(direction, (int)block.TargetFromWest); break;

                case TurnBlockBase.StartPosition.West:
                    direction = angleToStartPosition(direction, (int)block.TargetFromEast);
                    break;
                }

                Vector3 dire;
                switch (direction)
                {
                case TurnBlockBase.StartPosition.North:
                    dire = new Vector3(0, 0, blockWidth);             break;

                case TurnBlockBase.StartPosition.South:
                    dire = new Vector3(0, 0, -blockWidth);    break;

                case TurnBlockBase.StartPosition.East:
                    dire = new Vector3(blockWidth, 0, 0);     break;

                case TurnBlockBase.StartPosition.West:
                    dire = new Vector3(-blockWidth, 0, 0);            break;

                default:
                    dire = new Vector3(0, 0, 0);                              break;
                }
                newPos += dire;
            }
            else
            {
                break;
            }
        }
        return(false);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Pos = transform.position;

        if (!PlayerController.IsSpeedUp && ++frame % 60 == 0 && frame > 180 && PuzzleManager.CurrentStage != 0)
        {
            if (PuzzleManager.IsConnectToGoalBlock(PlayerController.Pos, PlayerController.Direction))
            {
                PlayerController.SpeedUp();
            }
        }

        // 移動方向求める
        float   angleDir = transform.eulerAngles.y * (Mathf.PI / 180.0f);
        Vector3 dir      = new Vector3(Mathf.Cos(angleDir), Mathf.Sin(angleDir), 0.0f);

        if (dir.x > 0.9f)
        {
            Direction = TurnBlockBase.StartPosition.North;
        }
        else if (dir.x < -0.9f)
        {
            Direction = TurnBlockBase.StartPosition.South;
        }
        else if (dir.y < -0.9f)
        {
            Direction = TurnBlockBase.StartPosition.West;
        }
        else if (dir.y > 0.9f)
        {
            Direction = TurnBlockBase.StartPosition.East;
        }

        if (IsActive)
        {
            var     radian = (transform.eulerAngles.y) * Mathf.Deg2Rad;
            Vector2 vector = new Vector2(Mathf.Sin(radian), Mathf.Cos(radian));
            if (IsSpeedUp)
            {
                transform.position = new Vector3(
                    (vector.x * kSpeedPerSecond * 4 / 60f) + transform.position.x,
                    transform.position.y,
                    (vector.y * kSpeedPerSecond * 4 / 60f) + transform.position.z
                    );
            }
            else
            {
                transform.position = new Vector3(
                    (vector.x * kSpeedPerSecond / 60f) + transform.position.x,
                    transform.position.y,
                    (vector.y * kSpeedPerSecond / 60f) + transform.position.z
                    );
            }
        }

        RaycastHit hit;
        var        isHit = Physics.SphereCast(transform.position, 0.1f, Vector3.down, out hit, 100f, targerLayer);

        if (!isHit)
        {
            _collider.enabled = false;
        }
    }