当前位置: 首页>>代码示例>>C#>>正文


C# TileType.GetLength方法代码示例

本文整理汇总了C#中TileType.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# TileType.GetLength方法的具体用法?C# TileType.GetLength怎么用?C# TileType.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileType的用法示例。


在下文中一共展示了TileType.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GrowAll

	/// <summary>
	/// Grows the minerals on the map.
	/// </summary>
	/// <param name="map">The map where the minerals spawn</param>
	/// <param name="biomeMap">The biome map attached to the previous map.</param>
	public void GrowAll (TileType[, ] map, BiomeType[, ] biomeMap) {

		NoiseGenerator gen = new NoiseGenerator ();

		while (availableMinerals.Count > 0) {

			MineralInfo mineral = availableMinerals.Dequeue();

			gen.Reset();

			for (int x = 0; x < map.GetLength(0); x ++) {

				int y = (mineral.minHeight > 0 ? mineral.minHeight : 0);
				int maxY = (mineral.maxHeight < map.GetLength(1) ? mineral.maxHeight : map.GetLength(1));

				for (; y < maxY; y ++) {

					if (IsTileCompatible(biomeMap, x, y, mineral.compatibleBiomes) && (mineral.rarity < (int) gen.PerlinNoise(x, y, 10, 100, 1)))
						PlaceMinerals(map, x, y, mineral.minerals);

				}
			}
		
		}

	}
开发者ID:Sphara,项目名称:The-Lonely...-Thing,代码行数:31,代码来源:MineralFarm.cs

示例2: TileMapBuilder

        /// <summary>
        /// Initializes a new instance of the TileMapBuilder class
        /// </summary>
        /// <param name="map">matrix of symbols</param>
        /// <param name="dictionary">dictionary with keys for the symbols</param>
        /// <param name="tileSize">Tile size</param>
        public TileMapBuilder(TileType[,] map, Dictionary<TileType, Bitmap> dictionary, int tileSize)
        {
            int mapRows = map.GetLength(0);
            int mapCols = map.GetLength(1);

            this.MapImage = new Bitmap(mapCols * tileSize, mapRows * tileSize);
            Graphics mapGraphics = Graphics.FromImage(this.MapImage);

            Bitmap tile;
            for (int row = 0; row < mapRows; row++)
            {
                for (int col = 0; col < mapCols; col++)
                {
                    tile = dictionary[map[row, col]];
                    int x = col * tileSize;
                    int y = row * tileSize;
                    mapGraphics.DrawImage(tile, x, y, tileSize, tileSize);
                }
            }
        }
开发者ID:jrusev,项目名称:Games,代码行数:26,代码来源:TileMapBuilder.cs

示例3: DetectSimilarBorderTiles

 //Detect if there is a similar tile next to the bordering tile
 private int DetectSimilarBorderTiles(TileType[,] area, TileType replaceTarget, int x_coord, int y_coord)
 {
     int count = 0;
     //Check if we are at the edge of the map, since taht would break the program
     if (x_coord > 0 && x_coord < area.GetLength (0) - 1 && y_coord > 0 && y_coord < area.GetLength (1) - 1) {
         //Directly touching the point
         if (area [x_coord - 1, y_coord + 0] == replaceTarget)
             count++;
         if (area [x_coord + 0, y_coord - 1] == replaceTarget)
             count++;
         if (area [x_coord + 1, y_coord + 0] == replaceTarget)
             count++;
         if (area [x_coord + 0, y_coord + 1] == replaceTarget)
             count++;
     }
     return count;
 }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:18,代码来源:TDMap.cs

