コード例 #1
0
    public BlockUnit GetEntryBlock(Vector3 crossingPos, GameDefine.Direction dir, bool correctRoad, bool onRoad)
    {
        Vector3 blockPos = crossingPos;

        blockPos  += BlockOffset[(int)dir];
        blockPos.y = onRoad ?  correctRoad ? 2.6f : 2.4f : -3.0f;

        BlockUnit unit = GetEntryBlock(correctRoad);

        unit.transform.position = blockPos;
        unit.SetVisible(true);
        unit.crossingPos = crossingPos;
        unit.direction   = dir;
        unit.color       = correctRoad;

        if (!correctRoad)
        {
            // TODO: Refactor, put scaling logic in ObsBlock
            if (dir != GameDefine.Direction.Forward)
            {
                unit.transform.localScale = new Vector3(width, tall, size);
            }
            else
            {
                unit.transform.localScale = new Vector3(size, tall, width);
            }
        }

        return(unit);
    }
コード例 #2
0
    public void SetPosition(Vector3 pos, GameDefine.Direction pathDir, GameDefine.Direction[] turns)
    {
        this.directions = turns;

        // Make arrow off track
        Vector3 arrowOffset;

        if (pathDir == GameDefine.Direction.Forward)
        {
            if (System.Array.IndexOf(turns, GameDefine.Direction.Left) != -1)
            {
                arrowOffset = Vector3.right * f;
            }
            else
            {
                arrowOffset = Vector3.left * f;
            }
        }
        else
        {
            arrowOffset = Vector3.back * f;
        }

        arrowOffset.y       = arrow.localPosition.y;
        arrow.localPosition = arrowOffset;
        transform.position  = pos;

        // Assign an initial rotation
        turn = Random.Range(0, 2);
        Vector3 initRot = RotationsByDirection[(int)turns[turn]];

        arrow.transform.eulerAngles   = initRot;
        bridgeR.transform.eulerAngles = initRot;
    }
コード例 #3
0
    public RoadUnit ExtendPath(RoadUnit road, int depth)
    {
        if (depth < 0)
        {
            return(road);
        }

        if (!road)
        {
            road = CreateRoad(Vector3.zero, GameDefine.Direction.Forward, 14, true);
        }

        if (depth == 0)
        {
            return(road);
        }

        if (road.arrow == null)
        {
            Vector3   crossingPoint = road.startPoint + road.length * RoadDirections[(int)road.direction];
            ArrowUnit arrow         = MainObjControl.Instant.arrowCtrl.CreateArrow(crossingPoint, road.direction);
            float[]   nextLengths   = { GameDefine.roadRandSize, GameDefine.roadRandSize };
            bool[]    colors        = { Random.value > 0.5 ? true : false, true };
            colors[1] = !colors[0];

            arrow.road = road;
            road.next  = new RoadUnit[2];

            for (int i = 0; i < 2; i++)
            {
                GameDefine.Direction turn = arrow.directions[i];
                bool  color      = colors[i];
                float nextLength = nextLengths[i];

                road.next[i]        = CreateRoad(crossingPoint, turn, nextLength, color);
                road.next[i].father = road;
                // MainObjControl.Instant.blockCtrl.GetBlock(crossingPoint, turn, color, true);
            }
            road.arrow = arrow;
        }

        if (depth >= 1)
        {
            foreach (RoadUnit nextRoad in road.next)
            {
                ExtendPath(nextRoad, depth - 1);
            }
        }

        return(road);
    }
コード例 #4
0
    IEnumerator GuideBall()
    {
        // By here the ball will give into arrow.Direction()

        // Wait for the wall to roll to the center of the crossing
        // Because Collider has a volume
        float rollToCenterTime = (collider.transform.position - ball.transform.position).magnitude / ball.speed;

        yield return(new WaitForSeconds(rollToCenterTime));

        // Change ball direction
        GameDefine.Direction direction = arrow.GetDirection();
        ball.SetDirection(direction);
    }
コード例 #5
0
    public void Play(Vector3 pos, GameDefine.Direction dir, string text, Color?color = null)
    {
        textPro.color = color.GetValueOrDefault(new Color(0.3679245f, 0.3679245f, 0.3679245f));

        pos.y = 1f;

        pos += 2f * (dir == GameDefine.Direction.Forward ? Vector3.forward :
                     dir == GameDefine.Direction.Left ? Vector3.left : Vector3.right);
        textObj.transform.position    = pos;
        textObj.transform.eulerAngles =
            dir == GameDefine.Direction.Forward ? Vector3.zero :
            dir == GameDefine.Direction.Left ? new Vector3(0, -90f, 0) : new Vector3(0, 90f, 0);

        textPro.text  = text;
        textPro.alpha = 1f;
    }
