Esempio n. 1
0
    public void AddTile(MapGenerator.TrackTile tile, Tile LastTile)
    {
        entrancePos     = LastTile.exitPos;
        rotAnterior     = LastTile.outPutRot;
        isTheLastACurve = LastTile.isCurved;
        index           = tile.index;
        isCurved        = tile.isCurve;
        size            = new Vector2(tile.SizeX, tile.SizeY);
        step            = new Vector2(tile.StepX, tile.StepY);

        originalInfo = tile;

        AjustRotation();
    }
Esempio n. 2
0
    public void AddFirstTile(Vector2 entPos, MapGenerator.TrackTile tile, Vector2 direct, RotationState rotState, bool isCurve)
    {
        direction    = direct;
        originalInfo = tile;
        index        = tile.index;
        entrancePos  = entPos;
        size         = new Vector2(tile.SizeX, tile.SizeY);
        step         = new Vector2(tile.StepX, tile.StepY);

        rotation  = rotState;
        outPutRot = RotationState.Left;
        isCurved  = tile.isCurve;
        ExitPos();
    }
Esempio n. 3
0
    public void Place(MapGenerator.TrackTile Selected, Vector3 posToPlace, Transform posRef)
    {
        if (tileTracksIndex > 0)
        {
            posToPlace.x = tileTracks[tileTracksIndex - 1].exitPos.x;
            posToPlace.y = tileTracks[tileTracksIndex - 1].exitPos.y;
        }
        for (int i = 0; i < tileTracksIndex; i++)
        {
            //Debug.Log("posToPlace " + posToPlace);
            //Debug.Log("tile[i].transform.position " + tile[i].transform.position);
            if (posToPlace == tile[i].transform.position && Selected.name != "Final")
            {
                canBePlaced = false;
                erroScreen.SetActive(true);
                break;
            }
            else
            {
                canBePlaced = true;
            }
        }
        canBePlaced = false;
        for (int x = 0; x < GridSize; x++)
        {
            for (int y = 0; y < GridSize; y++)
            {
                Debug.Log("Pos to Place: " + posToPlace + "Grid Pos: " + Grid[x, y].transform.position);
                if (posToPlace == Grid[x, y].transform.position)
                {
                    Debug.Log("Pos to Place: " + posToPlace);
                    canBePlaced = true;
                    break;
                }
                else
                {
                    canBePlaced = false;
                }
            }
            if (canBePlaced)
            {
                break;
            }
        }
        if (!canBePlaced)
        {
            erroScreen.SetActive(true);
            ClearTrackFromTouchPos(tileTracksIndex - 2);
        }
        if (canBePlaced && !FinalHasBeenPlaced)
        {
            // A track is beeing placed in the seleceted pos
            tile.Add(Instantiate(Selected.image, posToPlace, Quaternion.identity, posRef));
            tileTracks.Add(new Tile());
            Vector3 TileScale = tileTracks[tileTracksIndex].Scale;

            tile[tileTracksIndex].transform.localScale = new Vector3((width / GridSize - 1) * Scale * TileScale.x, (height / GridSize - 1) * Scale * TileScale.y, 1 * TileScale.z);



            if (tileTracksIndex > 0)
            {
                // Debug.Log("UsingExit");
                //tileTracks[tileTracksIndex].AddTile(tileTracks[tileTracksIndex - 1].exitPos, Selected, directionFlow, tileTracks[tileTracksIndex - 1].rotation, tileTracks[tileTracksIndex - 1].originalInfo.isCurve);
                tileTracks[tileTracksIndex].AddTile(Selected, tileTracks[tileTracksIndex - 1]);
            }
            else
            {
                tileTracks[tileTracksIndex].AddFirstTile(new Vector2(posToPlace.x, posToPlace.y), Selected, directionFlow, Tile.RotationState.Left, false);
            }
            tile[tileTracksIndex].transform.rotation = Quaternion.Euler(tileTracks[tileTracksIndex].rot);
            //SpinLastTrack(tileTracksIndex);
            //Debug.Log(TileScale + "Instance");
            if (Selected.name == "Final")
            {
                FinalHasBeenPlaced = true;
                for (int i = 0; i < tileTracksIndex; i++)
                {
                    if (posToPlace == tile[i].transform.position && tileTracks[tileTracksIndex].outPutRot != tileTracks[i].rotation)
                    {
                        erroScreen.SetActive(true);
                        Debug.Log("Clear");
                        ClearTrackFromTouchPos(tileTracksIndex - 1);
                    }
                }
                if (tile[tileTracksIndex].transform.position == tile[0].transform.position)
                {
                    MapInfo.isLoop = true;
                    LoopScreen.SetActive(true);
                }
            }

            tileTracksIndex++;
            //canBePlaced = true;
        }
        FindObjectOfType <UiManager>().ShowTabs();
    }