Beispiel #1
0
    bool IsNextTileWillBeValid(RoadTile.Type type)
    {
        Vector2 nextTilePosition      = Vector2.zero;
        Vector2 simulatedOutDirection = GetNewOutDirection(type, lastOutDirection);

        nextTilePosition = lastOutDirection + simulatedOutDirection + standingTilePosition;

        return(!activeTileMap.ContainsKey(nextTilePosition));
    }
Beispiel #2
0
    Vector2 GetNewOutDirection(RoadTile.Type type, Vector2 lastOutDirection)
    {
        Vector2 newOutDirection = lastOutDirection;
        Vector2 left            = Vector2.Perpendicular(lastOutDirection);
        Vector2 right           = -left;

        if (type == RoadTile.Type.Right)
        {
            newOutDirection = right;
        }
        else if (type == RoadTile.Type.Left)
        {
            newOutDirection = left;
        }

        return(newOutDirection);
    }
Beispiel #3
0
    public void InstallTile(RoadTile.Type type, Vector3 position, Vector3 direction)
    {
        RoadTile installedTile = roadTilePool.GetFromPool(type);

        installedTile.transform.position = position;
        installedTile.transform.rotation = Quaternion.LookRotation(direction);

        Vector2 mapPosition = standingTilePosition + lastOutDirection;

        activeTileMap.Add(mapPosition, installedTile);

        lastWorldPoint = position;

        if (type != RoadTile.Type.Straight)
        {
            Rotator rotator;

            RotatorLink rotatorLink = installedTile.GetComponent <RotatorLink>();

            if (roadTilePool[roadTilePool.InstantiatedCount - 2].TileType != type)
            {
                rotator = rotatorPool.GetFromPool();

                float clockwiseValue;
                if (installedTile.TileType == RoadTile.Type.Left)
                {
                    clockwiseValue = -1;
                }
                else
                {
                    clockwiseValue = 1;
                }
                rotator.ApplyInstallProcess(clockwiseValue);
                rotatorLink.InstallRotator(rotator);
            }
            else
            {
                rotatorLink.Rotator = roadTilePool[roadTilePool.InstantiatedCount - 2].GetComponent <RotatorLink>().Rotator;
            }
        }

        installedTile.ApplyInstallProcess(direction, position, mapPosition);
    }
Beispiel #4
0
    void Generate()
    {
        while (!HasEscapedCamera())
        {
            //Select a type.
            bool          tileApproved = false;
            RoadTile.Type selectedType = RoadTile.Type.Straight;

            while (!tileApproved)
            {
                float turnRoll = Random.Range(0, 1f);

                if (turnRoll > 1 - turnPossibility)
                {
                    //Turn it is;
                    if (0.5f > Random.Range(0, 1f))
                    {
                        selectedType = RoadTile.Type.Left;
                        if (oppositionCount < 0)
                        {
                            selectedType = RoadTile.Type.Right;
                        }
                    }
                    else
                    {
                        selectedType = RoadTile.Type.Right;
                        if (oppositionCount > 0)
                        {
                            selectedType = RoadTile.Type.Left;
                        }
                    }
                }
                else
                {
                    //Straight!!!
                    selectedType = RoadTile.Type.Straight;
                }

                tileApproved = IsNextTileWillBeValid(selectedType);

                if (tileApproved)
                {
                    if (selectedType == RoadTile.Type.Left)
                    {
                        oppositionCount -= 1;
                    }
                    else if (selectedType == RoadTile.Type.Right)
                    {
                        oppositionCount += 1;
                    }
                }

                tryCounter += 1;
                if (tryCounter == 10000)
                {
                    Debug.Log("I AM OUT at = " + roadTilePool.InstantiatedCount);
                    break;
                }
            }

            if (tryCounter == 10000)
            {
                enabled = false;
                break;
            }
            else
            {
                tryCounter = 0;
            }

            InstallTile(selectedType, roadTilePool.LastInstantiated.OutPoint.position, roadTilePool.LastInstantiated.OutPoint.forward);

            standingTilePosition += lastOutDirection;
            lastOutDirection      = GetNewOutDirection(selectedType, lastOutDirection);
        }
    }