コード例 #1
0
ファイル: WorldGenerator.cs プロジェクト: akbiggs/Crash.net
        /// <summary>
        /// Generate a tilemap from the given file.
        /// </summary>
        /// <param name="filepath">The path to a text file.</param>
        /// <returns>A tilemap generated from the given filepath.</returns>
        public static Tile[,] TilesFromFile(string filepath)
        {
            StreamReader reader = new StreamReader(filepath);
            String line = reader.ReadLine();
            Tile[,] tiles = new Tile[ROOM_WIDTH, ROOM_HEIGHT];
            int x = 0, y = 0;

            while (line != null)
            {
                line.Trim().Replace(" ", "");
                foreach (string tile in line.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                {
                    tiles[x, y] = Tile.FromString(tile);
                    ++x;
                }
                ++y;
            }

            return tiles;
        }
コード例 #2
0
ファイル: Room.cs プロジェクト: akbiggs/Crash.net
        /// <summary>
        /// Sets the tile at the given coordinates to the given tile.
        /// </summary>
        /// <param name="col">The x-coordinate of the new tile, relative to other tiles.</param>
        /// <param name="row">The y-coordinate of the new tile, relative to other tiles.</param>
        /// <param name="tiletype">The new tile.</param>
        private void SetTile(int col, int row, TileType tiletype)
        {
            Tile tile = new Tile(new Vector2(col * TILESIZE, row * TILESIZE), tiletype);
            if (ValidRow(row) && ValidCol(col))
            {
                if (tiles == null) tiles = new Tile[Width, Height];
                tiles[col, row] = tile;

                // determine the part of the map that has not been rendered yet,
                // based on this new unrendered tile and the other tiles that have not been rendered.
                float pixelX = col * TILESIZE;
                float pixelY = row * TILESIZE;
                if (unrenderedRegion == Rectangle.Empty)
                    unrenderedRegion = new Rectangle((int)pixelX, (int)pixelY, TILESIZE, TILESIZE);
                else
                {
                    float smallerX = Math.Min(pixelX, unrenderedRegion.X);
                    float largerX = Math.Max(pixelX, unrenderedRegion.X);
                    float smallerY = Math.Min(pixelY, unrenderedRegion.Y);
                    float largerY = Math.Max(pixelY, unrenderedRegion.Y);
                    unrenderedRegion = new Rectangle((int)smallerX, (int)smallerY,
                        (int)(largerX - smallerX + TILESIZE), (int)(largerY - smallerY + TILESIZE));
                }
            }
        }
コード例 #3
0
ファイル: Room.cs プロジェクト: akbiggs/Crash.net
 public Room(Tile[,] tiles) :
     this(tiles.GetLength(0), tiles.GetLength(1), new List<Direction>())
 {
     this.tiles = tiles;
 }