Пример #1
0
    private static HashSet <Vector2Int> floodFillGenMap(Vector2Int startCell, TileObject[,] m, ITypeGrid typeGrid)
    {
        HashSet <Vector2Int> FloodedCells = new HashSet <Vector2Int>()
        {
            startCell
        };

        Queue <Vector2Int> queue = new Queue <Vector2Int>()
        {
        };

        queue.Enqueue(startCell);

        TileObject t = m[startCell.x, startCell.y];

        while (queue.Count > 0)
        {
            Vector2Int   Cell  = queue.Dequeue();
            Vector2Int[] Cells = Utility.getAllNeighbours_General(Cell, typeGrid, m.GetLength(0), m.GetLength(1));

            foreach (Vector2Int c in Cells)
            {
                if (t == m[c.x, c.y])
                {
                    if (!FloodedCells.Contains(c))
                    {
                        queue.Enqueue(c);
                    }
                    FloodedCells.Add(c);
                }
            }
        }

        return(FloodedCells);
    }
Пример #2
0
    public static float BinaryMapSimilarity(TileObject[,] mainMap, TileObject[,] Alias, Vector2Int startMainMap, Vector2Int startAlias)
    {
        float similarity = 0f;

        int lX = Mathf.Min(startMainMap.x, startAlias.x);
        int hX = Mathf.Min(mainMap.GetLength(0) - startMainMap.x - 1, Alias.GetLength(0) - startAlias.x - 1);
        int lY = Mathf.Min(startMainMap.y, startAlias.y);
        int hY = Mathf.Min(mainMap.GetLength(1) - startMainMap.y - 1, Alias.GetLength(1) - startAlias.y - 1);


        for (int i = -lX; i <= hX; i++)
        {
            for (int j = -lY; j <= hY; j++)
            {
                for (int h = -lX; h <= hX; h++)
                {
                    for (int k = -lY; k <= hY; k++)
                    {
                        int sign = (mainMap[startMainMap.x + i, startMainMap.y + j].type == IGenerator.wallChar ? 1 : 0) - (Alias[startAlias.x + i, startAlias.y + j].type == IGenerator.wallChar ? 1 : 0);
                        sign *= (mainMap[startMainMap.x + h, startMainMap.y + k].type == IGenerator.wallChar ? 1 : 0) - (Alias[startAlias.x + h, startAlias.y + k].type == IGenerator.wallChar ? 1 : 0);

                        if (sign != 0)
                        {
                            similarity += sign * functionPointsDifference(new Vector2(startMainMap.x + i, startMainMap.y + j), new Vector2(startAlias.x + h, startAlias.y + k));
                        }
                    }
                }
            }
        }

        return(similarity);
    }
Пример #3
0
 public void DisplayMap(TileObject[,] map, Transform container, ITypeGrid gridType)
 {/*                                                                     DA FIXARE!
   * if (map.GetLength(0) * map.GetLength(1) > thresholdToCompositeImage)
   *     printCompositeMap(container, gridType, map, 0);
   * else*/
     printMap(container, gridType, map);
 }
Пример #4
0
    public void generateButtonPressed()
    {
        GeneratorUIManager.Instance.disableGenerateButton();
        GeneratorUIManager.Instance.deleteMapOnUI(Content.transform);

        try
        {
            validateGeneratorParams(GeneratorsVect[(int)activeGenerator]);
            GeneratorsVect[(int)activeGenerator].TypeGrid = TypeGridVect[(int)activeTypeGrid];  //Typegrid change in generator
            TileObject[,] map = GeneratorsVect[(int)activeGenerator].initializeMap();

            GeneratorsVect[(int)activeGenerator].generateMap();
            GeneratorsVect[(int)activeGenerator].postprocessMap();


            if (GeneratorsVect[(int)activeGenerator].useRandomSeed)
            {
                GeneratorUIManager.Instance.gameObject.GetComponent <UIParametersValueChange>().refreshUIParams();
            }

            dataMap = MapEvaluator.computeMetrics(GeneratorsVect[(int)activeGenerator].getMap(), GeneratorsVect[(int)activeGenerator].TypeGrid, GeneratorsVect[(int)activeGenerator].startPos, GeneratorsVect[(int)activeGenerator].endPos);
            DisplayMainMap((GeneratorUIManager.Instance.isTrapsOnMapBorderToggleOn() ? GeneratorsVect[(int)activeGenerator].getMapWTrapBorder() : GeneratorsVect[(int)activeGenerator].getMap()));
            GeneratorUIManager.Instance.showUIMapInfo(MapHolder.transform, dataMap, GeneratorsVect[(int)activeGenerator].TypeGrid);
        }
        catch (Exception e) {
            ErrorManager.ManageError(ErrorManager.Error.SOFT_ERROR, e.Message);
        }

        GeneratorUIManager.Instance.enableGenerateButton();
    }
 public StructuredAlias(TileObject[,] a)
 {
     AliasMap           = a;
     start              = new Vector2Int(-1, -1);
     end                = new Vector2Int(-1, -1);
     similarityDistance = -1;
 }