示例4: Largest_Space

    public int Largest_Space(TileType[,] area, TileType scanTarget, List<Coord> topLeftCoords)
    {
        int[,] scanArea = new int[area.GetLength (0),area.GetLength (1)];
        int largestCount = 0;
        int currentCount = 0;
        Queue<Coord> coordQ = new Queue<Coord> ();
        Coord current;
        //This coord will be removed at the end of this function
        Coord largestCoord;
        largestCoord.x_coord = 0;
        largestCoord.y_coord = 0;
        //Set scanArea to area so that we can easily scan the map
        for (int y = 0; y < scanArea.GetLength(1); y++) {
            for (int x = 0; x < scanArea.GetLength(0); x++) {
                scanArea[x, y] = (int)area[x, y];
            }
        }
        //Scan the map for the 'scanTarget', when one is found, inspect its area and then compare sizes
        //-1 signifies that the tile has been scaned
        for (int y = 0; y < scanArea.GetLength(1); y++) {
            for (int x = 0; x < scanArea.GetLength(0); x++){

                if(scanArea[x, y] == (int)scanTarget){
                    currentCount = 0;
                    current.x_coord = x;
                    current.y_coord = y;
                    scanArea[x, y] = -1;

                    coordQ.Enqueue (current);
                    topLeftCoords.Add (current);
                    currentCount++;
                    //Keep scan until queue is empty
                    while(coordQ.Count != 0){
                        ScanMap (scanArea, coordQ, scanTarget, ref currentCount);
                    }
                    //Compare if this area is the largest
                    if(currentCount > largestCount){
                        largestCoord.x_coord = x;
                        largestCoord.y_coord = y;
                        largestCount = currentCount;
                    }
                }
            }
        }
        //Remove the coord responsible for the largest from the list
        topLeftCoords.Remove (largestCoord);
        return largestCount;
    }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:48,代码来源:TDMap.cs

示例5: GenerateSquares

	/// <summary>
	/// Generates the gameobjects.
	/// </summary>
	/// <param name="map">Map.</param>

	public void GenerateSquares(TileType[,] map) {

		GameObject tile;

		for (int i = 0; i < map.GetLength(0); i++) {
			for (int j = 0; j < map.GetLength(1); j++) {
			
				tile = (GameObject)Instantiate(getTile(map[i, j]), new Vector3(i, j, 0), Quaternion.identity);
				tile.name = "Tile[" + i + "][" + j + "]";
				tile.transform.parent = tileCollection.transform;
				tileMap.Add (new Coord(i, j), tile);

				Diffusion d = tile.GetComponent<Diffusion> ();
				if (d)
					AIMap.Add(new Coord(i, j), d);

				MouseOver m = tile.GetComponent<MouseOver> ();
				if (m && m.isLinkable) {
					linkables.Enqueue (m);
				}

			}
		}

		foreach (KeyValuePair<Coord, Diffusion> kvp in AIMap) {
			AttachNeighbours(kvp.Key.x, kvp.Key.y);
		}

		LinkLinkables ();
	}
开发者ID:Sphara,项目名称:The-Lonely...-Thing,代码行数:35,代码来源:SquareGenerator.cs

