示例#1
0
    public void RemovePath(RoadUnit road, int keepDepth)
    {
        if (road == null)
        {
            return;
        }

        if (road.next != null)
        {
            foreach (RoadUnit nextRoad in road.next)
            {
                RemovePath(nextRoad, keepDepth - 1);
            }
        }

        if (keepDepth <= 0)
        {
            road.gameObject.SetActive(false);
            if (road.arrow != null)
            {
                road.arrow.gameObject.SetActive(false);
            }
            if (road.block != null)
            {
                road.block.gameObject.SetActive(false);
            }
            foreach (BlockUnit blk in road.extraBlocks)
            {
                blk.gameObject.SetActive(false);
            }
        }
    }
示例#2
0
    void Awake()
    {
        player = MainObjControl.Instant.playerCtrl;

        RoadUnit rootRoad = ExtendPath(null, 1);

        player.currentRoad = rootRoad;
    }
示例#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
    public void RemovePreviousPaths(RoadUnit road)
    {
        if (road.GetFather() == null)
        {
            return;
        }
        RoadUnit grandfatherRoad = road.GetFather().GetFather();

        if (grandfatherRoad == null)
        {
            RoadUnit freeRoad = road.GetFather();
            freeRoad.gameObject.SetActive(false);
            if (freeRoad.arrow != null)
            {
                freeRoad.arrow.gameObject.SetActive(false);
            }
            if (freeRoad.block != null)
            {
                freeRoad.block.gameObject.SetActive(false);
            }
            foreach (BlockUnit blk in freeRoad.extraBlocks)
            {
                blk.gameObject.SetActive(false);
            }
            return;
        }
        foreach (RoadUnit freeRoad in grandfatherRoad.next)
        {
            freeRoad.gameObject.SetActive(false);
            if (freeRoad.arrow != null)
            {
                freeRoad.arrow.gameObject.SetActive(false);
            }
            if (freeRoad.block != null && freeRoad.direction != road.GetFather().direction)
            {
                freeRoad.block.gameObject.SetActive(false);
            }
            foreach (BlockUnit blk in freeRoad.extraBlocks)
            {
                blk.gameObject.SetActive(false);
            }
        }
        return;
    }
    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;
    }
示例#6
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);
    }