Пример #6
0
        //private const float ambientLightLevel = 1;

        public TileObject[,] LightPass(TileObject[,] tileData, int dist)
        {
            //int degOffset = 360 / rayCount; // should give a multiplier (ONLY IF NO DECIMAL PRODUCT!!!)
            //here we process line of sight for lightsources

            //Get the new ambientLightLevel from the clock
            // it seems we want pow(e, (-pow(currentHour - totalHours/2, 2) / totalHours))
            ambientLightLevel = Mathf.Pow(logE, (-Mathf.Pow((Clock.currentHour - Clock.totalHours / 2), 2) / Clock.totalHours));
            if (ambientLightLevel <= 0.15f)
            {
                ambientLightLevel = 0.15f;
            }

            List <Vector2Int> lightPositions = new List <Vector2Int>();

            for (int y = 0; y < MapViewport.viewPortRadius; y++)
            {
                for (int x = 0; x < MapViewport.viewPortRadius; x++)
                {
                    tileData[x, y].tile.color = new Color(ambientLightLevel, ambientLightLevel, ambientLightLevel);
                    if (tileData[x, y].lightSource && lightPositions.Count < maxLightsInView)
                    {
                        lightPositions.Add(new Vector2Int(x, y));
                    }
                }
            }

            //Now we use these lightPositions as a basis to create the lights in the viewport
            foreach (var light in lightPositions)
            {
                tileData = DrawLight(tileData, light.x, light.y, dist);
            }

            return(tileData);
        }
Пример #7
0
    TileObject[,] tiles;  //change to basetile?

    void Awake()
    {
        int gridSize = GameObject.Find("Managers").GetComponent <GridManager>().gridSize;

        tiles = new TileObject[gridSize, gridSize];
        units = new Unit[gridSize, gridSize];
    }
Пример #8
0
 public Room(int width, int height)
 {
     this.width   = width;
     this.height  = height;
     this.objects = new TileObject[width, height];
     buildTempMap();
 }
 public StructuredAlias(TileObject[,] a, Vector2Int b, Vector2Int c, float d)
 {
     AliasMap           = a;
     start              = b;
     end                = c;
     similarityDistance = d;
 }
Пример #10
0
        public TileObject(ContentManager Content, TileObject[,] tileGrid, int row, int col, char inputChar)
        {
            this.tileGrid          = tileGrid;
            this.StartingInputChar = inputChar;
            Row          = row;
            Col          = col;
            Position.X   = col * Globals.MAP_TILE_PIXEL_SIZE + Globals.MAP_X_OFFSET;
            Position.Y   = row * Globals.MAP_TILE_PIXEL_SIZE + Globals.MAP_Y_OFFSET;
            this.Content = Content;

            switch (inputChar)
            {
            case 'o':
                Type = TileType.BigDot;
                break;

            case '<':
                Type = TileType.BottomLeftCorner;
                break;

            case '>':
                Type = TileType.BottomRightCorner;
                break;

            /*case '.':
             *  Type = TileType.Cherry;
             *  break;*/
            case 'g':
                Type = TileType.Gate;
                break;

            case '-':
                Type = TileType.HorizontalWall;
                break;

            case '.':
                Type = TileType.SmallDot;
                break;

            case '/':
                Type = TileType.TopLeftCorner;
                break;

            case '\\':
                Type = TileType.TopRightCorner;
                break;

            case '|':
                Type = TileType.VerticalWall;
                break;

            default:
                Type = TileType.Empty;
                break;
            }

            Scale  = (float)Globals.MAP_TILE_PIXEL_SIZE / (float)Sprite.Height;
            Center = new Vector2(Sprite.Width / 2, Sprite.Height / 2);
        }