示例6: GenerateElevators

    /// <summary>
    /// Creates an instantites the tiles. 
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary<TileSetType, TileLevel> availiableTile)
    {
        List<Vector2> leftEnds = new List<Vector2>();
        List<Vector2> rightEnds = new List<Vector2>(); 

        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx]; 

                if (type == TileType.LeftEnd)
                {
                    leftEnds.Add(new Vector2(xdx, ydx)); 
                }
                else if (type == TileType.RightEnd)
                {
                    rightEnds.Add(new Vector2(xdx, ydx)); 
                }
            }
        }

        DualStore<Vector2, Vector2> veritcal = new DualStore<Vector2, Vector2>(); 

        foreach (Vector2 vec in rightEnds)
        {
            int xdx = (int)vec.x + 1;
            //int ydx = (int)vec.y; 

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1; 
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = - 1; 
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1; 
                }
            }
        }

        foreach (Vector2 vec in leftEnds)
        {
            int xdx = (int)vec.x - 1;
            //int ydx = (int)vec.y; 

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (KeyValuePair<Vector2, Vector2> kv in veritcal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);
            

            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir = MovementDirection.updown; 
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();
            
            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

        DualStore<Vector2, Vector2> horizontal = new DualStore<Vector2, Vector2>();

//.........这里部分代码省略.........
开发者ID:DanWright91,项目名称:GGJ16,代码行数:101,代码来源:MapGenerator.cs

示例7: SpiralGeneration

 /*Clear*/
 //General in a clockwise (square)spiral from the outside base on neighbouring tiles
 private void SpiralGeneration(TileType[,] area, TileType replaceTarget, int kFactor, int cFactor)
 {
     int increment = 1;
     bool reachedCenter = false;
     //Expand from there by density and build it spirally
     do
     {
         //Top
         for (int x = increment; x < area.GetLength(0) - 1 - increment; x++)
             GenerateTileByRelation(area, replaceTarget,
                                    x, 			//x-coord
                                    increment, 	//y-coord
                                    kFactor, cFactor);
         //Right
         for (int y = increment; y < area.GetLength(1) - 1 - increment; y++)
             GenerateTileByRelation(area, replaceTarget,
                                    area.GetLength(0) - 1 - increment,	//x-coord
                                    y, 									//y-coord
                                    kFactor, cFactor);
         //Bottom
         for (int x = area.GetLength(0) - 1 - increment; x >= increment; x--)
             GenerateTileByRelation(area, replaceTarget,
                                    x, 									//x-coord
                                    area.GetLength(1) - 1 - increment, 	//y-coord
                                    kFactor, cFactor);
         //Left
         for (int y = area.GetLength(1) - 1 - increment - 1; y >= increment + 1; y--)
             GenerateTileByRelation(area, replaceTarget,
                                    increment,	//x-coord
                                    y, 			//y-coord
                                    kFactor, cFactor);
         //Increment or stop?
         if (2 * increment > area.GetLength(0) || 2 * increment > area.GetLength(1))
             reachedCenter = true;
         else
             increment++;
     } while (!reachedCenter);
 }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:40,代码来源:TDMap.cs

示例8: SafeCoord

 private bool SafeCoord(TileType[,] area, int x_coord, int y_coord)
 {
     return(x_coord >= 0 && x_coord < area.GetLength(0) && y_coord >= 0 && y_coord < area.GetLength(1));
 }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:4,代码来源:TDMap.cs

示例9: GenerateTileByRelation

 /*Clear*/
 //Replaces tile if the neighbouring tiles are alike
 private void GenerateTileByRelation( TileType[,] area, TileType replaceTarget, int x_coord, int y_coord, int kFactor, int cFactor)
 {
     //(Modifier x Neighbouring Trees) / 100
     if (((kFactor * DetectSimilarBorderTiles(area, replaceTarget, x_coord, y_coord)) + cFactor) > (int)Random.Range(0,100) &&
         x_coord > 0 && x_coord < area.GetLength (0) - 1 && y_coord > 0 && y_coord < area.GetLength (1) - 1)
         area[x_coord, y_coord] = replaceTarget;
 }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:9,代码来源:TDMap.cs

示例10: PlaceMinerals

	void PlaceMinerals (TileType[, ] map, int x, int y, List<TileType> minerals)
	{
		if (map [x, y] != TileType.NONE && (y + 1) < map.GetLength(1) && map[x, y + 1] != TileType.NONE) {

			int i = Random.Range(0, minerals.Count);

			map[x, y] = minerals[i];
		
		}
	}
开发者ID:Sphara,项目名称:The-Lonely...-Thing,代码行数:10,代码来源:MineralFarm.cs

示例11: EasyMap

    // building an easy map - only up and right turns. EasyMap gets a two dimensional array
    // and builds an easy map in it. the number 0 represents a wall (or solid matter)
    // and the number 1 represents a room (the path, a hallway, air, what ever you want)
    static MapDescriptor EasyMap(int sizeX, int sizeY)
    {
        System.Random rng = new System.Random();
        var tiles = new TileType[sizeX, sizeY];

        //finding the greatest common divisor of the lengths of the rectangle.
        // this gives a better way of randomizing tiles, instead in a ratio of 1:1
        // the ratio depends on the size of the rectangle (for a 10 by 20 rectangle
        // the randomizing ratio for up and right will be 1:2)
        int gcd = FindGCD(tiles.GetLength(1), tiles.GetLength(0));
        int ChanceNum = (tiles.GetLength(1) / gcd) + (tiles.GetLength(0) / gcd);

        // setting the whole tiles to 0, everything is a wall
        for (int i = 0; i < tiles.GetLength(0); i++) {
            for (int j = 0; j < tiles.GetLength(1); j++) {
                tiles[i,j] = TileType.Wall;
            }
        }
        //[0,0] is the starting point and so it always equals to 1. [0,0] represents the
        // right bottom point of the map
        tiles[0, 0] = TileType.Floor;

        //indexes to the last tile that was changed
        int CurrentRow = 0;
        int CurrentCol = 0;
        int num;
        // the pathway can be as long as the sum of the number of columns
        // and rows in the array minus 1
        for (int i = 0; i < (tiles.GetLength(0) + tiles.GetLength(1)); i++)
        {
            if (CurrentCol < tiles.GetLength(1) - 1 && CurrentRow < tiles.GetLength(0) - 1)
            {
                //getting a random number between 0 and the chance num, so the odds
                //of getting an up or right turn will be adjusted by the size of the rectangle
                 num = rng.Next(0, ChanceNum);

                if (num < Math.Min((tiles.GetLength(1) / gcd), (tiles.GetLength(0) / gcd)))
                {
                    if(tiles.GetLength(1)>tiles.GetLength(0)){
                        CurrentRow++;
                        tiles[CurrentRow, CurrentCol] = TileType.Floor;

                    }
                    else
                    {
                        CurrentCol++;
                        tiles[CurrentRow, CurrentCol] = TileType.Floor;
                    }
                }
                else{

                    if(tiles.GetLength(1)>tiles.GetLength(0))
                    {
                        CurrentCol++;
                        tiles[CurrentRow, CurrentCol] = TileType.Floor;

                    }else
                    {
                        CurrentRow++;
                        tiles[CurrentRow, CurrentCol] = TileType.Floor;
                    }
                }
            }
        }

        while (CurrentRow != tiles.GetLength(0) - 1)
        {

            num = rng.Next(0, tiles.GetLength(1));
            MoveUp(num, tiles);
            CurrentRow++;
        }
        while (CurrentCol != tiles.GetLength(1) - 1)
        {
            num = rng.Next(0, tiles.GetLength(0));
            MoveRight(num, tiles);
            CurrentCol++;
        }

        var result = new MapDescriptor();
        result.tiles = tiles;
        // Simple paths always start at the bottom left, end at the top right
        result.startX = 0;
        result.startY = 0;
        result.endX = sizeX;
        result.endY = sizeY;

        return result;
    }
开发者ID:HankTheChog,项目名称:WalkInTheDark,代码行数:92,代码来源:Maping.cs

示例12: MoveUp

    static void MoveUp(int col, TileType[,] map)
    {
        int row = map.GetLength(0)-1;

        while (map[row-1, col] != TileType.Floor)
        {
            row--;
        }
        map[row, col] = TileType.Floor;

        for (int i = col+1; i < map.GetLength(1); i++)
        {
            for (int j = map.GetLength(0)-1; j > 0; j--)
            {
                if (map[j-1, i] == TileType.Floor)
                {
                    map[j, i] = TileType.Floor;
                    map[j - 1, i] = TileType.Wall;
                }
            }
        }
    }
开发者ID:HankTheChog,项目名称:WalkInTheDark,代码行数:22,代码来源:Maping.cs

示例13: MoveRight

    static void MoveRight(int row, TileType[,] map)
    {
        int col = map.GetLength(1) - 1;
        while (map[row, col - 1]!=TileType.Floor)
        {
            col--;
        }
        map[row,col]=TileType.Floor;

        for (int i = row+1; i < map.GetLength(0); i++)
        {
            for (int j = map.GetLength(1)-1; j > 0; j--)
            {
                if (map[i, j - 1] == TileType.Floor)
                {
                    map[i, j] = TileType.Floor;
                    map[i,j - 1] = TileType.Wall;
                }
            }
        }
    }
开发者ID:HankTheChog,项目名称:WalkInTheDark,代码行数:21,代码来源:Maping.cs

示例14: InstantiateTiles

    /// <summary>
    /// Instantiates all the tiles. 
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void InstantiateTiles(TileType[,] map, int dividerLevel, Dictionary<TileSetType, TileLevel> availiableTile, List<Vector2> spawnPoints)
    {
        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx]; 
                if (type != TileType.None && type != TileType.Lava)
                {
                    TileSetType level = ydx > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

                    GameObject obj = availiableTile[level].GetTileType(type);
                    var tile = (GameObject) Instantiate(obj, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());

                    Debug.Log(tile);
                    NetworkServer.Spawn(tile);
                }
                else if (type == TileType.Lava)
                {
                    GameObject obj = availiableTile[TileSetType.lava].GetTileType(TileType.Top);
                    var tile = (GameObject)Instantiate(obj, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());
                    tile.name = "Lava"; 
                    Debug.Log(tile);
                    NetworkServer.Spawn(tile);
                }

                //GameObject bck = availiableTile[TileSetType.background].GetTileType(TileType.Filler);
                //var backt = (GameObject)Instantiate(bck, new Vector3(xdx * Tilesize, ydx * Tilesize), new Quaternion());
                //backt.name = "background";
                //Debug.Log(backt);
                //NetworkServer.Spawn(backt); 
            }
        }

        foreach(Vector2 point in spawnPoints)
        {
            var spawn = (GameObject)Instantiate(SpawnPrefab, new Vector3(point.x * Tilesize, point.y * Tilesize), new Quaternion());
            spawn.name = "spawnPoint"; 
            Debug.Log(spawn); 
            NetworkServer.Spawn(spawn); 
        }

        //GameObject back = backgroundPrefab;
        
        var backobj = (GameObject)Instantiate(backgroundPrefab, new Vector3(0, 0, -1.5f), new Quaternion());
        BackgroundScript move = backobj.GetComponent(typeof(BackgroundScript)) as BackgroundScript;
        move.MapSize = new Vector2(WidthSize * Tilesize, HeightSize * Tilesize);
        move.DividerLevel = dividerLevel;
        Debug.Log(backobj);
        NetworkServer.Spawn(backobj); 


    }