コード例 #6
0
    public BlockUnit GetExtraBlock(Vector3 crossingPos, GameDefine.Direction dir)
    {
        // Currently, diamond is the only extra block available
        Vector3 blockPos = crossingPos;

        blockPos  += BlockOffset[(int)dir] * 1.5f;
        blockPos.y = 2.6f;

        BlockUnit unit = Instantiate(diamondPrefab).GetComponent <BlockUnit>();

        unit.transform.position = blockPos;
        unit.SetVisible(true);
        unit.crossingPos = crossingPos;
        unit.direction   = dir;

        return(unit);
    }
コード例 #7
0
    public RoadUnit GetNextByDirection(GameDefine.Direction dir)
    {
        if (next == null)
        {
            return(null);
        }

        foreach (RoadUnit road in next)
        {
            if (road.direction == dir)
            {
                return(road);
            }
        }

        return(null);
    }
コード例 #8
0
    private void OnTriggerEnter(Collider other)
    {
        StartCoroutine(GuideBall());

        // Remove paths on the other direction
        GameDefine.Direction oppDir  = arrow.GetOppositeDirection();
        RoadUnit             oppRoad = arrow.road.GetNextByDirection(oppDir);

        roadCtrl.RemovePath(oppRoad, 1);

        //Remove previours useless paths
        roadCtrl.RemovePreviousPaths(playerCtrl.currentRoad);


        // Update player
        GameDefine.Direction aheadDir  = arrow.GetDirection();
        RoadUnit             aheadRoad = arrow.road.GetNextByDirection(aheadDir);

        playerCtrl.currentRoad = aheadRoad;
    }
コード例 #9
0
    public void Set(Vector3 startPoint, GameDefine.Direction direction, float length)
    {
        this.startPoint = startPoint;
        this.length     = length;
        this.direction  = direction;
        arrow           = null;
        block           = null;
        next            = null;

        Vector3 scale;
        Vector3 pos;

        float scaleLength = length - GameDefine.roadDistance;

        if (direction == GameDefine.Direction.Forward)
        {
            scale.x = GameDefine.roadWidth;
            scale.z = scaleLength;
            pos     = startPoint + Vector3.forward * (0.5f * GameDefine.roadWidth + 0.5f * scale.z + GameDefine.roadDistance);
        }
        else
        {
            scale.z = GameDefine.roadWidth;

            if (direction == GameDefine.Direction.Right)
            {
                scale.x = scaleLength;
                pos     = startPoint + Vector3.right * (0.5f * GameDefine.roadWidth + 0.5f * scale.x + GameDefine.roadDistance);
            }
            else
            {
                scale.x = scaleLength;
                pos     = startPoint + Vector3.left * (0.5f * GameDefine.roadWidth + 0.5f * scale.x + GameDefine.roadDistance);
            }
        }

        scale.y = GameDefine.roadTall;

        transform.localScale = scale;
        transform.position   = pos;
    }
コード例 #10
0
    public ArrowUnit CreateArrow(Vector3 forkPos, GameDefine.Direction pathDir)
    {
        GameDefine.Direction[] turns = new GameDefine.Direction[2];

        if (pathDir == GameDefine.Direction.Forward)
        {
            turns[0] = GameDefine.Direction.Forward;
            turns[1] = Random.value > 0.5 ? GameDefine.Direction.Right : GameDefine.Direction.Left;
        }
        else
        {
            turns[0] = pathDir;
            turns[1] = GameDefine.Direction.Forward;
        }

        // TODO: Create Fork
        ArrowUnit arrow = GetArrow();

        arrow.SetPosition(forkPos, pathDir, turns);
        arrow.directions = turns;

        return(arrow);
    }
コード例 #11
0
    // Return: Position of next crossing
    RoadUnit CreateRoad(Vector3 crossingPoint, GameDefine.Direction direction, float length, bool correctRoad)
    {
        // Add path to listRoadActive
        // Add block to listBlock

        bool      onRoad  = true;
        RoadUnit  newRoad = GetRoad();
        BlockUnit unit    = MainObjControl.Instant.blockCtrl.GetEntryBlock(crossingPoint, direction, correctRoad, onRoad);

        newRoad.Set(crossingPoint, direction, length);
        newRoad.block = unit;
        unit.road     = newRoad;

        // Randomly generate a diamond on the wrong road
        if (!correctRoad && Random.value < 0.5)
        {
            newRoad.extraBlocks.Add(MainObjControl.Instant.blockCtrl.GetExtraBlock(crossingPoint, direction));
        }

        activeRoads.Add(newRoad);
        activeBlocks.Add(unit);

        return(newRoad);
    }
コード例 #12
0
 public void SetDirection(GameDefine.Direction direction)
 {
     this.direction            = direction;
     rigidBody.angularVelocity = angularVelocity;
 }