Пример #11
0
    public void ScaleToFitContainerWPadding(RectTransform contentRect, TileObject[,] map, ITypeGrid tG)
    {
        RectTransform prefabRect = tG.TilePrefab.GetComponent <RectTransform>();

        contentRect.localScale = Vector3.one;
        contentRect.sizeDelta  = new Vector2(map.GetLength(0) * prefabRect.sizeDelta.x + paddingContent, map.GetLength(1) * prefabRect.sizeDelta.y + paddingContent);

        ScaleToFitContainer(contentRect);
    }
Пример #12
0
    public static void buildRoomsOnMap(TileObject[,] map, Vector2Int[] walls)
    {
        int i = 0;

        while (i < walls.Length)
        {
            map[walls[i].x, walls[i].y].type = IGenerator.roomChar;
            i++;
        }
    }
Пример #13
0
 public TileMap(TextureMap map, Point start)
 {
     this.tileTextureMap       = map._textureMap;
     this.tileObjectTextureMap = map._objectTextureMap;
     this._tiles         = new Tile[this.MapHeight, this.MapWidth];
     this._tileObjects   = new TileObject[this.MapHeight, this.MapWidth];
     this._startLocation = start;
     this._camera        = new Camera(this._startLocation, this);
     this._players       = new List <Player>();
     this._observers     = new List <TileObject>();
 }
Пример #14
0
 public TileMap(TextureMap map, Point start)
 {
     this.tileTextureMap = map._textureMap;
     this.tileObjectTextureMap = map._objectTextureMap;
     this._tiles = new Tile[this.MapHeight, this.MapWidth];
     this._tileObjects = new TileObject[this.MapHeight, this.MapWidth];
     this._startLocation = start;
     this._camera = new Camera(this._startLocation, this);
     this._players = new List<Player>();
     this._observers = new List<TileObject>();
 }
Пример #15
0
        private TileObject[,] DrawLight(TileObject[,] tileData, int x, int y, int dist)
        {
            tileData[x, y].tile.color = new Color(1, 1, 1);
            int degOffset = 360 / rayCount;

            for (int i = 0; i < rayCount; i++)
            {
                int   deg = i * degOffset;
                float rad = (float)deg * Mathf.Deg2Rad;
                //We need to get the hypothanuse of a right triangle where x is dist and the angle is deg
                int tileX = Mathf.RoundToInt(Mathf.Cos(rad) * (float)dist) + x;
                int tileY = Mathf.RoundToInt(Mathf.Sin(rad) * (float)dist) + y;

                int d = DiagonalDistance(x, y, tileX, tileY);

                for (int j = 0; j < d; j++)
                {
                    int   tx    = Mathf.RoundToInt(Mathf.Lerp(x, tileX, j / (float)d));
                    int   ty    = Mathf.RoundToInt(Mathf.Lerp(y, tileY, j / (float)d));
                    float cMult = 1 - ((j + 1) / (float)d);
                    if (cMult < ambientLightLevel)
                    {
                        cMult = ambientLightLevel;
                    }

                    //CHECK BOUNDS!
                    if (tx < 0 || tx >= MapViewport.viewPortRadius)
                    {
                        continue;
                    }
                    if (ty < 0 || ty >= MapViewport.viewPortRadius)
                    {
                        continue;
                    }


                    if (tileData[tx, ty].tile.color.r < cMult)
                    {
                        tileData[tx, ty].tile.color = new Color(cMult, cMult, cMult, 1);
                    }

                    if (tx == x && ty == y)
                    {
                        continue;
                    }
                    if (tileData[tx, ty].collider && !tileData[tx, ty].transparent)
                    {
                        break;
                    }
                }
            }

            return(tileData);
        }