开发者ID:DanWright91,项目名称:GGJ16,代码行数:59,代码来源:MapGenerator.cs

示例15: FillIsolated

 //Similar to ScanMap(), but interacts with the actual map so that changes can be made. replace scanTargets
 //to replaceTargets
 private void FillIsolated(TileType[,] area, Queue<Coord> topLeftCoords, TileType scanTarget, TileType replaceTarget)
 {
     Coord current = topLeftCoords.Dequeue ();
     Coord nextPoint;
     //Scan left
     if (current.x_coord > 0) {
         if (area[current.x_coord - 1, current.y_coord] == scanTarget){
             nextPoint.x_coord = current.x_coord - 1;
             nextPoint.y_coord = current.y_coord;
             area[nextPoint.x_coord, nextPoint.y_coord] = replaceTarget;
             topLeftCoords.Enqueue (nextPoint);
         }
     }
     //Scan right
     if (current.x_coord < area.GetLength(0) - 1) {
         if (area[current.x_coord + 1, current.y_coord] == scanTarget){
             nextPoint.x_coord = current.x_coord + 1;
             nextPoint.y_coord = current.y_coord;
             area[nextPoint.x_coord, nextPoint.y_coord] = replaceTarget;
             topLeftCoords.Enqueue (nextPoint);
         }
     }
     //Scan up
     if (current.y_coord > 0) {
         if (area[current.x_coord, current.y_coord - 1] == scanTarget){
             nextPoint.x_coord = current.x_coord;
             nextPoint.y_coord = current.y_coord - 1;
             area[nextPoint.x_coord, nextPoint.y_coord] = replaceTarget;
             topLeftCoords.Enqueue (nextPoint);
         }
     }
     //Scan down
     if (current.y_coord < area.GetLength(1) - 1) {
         if (area[current.x_coord, current.y_coord + 1] == scanTarget){
             nextPoint.x_coord = current.x_coord;
             nextPoint.y_coord = current.y_coord + 1;
             area[nextPoint.x_coord, nextPoint.y_coord] = replaceTarget;
             topLeftCoords.Enqueue (nextPoint);
         }
     }
 }
开发者ID:Jlancy,项目名称:DEE-files,代码行数:43,代码来源:TDMap.cs


注:本文中的TileType.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。