Пример #16
0
        private void Awake()
        {
            // Initializing two arrays ona for holding cards center global positions and second one for all nodeHolders on the scene in proper grid order
            _nodeObjects   = new TileObject[gridSize.x * 2, gridSize.y * 2];
            _cardPositions = new Vector2[gridSize.x, gridSize.y];

            for (int y = 0; y < gridSize.y; y++)
            {
                for (int x = 0; x < gridSize.x; x++)
                {
                    Card current = cards[Random.Range(0, cards.Length)];    // Getting random card

                    //Instantiating the card and receiving its nodes
                    Tile[] nodes = InstantiateNode(current, new Vector2Int(x, y));

                    for (int n = 0; n < nodes.Length; n++)
                    {
                        // Generating node position according to its card and location in it
                        Vector2Int nodePos = new Vector2Int();

                        nodePos.y = Mathf.FloorToInt(n / 2);
                        nodePos.x = n % 2;

                        // As nodes goes not usual row by row, but in the circle - shift in x position is required
                        if (n == 2)
                        {
                            nodePos.x += 1;
                        }
                        if (n == 3)
                        {
                            nodePos.x -= 1;
                        }

                        // Instantiating node holder to the scene to current node position
                        TileObject tile = Instantiate(tileObject,
                                                      new Vector3(_cardPositions[x, y].x + (nodePos.x * tileSize - tileSize / 2), _cardPositions[x, y].y - (nodePos.y * tileSize - tileSize / 2), transform.position.z),
                                                      Quaternion.identity, tilesRoot).GetComponent <TileObject>();
                        tile.gameObject.name = "Node :" + (nodePos.x + x * 2) + " : " + (nodePos.y + y * 2);

                        tile.Init(nodes[n]);                                               // Init node holder with node data
                        tile.neighbors = new TileObject[4];                                // Init array of neighbors (4 directions)

                        _nodeObjects[nodePos.x + x * 2, nodePos.y + y * 2] = tile;         // Add node to _nodesArray to its proper position on the grid
                    }
                }
            }

            // Placing chips on left top corner and right bottom one
            PlaceChips();

            // Setting up neighbors for all nodes
            PropagateNeighbors();
        }
Пример #17
0
    public static Vector2Int[] isEndReachable(TileObject[,] map, ITypeGrid TypeGrid, Vector2Int start, Vector2Int end, bool IsAutoSOn)
    {
        Vector2Int[] solSteps = Search_AStar(map, TypeGrid, start, end);
        if (solSteps.First() != end && IsAutoSOn)
        {
            Utility.buildRoomsOnMap(map, walkSquareGrid(solSteps.First(), end));
            map[end.x, end.y].type = IGenerator.endChar;
            solSteps = Search_AStar(map, TypeGrid, start, end);
        }

        return(solSteps);
    }
Пример #18
0
 /// <summary>
 /// Inits the map with default values
 /// </summary>
 private void InitMap()
 {
     centerPoints = new List <TileObject>();
     map          = new TileObject[w, h];
     for (int i = 0; i < w; ++i)
     {
         for (int j = 0; j < h; ++j)
         {
             map[i, j] = new TileObject(i, j);
         }
     }
 }
Пример #19
0
    //modified version of the A_star. If a solving path exists, returns it otherwise put the visited cells where the last one is the closest ot the end cell
    public static Vector2Int[] Search_AStar(TileObject[,] map, ITypeGrid TypeGrid, Vector2Int start, Vector2Int end)
    {
        Hashtable CameFrom = new Hashtable();
        SimplePriorityQueue <Vector2Int> frontier = new SimplePriorityQueue <Vector2Int>();

        LinkedList <Vector2Int> SolutionPath = new LinkedList <Vector2Int>();

        frontier.Enqueue(start, 0);

        CameFrom[start]            = null;
        map[start.x, start.y].Cost = 0;

        Vector2Int closestCell = new Vector2Int(start.x, start.y);

        while (frontier.Count > 0)
        {
            Vector2Int current = frontier.Dequeue();
            //TEORICAMENTE LA TROVA DA SOLA
            closestCell = (TypeGrid.heuristic(current, end) < TypeGrid.heuristic(closestCell, end) ? current : closestCell);

            if (current.Equals(end))
            {
                break;
            }
            foreach (Vector2Int next in Utility.getNeighbours_General(map, current, TypeGrid, map.GetLength(0), map.GetLength(1)))
            {
                double newCost = map[current.x, current.y].Cost + 1;
                if (!CameFrom.Contains(next) || newCost < map[next.x, next.y].Cost)
                {
                    map[next.x, next.y].Cost = (int)newCost;
                    double priority = newCost + TypeGrid.heuristic(next, end);
                    frontier.Enqueue(next, (float)priority);
                    CameFrom[next] = current;
                }
            }
        }

        //if a path exists, closestCell==end otherwise is the last cell expanded
        Vector2Int cameValue = new Vector2Int(closestCell.x, closestCell.y);

        SolutionPath.AddLast(closestCell);

        while (CameFrom[cameValue] != null)
        {
            cameValue = (Vector2Int)CameFrom[cameValue];
            SolutionPath.AddLast(cameValue);
        }


        //if a path exists, the last cell is the end one
        return(SolutionPath.ToArray());
    }
Пример #20
0
        public Terrain()
        {
            tileReferences = new Point[size.X, size.Y];
            tileObjects    = new TileObject[size.X, size.Y];
            materials      = new Material[size.X, size.Y];

            for (int i = 0; i < size.X; i++)
            {
                for (int j = 0; j < size.Y; j++)
                {
                    materials[i, j]      = (Material)(Game1.random.Next(Enum.GetNames(typeof(Material)).Length));
                    tileReferences[i, j] = new Point(-1);
                }
            }
        }
Пример #21
0
    /// <summary>
    /// Will spawn a resource obstacle directly in the coordinates
    /// </summary>
    /// <param name="xPos">X Position of the obstacle</param>
    /// <param name="zPos">Z Position of the obstacle</param>
    // ObstacleObject SpawnObstacle(float xPos, float zPos)
    // {
    //     //It has a 50% percent of spawning a wood obstacle
    //     bool isWood = Random.value <= 0.5f;

    //     GameObject spawnedObstacle = null;

    //     //Check whether we spawn a wood obstacle or a stone obstacle
    //     if (isWood)
    //     {
    //         spawnedObstacle = Instantiate(woodPrefab);
    //         spawnedObstacle.name = "Wood " + xPos + " - " + zPos;
    //     }
    //     else
    //     {
    //         spawnedObstacle = Instantiate(rockPrefab);
    //         spawnedObstacle.name = "Stone " + xPos + " - " + zPos;
    //     }

    //     //Sets the position and the parent of the spawned resource.
    //     spawnedObstacle.transform.position = new Vector3(xPos, tileEndHeight, zPos);
    //     spawnedObstacle.transform.SetParent(resourcesHolder);

    //     return spawnedObstacle.GetComponent<ObstacleObject>();
    // }

    /// <summary>
    /// Create tile grid to add buildings.
    /// </summary>
    public void CreateGrid(List <TileObject> refVisualGrid)
    {
        //Set the size of our tile grid.
        tileGrid = new TileObject[levelWidth, levelLength];

        //Iterates through all of the tile grid
        for (int x = 0; x < levelWidth; x++)
        {
            for (int z = 0; z < levelLength; z++)
            {
                //Connects the tile grid directly to the visual grid.
                tileGrid[x, z] = refVisualGrid.Find(v => v.xPos == x && v.zPos == z);
                //Debug.Log(tileGrid[x, z].gameObject.name);
            }
        }
    }
Пример #22
0
        public TileObject[,] RenderEntitiesWithLighting(TileObject[,] backgroundData)
        {
            int halfWidth = ((MapViewport.viewPortRadius - 1) / 2);

            //Instead of doing this, the player will be in the entityManager and be parsed with the other entities for rendering!
            for (int i = 0; i < entityRenderBuffer.Count; i++)
            {
                Tile tile = (Tile)ScriptableObject.CreateInstance(typeof(Tile));
                tile.sprite = entityRenderBuffer[i].bufferData[entityRenderBuffer[i].bufferIndex];
                tile.color  = backgroundData[entityRenderBuffer[i].x + halfWidth, entityRenderBuffer[i].y + halfWidth].tile.color;
                entityViewport.SetTile(entityViewport.WorldToCell(new Vector3Int(entityRenderBuffer[i].x, entityRenderBuffer[i].y, 0)), tile);
            }

            lastUpdateBackgroundData = backgroundData;
            return(backgroundData);
            // go trough the entityRenderBuffer and for each object, create a tile, set it's color and place it on the entityTilemap
        }
    public Dictionary <int, StructuredAlias> .ValueCollection generateAliasOnTheFly()
    {
        mainMap          = ParameterManager.Instance.MapToPlay;
        gridType         = ParameterManager.Instance.GridType;
        SimilarMapsQueue = new SimplePriorityQueue <TileObject[, ]>();
        K_CollisionSet   = MapEvaluator.BuildKCollisionVec(mainMap, gridType, ParameterManager.Instance.StartCell, Mathf.Max(ParameterManager.Instance.minStepsSolution, ParameterManager.Instance.maxStepsSolution));
        GenerateAndTestAliasMaps();
        Dictionary <int, StructuredAlias> dic = new Dictionary <int, StructuredAlias>();

        int i = UnityEngine.Random.Range(3, 7); //try to change

        while (i > 0)
        {
            dic.Add(i, new StructuredAlias(SimilarMapsQueue.Dequeue()));
            i--;
        }

        return(dic.Values);
    }
Пример #24
0
    public static HashSet <Vector2Int>[] BuildKCollisionVec(TileObject[,] map, ITypeGrid TypeGrid, Vector2Int start, int lookahead)
    {
        int i;
        HashSet <Vector2Int> visited = new HashSet <Vector2Int>();

        visited.Add(start);

        HashSet <Vector2Int>[] KCollisionCells = new HashSet <Vector2Int> [lookahead + 1];//plus 1 since the 0 position is the cells found at zero steps i.e. start cell and so on


        for (i = 0; i < KCollisionCells.Length; i++)
        {
            KCollisionCells[i] = new HashSet <Vector2Int>();
        }

        KCollisionCells[0].Add(Vector2Int.zero);
        i = 1;
        while (i <= lookahead)
        {
            foreach (Vector2Int curr in KCollisionCells[i - 1])
            {
                Vector2Int mainMapPos = new Vector2Int(start.x + curr.x, start.y + curr.y);
                if (map[mainMapPos.x, mainMapPos.y].type != IGenerator.wallChar)
                {
                    foreach (Vector2Int next in Utility.getAllNeighbours_General(mainMapPos, TypeGrid, map.GetLength(0), map.GetLength(1)))
                    {
                        if (!visited.Contains(next) && Utility.in_bounds_General(next, map.GetLength(0), map.GetLength(1)))
                        {
                            KCollisionCells[i].Add(next - start);//start is subtracted since the collision list must be absolute and not relative wrt startcell of mainmap
                            visited.Add(next);
                        }
                    }
                }
            }


            i++;
        }



        return(KCollisionCells);
    }
Пример #25
0
    //this version get all neighbours walls excluded: is a more general version
    public static Vector2Int[] getNeighbours_General(TileObject[,] map, Vector2Int id, ITypeGrid TypeGrid, int width, int height)
    {
        Vector2Int[] results = new Vector2Int[] { };

        foreach (Vector2Int dir in TypeGrid.getDirs())
        {
            Vector2Int next = new Vector2Int(id.x + dir.x, id.y + dir.y);
            if (in_bounds_General(next, width, height) && passable_General(next, map))
            {
                Array.Resize(ref results, results.Length + 1);
                results[results.GetUpperBound(0)] = next;
            }
        }

        if ((id.x + id.y) % 2 == 0)
        {
            Array.Reverse(results);
        }

        return(results);
    }
Пример #26
0
        public static void LoadContent(ContentManager Content)
        {
            // Initialize Tile and Collision Grid
            TileGrid = new TileObject[Globals.MAP_NUM_OF_VERTICAL_TILES, Globals.MAP_NUM_OF_HORIZONTAL_TILES];

            // Read ASCII map. Populate Tile and Collision grid
            TextReader reader      = new StreamReader("map.txt", Encoding.ASCII);
            string     inputString = reader.ReadToEnd().Replace("\r", "").Replace("\n", "");

            char input;
            int  count = 0;

            for (int row = 0; row < Globals.MAP_NUM_OF_VERTICAL_TILES; row++)
            {
                for (int col = 0; col < Globals.MAP_NUM_OF_HORIZONTAL_TILES; col++)
                {
                    input = inputString[count++];
                    TileGrid[row, col] = new TileObject(Content, TileGrid, row, col, input);
                }
            }

            HealTile = GetTile('H');
        }
Пример #27
0
    private TileObject[,] CreateMapWithBorder()
    {
        switch (TypeGrid.gridType)
        {
        case ITypeGrid.TypeGridEnum.SQUARE:
            tmpMapWBorder = new TileObject[map.GetLength(0) + 2, map.GetLength(1) + 2];

            for (int i = 0; i < tmpMapWBorder.GetLength(0); i++)
            {
                for (int j = 0; j < tmpMapWBorder.GetLength(1); j++)
                {
                    if (i > 0 && i < tmpMapWBorder.GetLength(0) - 1 && j > 0 && j < tmpMapWBorder.GetLength(1) - 1)
                    {
                        tmpMapWBorder[i, j].type = map[i - 1, j - 1].type;
                    }
                    else
                    {
                        tmpMapWBorder[i, j].type = IGenerator.wallChar;
                    }
                }
            }
            break;

        case ITypeGrid.TypeGridEnum.HEXAGON:
            break;

        case ITypeGrid.TypeGridEnum.TRIANGLE:
            break;

        default:
            ErrorManager.ManageError(ErrorManager.Error.SOFT_ERROR, "Incorrect grid type.");
            break;
        }

        return(tmpMapWBorder);
    }
Пример #28
0
    public void printMap(Transform t, ITypeGrid g, TileObject[,] map)
    {
        t.localScale = Vector3.one;

        RectTransform contentRect = t.gameObject.GetComponent <RectTransform>();

        float displX = (map.GetLength(0) % 2 == 0 ? .5f : 0f);
        float displY = (map.GetLength(1) % 2 == 0 ? .5f : 0f);

        RectTransform prefabRect = g.TilePrefab.GetComponent <RectTransform>();



        for (int x = 0; x < map.GetLength(0); x++)
        {
            for (int y = 0; y < map.GetLength(1); y++)
            {
                Vector3 tilePosition = new Vector3((-map.GetLength(0) / 2 + displX + x) * g.offsetX * prefabRect.sizeDelta.x, (-map.GetLength(1) / 2 + displY + y) * g.offsetY * prefabRect.sizeDelta.y, 0);

                GameObject newTile = Instantiate(g.TilePrefab, Vector3.zero, Quaternion.identity) as GameObject;
                applyTileColor(newTile, map[x, y].type);
                RectTransform newTileRect = newTile.GetComponent <RectTransform>();
                newTileRect.SetParent(contentRect);

                newTileRect.localScale       = Vector3.one * (1 - outlinePercent);
                newTileRect.anchoredPosition = tilePosition;

                if (map[x, y].type == IGenerator.startChar)
                {
                    originUIMap = new Vector2(tilePosition.x, tilePosition.y);
                }
            }
        }

        ScaleToFitContainerWPadding(contentRect, map, g);
    }
Пример #29
0
    }                                                             //a postprocessing operation of map is optionally available for inherited classes

    public virtual TileObject[,] generateAliasMap(TileObject[,] MainMap, HashSet <Vector2Int> CollisionCells)
    {
        return(map);
    }                                                                                                                       //SWITCH TO ABSTRACT AS SOON AS POSSIBLE
Пример #30
0
 private void Awake()
 {
     m_grid = new TileObject[Map.MAP_SIZE, Map.MAP_SIZE];
 }
Пример #31
0
 public static bool passable_General(Vector2Int id, TileObject[,] map)
 {
     return(map[id.x, id.y].type != IGenerator.wallChar);
 }