Ejemplo n.º 1
0
 public void CreateWorldFromMapTiles(MapTile[,] map)
 {
     world = (MapTile[,])map.Clone();
     worldSizeX = map.GetLength(0);
     worldSizeY = map.GetLength(1);
     MapGenerator.singleton.CreateLoadedWorldMesh(true);
 }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        m_Tiles = new MapTile[MapWidth, MapHeight];
        for (int i = 0; i < MapWidth; i++)
        {
            for (int j = 0; j < MapHeight; j++)
            {
                var tile = GameObject.Instantiate(TilePrefab);
                tile.transform.SetParent(transform);
                tile.transform.localPosition = new Vector3(
                    i * TileSize,
                    0,
                    j * TileSize
                    );
                m_Tiles[i, j] = tile.GetComponent <MapTile>();
            }
        }
        var centerTile = m_Tiles[MapWidth / 2, MapHeight / 2];

        centerTile.Status   = MapTile.TileStatus.Snake;
        centerTile.PrevTile = m_Tiles[MapWidth / 2 - 1, MapHeight / 2];
        centerTile.Count    = 2;
        centerTile.Refresh();
        centerTile.PrevTile.Status = MapTile.TileStatus.Snake;
        centerTile.PrevTile.Count  = 1;
        centerTile.PrevTile.Refresh();
        m_CurrentSnakeLen  = 2;
        m_CurrentSnakeHead = Tile2Index(MapWidth / 2, MapHeight / 2, MapWidth);
    }
Ejemplo n.º 3
0
    public MapTile[,] createLevel(int levelSize, int tiles, float chance)
    {
        posX          = levelSize / 2;
        posY          = levelSize / 2;
        baseTiles     = tiles;
        baseDirChance = chance;                                             //set the base dir from main chance (IMPORTANT)
        lvl           = setupLevel(levelSize, tiles, chance, lvl, obsRate); //create a level
        int attempt = 1;                                                    //attempts at making a solvable level

        bool levelMade = pathfindTest(moveList, lvl, baseTiles);            //test making a level
        bool doors     = addDoors(lvl);


        while (!levelMade) //keep trying to make levels if one fails, so far works 100%
        {
            attempt++;
            Debug.Log("generating attempt " + attempt);
            lvl = setupLevel(levelSize, baseTiles, 0.6f, lvl, obsRate);
            Debug.Log("testing path");
            levelMade = pathfindTest(moveList, lvl, baseTiles);
            doors     = addDoors(lvl);
        }
        Debug.Log("path found on attempt " + attempt);

        return(lvl);
    }
Ejemplo n.º 4
0
    public void createNewMap(int w, int h)
    {
        width  = w;
        height = h;

        map = new MapTile[width, height];
    }
Ejemplo n.º 5
0
        public static MapTile[,] createmap(MapTile[,] smap, int he, int wi)
        {
            h      = he;
            w      = wi;
            mtiles = smap;
            Random r = new Random();

            floornum = r.Next((int)((smap.Length * 0.6) - (smap.Length * 0.1)), (int)((smap.Length * 0.6) + (smap.Length * 0.1)));
            int[] dir = new int[4] {
                0, 0, 0, 0
            };
            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    if (mtiles[x, y].type == 1)
                    {
                        tmove(x, y);
                        break;
                    }
                }
            }


            return(mtiles);
        }
Ejemplo n.º 6
0
/// <summary>
    /// Instantiate new MapTiles into the scene (inactive - to be activated and animated later).
    /// </summary>
    /// <param name="newGeneratedMapArray">Unparsed generated map data.</param>
    /// <returns></returns>
    ///
    private GameObject[,] InstantiateNewMapTiles(MapTile[,] newGeneratedMapArray)
    {
        if (Verbose >= 2)
        {
            Debug.Log("InstantiateNewMapTiles");
        }

        GameObject[,] newMapObjectArray = new GameObject[newGeneratedMapArray.GetLength(0), newGeneratedMapArray.GetLength(1)];

        // iterate through array and instantiate all objects
        for (int j = 0; j < newGeneratedMapArray.GetLength(0); j++)
        {
            for (int k = 0; k < newGeneratedMapArray.GetLength(1); k++)
            {
                if (newGeneratedMapArray[j, k] == null)
                {
                    continue;
                }
                if (newGeneratedMapArray[j, k].type == null)
                {
                    continue;
                }

                newMapObjectArray[j, k] = CreateMapTile(newGeneratedMapArray[j, k].type); // TODO: This variable now shouldn't be lowercase
            }
        }

        return(newMapObjectArray);
    }
Ejemplo n.º 7
0
        public void GenerateMap(float[,] noiseMap, TerrainRegions terrain)
        {
            this.terrain = terrain;
            int width  = noiseMap.GetLength(0);
            int height = noiseMap.GetLength(1);

            tiles = new MapTile[width, height];
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    bool foundRegion = false;
                    for (int i = 0; i < terrain.regions.Length - 1; i++)
                    {
                        if (noiseMap[x, y] < terrain.regions[i].height)
                        {
                            foundRegion = true;
                            tiles[x, y] = new MapTile(i, noiseMap[x, y]);
                            break;
                        }
                    }
                    if (!foundRegion)
                    {
                        tiles[x, y] = new MapTile(terrain.regions.Length - 1, noiseMap[x, y]);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void generateMap()
 {
     map = new MapTile[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             if (i == 0 || i == width - 1 || j == 0 || j == height - 1)
             {
                 GameObject newtile = GameObject.Instantiate(obstacle);
                 newtile.transform.SetParent(mapobj.transform);
                 newtile.transform.Translate(new Vector2(start_x + i * w, start_y + j * h));
                 map[i, j]   = new MapTile(1, newtile);
                 map[i, j].x = i;
                 map[i, j].y = j;
             }
             else
             {
                 GameObject newtile = GameObject.Instantiate(road);
                 newtile.transform.SetParent(mapobj.transform);
                 newtile.transform.Translate(new Vector2(start_x + i * w, start_y + j * h));
                 map[i, j]   = new MapTile(0, newtile);
                 map[i, j].x = i;
                 map[i, j].y = j;
             }
         }
     }
     checkConnection();
 }
Ejemplo n.º 9
0
        partial void InitProjectSpecific()
        {
            OnLocationChanged += LocationChanged;

            borders = new Rectangle(
                (int)Locations.Min(l => l.MapPosition.X),
                (int)Locations.Min(l => l.MapPosition.Y),
                (int)Locations.Max(l => l.MapPosition.X),
                (int)Locations.Max(l => l.MapPosition.Y));
            borders.Width  = borders.Width - borders.X;
            borders.Height = borders.Height - borders.Y;

            mapTiles = new MapTile[
                (int)Math.Ceiling(size * BackgroundScale / generationParams.TileSpriteSpacing.X),
                (int)Math.Ceiling(size * BackgroundScale / generationParams.TileSpriteSpacing.Y)];

            for (int x = 0; x < mapTiles.GetLength(0); x++)
            {
                for (int y = 0; y < mapTiles.GetLength(1); y++)
                {
                    mapTiles[x, y] = new MapTile(
                        generationParams.BackgroundTileSprites[Rand.Int(generationParams.BackgroundTileSprites.Count)], Rand.Range(0.0f, 1.0f) < 0.5f ?
                        SpriteEffects.FlipHorizontally : SpriteEffects.None);
                }
            }

            drawOffset = -CurrentLocation.MapPosition;
        }
Ejemplo n.º 10
0
    /// <summary>
    /// 去噪点
    /// </summary>
    /// <param name="posX"></param>
    /// <param name="posY"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    int GetSurroundingWalls(int posX, int posY, MapTile[,] data)
    {
        int wallCount = 0;

        for (int i = posX - 1; i <= posX + 1; i++)
        {
            for (int j = posY - 1; j <= posY + 1; j++)
            {
                if (i >= 0 && i < width && j >= 0 && j < height)
                {
                    if (i != posX || j != posY)
                    {
                        if (data[i, j] != null)
                        {
                            wallCount += data[i, j].isWall ? 1 : 0;
                        }
                        else
                        {
                            wallCount++;
                        }
                    }
                }
                //else
                //{
                //    wallCount++;
                //}
            }
        }

        return(wallCount);
    }
Ejemplo n.º 11
0
 private void firstmapgen()
 {
     height = 200;
     width  = 200;
     tiles  = new MapTile[200, 200];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             tiles[i, j] = new MapTile();
         }
     }
     for (int i = 49; i < 150; i++)
     {
         for (int j = 49; j < 150; j++)
         {
             tiles[i, j].type = 1;
         }
     }
     enter.x = 55;
     enter.y = 55;
     exit.x  = 105;
     exit.y  = 105;
     tiles[105, 105].contains.Add("exit");
 }
Ejemplo n.º 12
0
    public MapTile[,] setupLevel(int lvlSize, int numTiles, float dirChance, MapTile[,] level, float obsRate)
    {
        levelSize = lvlSize;
        posX      = levelSize / 2;
        posY      = levelSize / 2;
        tiles     = numTiles;
        level     = new MapTile[levelSize, levelSize];
        chance    = dirChance;

        //randomize initial direction and place the first tile (for debug)
        dir = rndDir();

        //create subsequent tiles
        while (tiles > 0)
        {
            generate(chance, level);

            //Debug.Log(tiles);
        }
        //create entry and exit points
        findTopLeft(level);
        findBottomRight(level);


        if (tiles == 0)
        {
            //place tiles into the array
            populate(level, obsRate);
            //print the array to console
            //printLevel();
            tiles = -5;
        }
        return(level);
    }
Ejemplo n.º 13
0
        int _dx, _dy; //position on map
        
        public Map(char[,] _map, int left, int top)
        {
            map = _map;
            _left = left;
            _top = top;
            _dx = _left;
            _dy = _top;
            _width = map.GetLength(0);
            _height = map.GetLength(1);
            _tiles = new MapTile[_width, _height];

            for (int y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    switch (map[x,y])
                    {
                        case '.': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_FLOOR, tileType.T_FLOOR, '.'); break; }
                        case '#': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_WALL, tileType.T_WALL, '#'); break; }
                        case '+': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_CLOSED_DOOR, tileType.T_CLOSEDDOOR, '+'); break; }
                        case '/': { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_OPEN_DOOR, tileType.T_OPENDOOR, '/'); break; }
                        default: { _tiles[x, y] = new MapTile(x, y, _left, _top, StringName.TILE_DESC_EMPTY, tileType.T_EMPTY, ' '); break; }
                    }
                }
            }

                Console.ForegroundColor = ConsoleColor.White;
        }
Ejemplo n.º 14
0
    public string[] levelToString(MapTile[,] level)
    {
        int x = level.GetLength(0), y = level.GetLength(1);

        string[] output = new string[x];
        for (int zx = 79; zx >= 0; zx--)
        {
            for (int zy = 0; zy < y; zy++)
            {
                if (level[zx, zy] == null)
                {
                    output[zx] += "X";
                }
                else if (level[zx, zy].type == TileType.Exit)
                {
                    output[zx] += "B";
                }
                else if (level[zx, zy].type == TileType.Entry)
                {
                    output[zx] += "A";
                }
                else
                {
                    output[zx] += "_";
                }
            }
        }
        return(output);
    }
Ejemplo n.º 15
0
 public void ChangeMap(List <WorldItemDetailsDTO> worldObjects, int beginX, int beginY)
 {
     Map = new MapTile[MapSizeX, MapSizeY];
     LoadWorldObjects(worldObjects, beginX, beginY);
     LoadItemsMonsters(beginX, beginY);
     LoadHeroes(beginX, beginY);
 }
Ejemplo n.º 16
0
 public Apocalypse(FWPGame game, Dictionary<string, Power> powers)
 {
     myPowers = powers;
     myGame = game;
     myMap = myGame.map.MapTiles;
     mySprites = new List<Sprite>();
 }
Ejemplo n.º 17
0
    public Location getTileLocation(MapTile[,] level, TileType tile)
    {
        Location output = null;
        int      x = level.GetLength(0), y = level.GetLength(1);

        for (int zx = 0; zx < x; zx++)
        {
            for (int zy = 0; zy < x; zy++)
            {
                if (level[zy, zx] != null)
                {
                    if (level[zy, zx].type == tile)
                    {
                        output = new Location {
                            X = zx, Y = zy
                        };
                    }
                }
            }
        }
        if (output == null)
        {
            Debug.Log("no " + tile + " found");
        }
        else
        {
            Debug.Log(tile + " found at " + output.X + "," + output.Y);
        }
        return(output);
    }
Ejemplo n.º 18
0
        // Token: 0x06000153 RID: 339 RVA: 0x0000570C File Offset: 0x0000390C
        public static TileMap Load(Stream stream)
        {
            TileMap result;

            using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress, true))
            {
                VarLenBinaryReader varLenBinaryReader = new VarLenBinaryReader(deflateStream);
                if (varLenBinaryReader.ReadByte() != 1)
                {
                    throw new InvalidDataException("Invalid BMap version.");
                }
                TileMap tileMap = new TileMap(varLenBinaryReader.ReadVarLen32(), varLenBinaryReader.ReadVarLen32());
                DeserializationContext deserializationContext = new DeserializationContext();
                deserializationContext.ReadFrom(varLenBinaryReader);
                uint width  = tileMap.Width;
                uint height = tileMap.Height;
                MapTile[,] tiles = tileMap.Tiles;
                int num = 0;
                while ((long)num < (long)((ulong)height))
                {
                    int num2 = 0;
                    while ((long)num2 < (long)((ulong)width))
                    {
                        MapTile.ReadFrom(ref tiles[num2, num], varLenBinaryReader, deserializationContext);
                        num2++;
                    }
                    num++;
                }
                result = tileMap;
            }
            return(result);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 将随机生成的数据集群化
 /// </summary>
 void SmoothMap(MapTile[,] data)
 {
     //data.GetLength(0);
     //data.GetLength(1);
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             if (data[i, j] == null)
             {
                 continue;
             }
             int surroundingTiles = 0;
             surroundingTiles = GetSurroundingWalls(i, j, data);
             if (surroundingTiles > 4)
             {
                 data[i, j].isWall = true;//变成wall
             }
             else if (surroundingTiles < 4)
             {
                 data[i, j].isWall = false;
             }
         }
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a map which has every possible connection established
        /// between each tile.
        /// </summary>
        /// <param name="Width"></param>
        /// <param name="Height"></param>
        public Map(uint Width, uint Height)
        {
#if DEBUG
            DateTime now = DateTime.Now;
#endif
            Log.Info("Map: Instantiating Tiles...");
            this._tiles  = new MapTile[Width, Height];
            this._width  = Width;
            this._height = Height;
            this._edges  = new List <Tuple <MapTile, MapTile> >();
            //Instantiate every tile.
            int x, y;
            int i = 0;

            for (y = 0; y < Height; y++)
            {
                for (x = 0; x < Width; x++)
                {
                    _tiles[x, y] = new MapTile(x, y, i);
                    i++;
                }
            }
            Log.Info("Map: Adding all neighbours...");
            //Connect each tile with its available neighbours
            AddNeighbours();
            //Snag the max number of edges for statistics later.
            this._maxNumberOfEdges = (uint)_edges.Count;
            Log.Info("Map: Done");
#if DEBUG
            DateTime done = DateTime.Now;
            Utils.Log.Info(string.Format("Map: Constructor took {0:0} milliseconds to create all connected map.", (done - now).TotalMilliseconds));
#endif
        }
Ejemplo n.º 21
0
        private void LoadFile(string fileName)
        {
            if (HasUnsavedChanges())
            {
                return;
            }
            CurrentFile = fileName;
            MapData data = CurrentDirectory.LoadFile(txtLevelName.Text = fileName).JsonToObject <MapData>();

            Tiles = null;
            string[] rows = data.Tiles.Split(';');
            for (int i = 0; i < rows.Length; i++)
            {
                string[] row = rows[i].Split('|');
                if (Tiles == null)
                {
                    Tiles = new MapTile[rows.Length, row.Length];
                }
                for (int j = 0; j < row.Length; j++)
                {
                    Tiles[i, j]        = new MapTile();
                    Tiles[i, j].Pos    = new Point(i, j);
                    Tiles[i, j].TileID = int.Parse(row[j]);
                }
            }
            Units = data.Units;
            melMapEvents.Datas   = data.MapEvents;
            cmbTileSets.Text     = data.Tileset;
            nudLevelNumber.Value = data.LevelNumber;
            ObjectiveFromString(data.Objective);
            Render();
            UpdateUnitListBox();
            Dirty = false;
        }
Ejemplo n.º 22
0
 public TileLayer(Size fullSize)
 {
     this.fullSize = fullSize;
     tiles         = new MapTile[fullSize.Width * 2 - 1, fullSize.Height];
     GridTouched   = new TouchType[fullSize.Width * 2 - 1, fullSize.Height];
     GridTouchedBy = new MapTile[fullSize.Width * 2 - 1, fullSize.Height];
 }
Ejemplo n.º 23
0
 void Awake()
 {
     map      = new MapTile[mapSize, mapSize];
     tileSize = tile.GetComponent <SpriteRenderer>().bounds.size.x;
     pivot    = calculatePivotPosition();
     createMap();
 }
Ejemplo n.º 24
0
        public static MapTile[,] createTiles(int GridSize)
        {
            if (GridSize == 1)
            {
                return(new MapTile[, ] {
                    { new MapTile()
                      {
                          Type = MapTile.MapTileType.Start, Exits = MapTileFactory.GenerateFourExits
                      } }
                });
            }
            else
            {
                MapTile[,] map = gererateEmptyMap(GridSize);

                GenerateRandomTile(GridSize, map, MapTile.MapTileType.Start);
                GenerateRandomTile(GridSize, map, MapTile.MapTileType.Key);
                GenerateRandomTile(GridSize, map, MapTile.MapTileType.Exit);

                for (int j = 0; j < map.GetLength(0); j++)     //Vertical
                {
                    for (int k = 0; k < map.GetLength(1); k++) //Horizontal
                    {
                        if (map[j, k].Type == MapTile.MapTileType.Empty)
                        {
                            GenerateTile(GridSize, map, MapTile.MapTileType.Regular, j, k);
                        }
                    }
                }


                return(map);
            }
        }
Ejemplo n.º 25
0
        void createMap(int width, int height)
        {
            this.width  = width;
            this.height = height;

            tiles = new MapTile[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    tiles[y, x] = new MapTile(x, y, tileSize, tileSize, 0, 0);
                }
            }

            for (int x = 0; x < width; x++)
            {
                tiles[0, x].Type     = 1;
                tiles[0, x].Walkable = false;

                tiles[height - 1, x].Type     = 1;
                tiles[height - 1, x].Walkable = false;
            }

            for (int y = 0; y < height; y++)
            {
                tiles[y, 0].Type     = 1;
                tiles[y, 0].Walkable = false;

                tiles[y, width - 1].Type     = 1;
                tiles[y, width - 1].Walkable = false;
            }
        }
Ejemplo n.º 26
0
        private void InsertRandomBricks(ref MapTile[,] map)
        {
            var brickSquares = (int)(_width * _height * 0.1);

            for (var i = 0; i < brickSquares; ++i)
            {
                var x = _random.Next(0, _xLimit);
                var y = _random.Next(0, _yLimit);
                if (_random.Next(0, 100) >= 25)
                {
                    var brick = (Walls)_random.Next(1, 15);
                    if (brick.HasFlag(Walls.Left) && !_mapArray[x, y].HasFlag(Walls.Left))
                    {
                        var length = _squareSize - (_mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0);
                        var offset = _mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0;
                        DrawSquares(ref map, Item.BrickWall, x * _squareSize, (y * _squareSize) + offset, 1, length);
                    }

                    if (brick.HasFlag(Walls.Right) && !_mapArray[x, y].HasFlag(Walls.Right))
                    {
                        var length = _squareSize - (_mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0) + (_mapArray[x, y].HasFlag(Walls.Bottom) ? 0 : 1);
                        var offset = _mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0;
                        DrawSquares(ref map, Item.BrickWall, (x + 1) * _squareSize, (y * _squareSize) + offset, 1, length);
                    }

                    if (brick.HasFlag(Walls.Top) && !_mapArray[x, y].HasFlag(Walls.Top))
                    {
                        var length = _squareSize - (_mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0);
                        var offset = _mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0;
                        DrawSquares(ref map, Item.BrickWall, (x * _squareSize) + offset, y * _squareSize, length, 1);
                    }

                    if (brick.HasFlag(Walls.Bottom) && !_mapArray[x, y].HasFlag(Walls.Bottom))
                    {
                        var length = _squareSize - (_mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0) + (_mapArray[x, y].HasFlag(Walls.Right) ? 0 : 1);
                        var offset = _mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0;
                        DrawSquares(ref map, Item.BrickWall, (x * _squareSize) + offset, (y + 1) * _squareSize, length, 1);
                    }
                }
                else
                {
                    var length = _squareSize - (_mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0) + (_mapArray[x, y].HasFlag(Walls.Bottom) ? 0 : 1);
                    var width  = _squareSize - (_mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0) + (_mapArray[x, y].HasFlag(Walls.Right) ? 0 : 1);

                    var xOffset = _mapArray[x, y].HasFlag(Walls.Left) ? 1 : 0;
                    var yOffset = _mapArray[x, y].HasFlag(Walls.Top) ? 1 : 0;

                    if (_random.Next(0, 100) >= 75)
                    {
                        DrawSquares(ref map, Item.BrickWall, (x * _squareSize) + xOffset, (y * _squareSize) + yOffset, width, length);
                    }
                    else
                    {
                        var middle = (int)Math.Ceiling(_squareSize / 2m);
                        DrawSquares(ref map, Item.BrickWall, (x * _squareSize) + middle, (y * _squareSize) + yOffset, 1, length);
                        DrawSquares(ref map, Item.BrickWall, (x * _squareSize) + xOffset, (y * _squareSize) + middle, width, 1);
                    }
                }
            }
        }
Ejemplo n.º 27
0
    public void CreateTestWorld(Vector2 size)
    {
        worldSizeX = (int)size.x;
        worldSizeY = (int)size.y;
        world = new MapTile[(int)size.x,(int)size.y];

        for(int i=0;i<worldSizeX;i++){
            world[i,0].fog = 255;
            world[i,0].baseFog = 255;
            world[i,0].height = 1;
            for(int n=1;n<worldSizeY;n++){
                world[i,n] = world[i,0];
            }
        }

        for(int i=0;i<worldSizeX;i++){
            for(int j=0;j<worldSizeY;j++){
                if((j == 0 || j == (worldSizeY-1)) || (i==0 || i ==(worldSizeX-1))){
                    world[i,j].height = 10;
                }
            }
        }
        /*
        world[5,5].height = 10;
        world[5,4].height = 10;
        world[5,3].height = 10;
        world[5,2].height = 10;

        world[5,5].fog = 0;
        world[5,4].fog = 0;
        world[5,3].fog = 0;
        world[5,2].fog = 0;*/

        MapGenerator.singleton.CreateLoadedWorldMesh(true);
    }
Ejemplo n.º 28
0
 public void CreateNewWorld(Vector2 size)
 {
     worldSizeX = (int)size.x;
     worldSizeY = (int)size.y;
     world = new MapTile[(int)size.x,(int)size.y];
     MapGenerator.singleton.CreateEmptyWorld(size);
 }
Ejemplo n.º 29
0
    public IEnumerator GenerateMap(MapTile[,] mapTiles)
    {
        isGenerating = true;

        int width  = tilemapSize.x;
        int height = tilemapSize.y;

        mapTiles = new MapTile[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                bool isSolid = Random.Range(1, 101) < rule_initialChance ? true : false;

                mapTiles[x, y] = new MapTile(new Vector2Int(x, y), isSolid);
            }
        }

        for (int i = 0; i < rule_numberOfIteration; i++)
        {
            mapTiles = GenTilePos(mapTiles);
            yield return(null);
        }

        isGenerating = false;

        GetComponent <MapController>().SetTiles(mapTiles);
    }
Ejemplo n.º 30
0
    public void UpdateTile(MapTile[,] mapTile, MapTile tileToUpdate)
    {
        isGenerating = true;

        int width  = mapTile.GetLength(0);
        int height = mapTile.GetLength(1);

        BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1);

        foreach (Vector3Int b in bounds.allPositionsWithin)
        {
            if (tileToUpdate.position.x + b.x >= 0 && tileToUpdate.position.x + b.x < width && tileToUpdate.position.y + b.y >= 0 && tileToUpdate.position.y + b.y < height)
            {
                MapTile tile = mapTile[tileToUpdate.position.x + b.x, tileToUpdate.position.y + b.y];
                tile.tile = debugTiles[1];

                foreach (SO_RuleTile rule in rulesForTiles)
                {
                    if (rule.IsThisTile(tile, mapTile))
                    {
                        tile.tile = rule.tile;
                        break;
                    }
                }
            }
        }

        isGenerating = false;
    }
Ejemplo n.º 31
0
    void doStartStuff()
    {
        map = GameObject.FindObjectOfType <MapExample>().tiles4;
        node finish = null;
        node start  = null;

        foreach (MapTile a in map)
        {
            if (a.IsGoal)
            {
                finish = new node(a.X, a.Y);
                Debug.Log("found finish at " + a.X + ", " + a.Y);
            }

            else if (a.IsStart)
            {
                start = new node(a.X, a.Y);
            }
        }
        path = aStar(start, finish);

        if (path != null)
        {
            targetWaypoint = new Vector3(path[currpoint].x, 1, path[currpoint].y);
            paused         = false;
            state          = playerstate.idle;
        }
        else
        {
            paused = true;
            state  = playerstate.move;
        }
    }
Ejemplo n.º 32
0
 // Use this for initialization
 void Start()
 {
     unitManager     = GameObject.Find("UnitManager").GetComponent <UnitManager>();
     controlsManager = GameObject.Find("ControlsManager").GetComponent <ControlsManager>();
     map             = new MapTile[mapWidth, mapHeight];
     MapSetup();
 }
Ejemplo n.º 33
0
 public MapLayer(string Name, int Width, int Height, float ParallaxValueVert, float ParallaxValueHorz)
 {
     this._tilemap = new MapTile[Width, Height];
     this._parallaxValueVert = ParallaxValueVert;
     this._parallaxValueHorz = ParallaxValueHorz;
     _name = Name;
 }
Ejemplo n.º 34
0
 //CopyConst
 public MapLayer(MapLayer MapLayer)
 {
     this._name = MapLayer._name;
     this._parallaxValueHorz = MapLayer._parallaxValueHorz;
     this._parallaxValueVert = MapLayer._parallaxValueVert;
     this._tilemap = MapLayer._tilemap;
 }
Ejemplo n.º 35
0
    public Map(int size_x, int size_y)
    {
        SizeX = size_x;
        SizeY = size_y;
        Tiles = new MapTile[size_x, size_y];

        System.Random rand = new System.Random();
        MapTile       tile;

        // Generate grass
        for (int x = 0; x < size_x; x++)
        {
            for (int y = 0; y < size_y; y++)
            {
                tile        = new MapTile(new Vector2(x, y));
                tile.Type   = MapTile.TileType.Grass;
                Tiles[x, y] = tile;
            }
        }

        // Generate starting dirt
        for (int dirt = 0; dirt < (SizeX * SizeY) / 2;)
        {
            var x = rand.Next(0, SizeX);
            var y = rand.Next(0, SizeY);

            tile = Tiles[x, y];
            if (tile.Type == MapTile.TileType.Grass)
            {
                tile.Type = MapTile.TileType.Dirt;
                dirt     += 1;
            }
        }
    }
Ejemplo n.º 36
0
Archivo: Map.cs Proyecto: bagnalla/RTS
        void loadMap(string mapFilePath)
        {
            string[] lines = File.ReadAllLines(mapFilePath);

            string[] widthAndHeight = lines[0].Split(' ');
            width  = int.Parse(widthAndHeight[0]);
            height = int.Parse(widthAndHeight[1]);

            tiles = new MapTile[height, width];

            for (int i = 1; i < height + 1; i++)
            {
                string[] rowOfTiles = lines[i].Split(' ');

                for (int s = 0; s < width; s++)
                {
                    int typeCode    = int.Parse(rowOfTiles[s].Substring(0, 1));
                    int pathingCode = int.Parse(rowOfTiles[s].Substring(1, 1));
                    tiles[i - 1, s] = new MapTile(s, (i - 1), tileSize, tileSize, typeCode, pathingCode);
                    if (pathingCode == 1)
                    {
                        Walls.Add(tiles[i - 1, s]);
                    }
                }
            }

            Util.SortByX(Walls);
        }
Ejemplo n.º 37
0
        public Map(UniMapData data, ContentManager content, string pathAndName, GraphicsDevice graphicsDevice)
        {
            m_data     = data;
            m_mapSizeX = m_data.WalkableGrid.GetLength(0);
            m_mapSizeY = m_data.WalkableGrid.GetLength(1);

            m_tiles = new MapTile[m_mapSizeX, m_mapSizeY];

            for (int y = 0; y < m_mapSizeY; y++)
            {
                for (int x = 0; x < m_mapSizeX; x++)
                {
                    m_tiles[x, y]       = new MapTile(content.Load <Texture2D>(pathAndName), new Vector2(18 + (x * 36), 18 + (y * 36)), Color.White, 4, 4, x, y, graphicsDevice);
                    m_tiles[x, y].Index = m_data.WalkableGrid[x, y];

                    // Setup bool values for tiles according to their index
                    if (m_data.WalkableGrid[x, y] <= 0)
                    {
                        m_tiles[x, y].IsWalkable  = true;
                        m_tiles[x, y].IsPlaceable = false;
                    }
                    else if (m_data.WalkableGrid[x, y] == 1)
                    {
                        m_tiles[x, y].IsWalkable  = false;
                        m_tiles[x, y].IsPlaceable = true;
                    }
                    else if (m_data.WalkableGrid[x, y] > 1)
                    {
                        m_tiles[x, y].IsWalkable  = false;
                        m_tiles[x, y].IsPlaceable = false;
                    }
                }
            }
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Creates an empty map structure
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public Map(short width, short height)
 {
     this.Height = height;
     this.Width = width;
     this.Grid = new MapTile[Width, Height];
     InitializeGrid();
 }
Ejemplo n.º 39
0
 public Map(int width, int height)
 {
     m_mapObjects = new List<IMapObjectCore>();
     m_monsterList = new List<Monster>();
     m_items = new List<Pair<Item, Point>>();
     m_width = width;
     m_height = height;
     m_map = new MapTile[m_width, m_height];
 }
Ejemplo n.º 40
0
        public Pathfinder(int width, int height)
        {
            //use our own tiles independent of that game state
            Map = new MapTile[height, width];

            for (int col = 0; col < width; col++)
                for (int row = 0; row < height; row++)
                    Map[row, col] = new MapTile(col, row);
        }
Ejemplo n.º 41
0
 public void LoadMap(string filePath)
 {
     //TODO LOAD THIS
     mapData = MapData.Load(filePath);
     // copy the map data array
     world = (MapTile[,])mapData.map.Clone();
     // create this mesh
     MapGenerator.singleton.CreateLoadedWorldMesh(new Vector2(mapData.mapSizeX,mapData.mapSizeY));
 }
Ejemplo n.º 42
0
        /// <summary>
        /// This constructor is used when creating a new map.  All tiles are null, since
        /// this is a blank world.
        /// </summary>
        /// <param name="map">the map</param>
        /// <param name="sectionCoord">the section coordinate of this object</param>
        public MapSection(WorldMap map, CoordXZ sectionCoord)
        {
            this.sectionCoord = sectionCoord;
            this.map = map;

            tileCoord = new CoordXZ(sectionCoord, map.TileSize);
            dirty = true;
            dirtyChildren = false;

            tiles = new MapTile[map.TilesPerSection, map.TilesPerSection];
        }
Ejemplo n.º 43
0
 //Key: u = unknown, d = dirt, w = water/wall
 public Map(int width, int height)
 {
     w = width;
     h = height;
     map = new MapTile[width, height];
     //Whole map is unknown at creation
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             map[x, y] = new MapTile();
         }
     }
 }
Ejemplo n.º 44
0
        public Map(string path)
        {
            _left = 1;
            _top = 5;
            _dx = _left;
            _dy = _top;

            string line;
            int count = 0;
            StreamReader mapFile = new StreamReader(path);
            int mapWidth = 0, mapHeight = 0;
            while ((line = mapFile.ReadLine()) != null)
            {
                if (count == 0)
                {
                    mapWidth = Convert.ToInt16(line);
                } else
                if (count == 1)
                {
                    mapHeight = Convert.ToInt16(line);
                    map = new char[mapWidth, mapHeight];
                    _tiles = new MapTile[mapWidth, mapHeight];
                }
                else
                {
                    char[] mp = new char[line.Length];
                    mp = line.ToCharArray();
                    for (int i = 0; i < line.Length; i++)
                    {
                        map[i,count-2] = mp[i];
                        switch (mp[i])
                        {
                            case '.': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_FLOOR, tileType.T_FLOOR, '.'); break; }
                            case '#': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_WALL, tileType.T_WALL, '#'); break; }
                            case '+': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_CLOSED_DOOR, tileType.T_CLOSEDDOOR, '+'); break; }
                            case '/': { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_OPEN_DOOR, tileType.T_OPENDOOR, '/'); break; }
                            default: { _tiles[i, count - 2] = new MapTile(i, count - 2, _left, _top, StringName.TILE_DESC_EMPTY, tileType.T_EMPTY, ' '); break; }
                        }
                        
                    }
                }
                count++;
            }

            _width = map.GetLength(0);
            _height = map.GetLength(1);
            //floorTile = _tiles[character.getOldTop() - _dy, character.getOldLeft() - _dx];
            Console.ForegroundColor = ConsoleColor.White;
        }
Ejemplo n.º 45
0
Archivo: Map.cs Proyecto: xcmel/FWPGame
 /// <summary>
 /// Create the tile grid given the size of the map.
 /// </summary>
 /// <param name="textureSize"></param>
 public void CreateTileGrid(Vector2 textureSize)
 {
     int tilesX = (int) textureSize.X / MAX_TILE_SIZE;
     int tilesY = (int) textureSize.Y / MAX_TILE_SIZE;
     mapTiles = new MapTile[tilesX, tilesY];
     for (int i = 0; i < tilesX; i++)
     {
         for (int j = 0; j < tilesY; j++)
         {
             MapTile tile = new MapTile(new Vector2(i * MAX_TILE_SIZE, j * MAX_TILE_SIZE),
                 new Vector2(MAX_TILE_SIZE, MAX_TILE_SIZE));
             mapTiles[i, j] = tile;
         }
     }
 }
Ejemplo n.º 46
0
Archivo: Map.cs Proyecto: Mokbii/TemFa
    public void Init()
    {
        mRowCount = vMapWidth / vTileSize;
        mColCount = vMapHeight / vTileSize;

        mMapTiles = new MapTile[mRowCount, mColCount];

        for (int iCol = 0; iCol < mColCount; iCol++)
        {
            for (int iRow = 0; iRow < mRowCount; iRow++)
            {
                //MapTile lMapTile = new MapTile(iCol * vMapWidth + iRow, new Vector2((iRow * vTileSize), (iCol * vTileSize)), vTileSize);
                MapTile lMapTile = new MapTile(iCol * vMapWidth + iRow, iRow, iCol, vTileSize);
                mMapTiles[iRow, iCol] = lMapTile;
            }
        }
    }
Ejemplo n.º 47
0
        /// <summary>
        /// Deserializes the first Frame of this State.
        /// </summary>
        /// <param name="stream">Input Stream</param>
        /// <param name="version">Protocol Version</param>
        public void DeserializeFirst(BinaryReader stream, byte version)
        {
            BlockBorder = stream.ReadBoolean();
            int width = stream.ReadInt32();
            int height = stream.ReadInt32();
            Tiles = new MapTile[width, height];

            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                {
                    Tiles[x, y] = new MapTile()
                    {
                        Shape = (TileShape)stream.ReadByte(),
                        Speed = (TileSpeed)stream.ReadByte(),
                        Height = (TileHeight)stream.ReadByte()
                    };
                }
        }
Ejemplo n.º 48
0
        public Map(MapControl mapControl, int width, int height, string name)
        {
            this.mapControl = mapControl;

            this.name = name;
            this.width = width;
            this.height = height;
            this.mapArray = new MapTile[width, height];
            //this.mapArrayLayer1 = new MapTile[width, height];

            this.objectArray = new List<MapObject>();
            this.mapLights = new List<MapLight>();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    mapArray[x, y] = new MapTile(x, y, 1);
                  //  mapArrayLayer1[x, y] = new MapTile(x, y, 0);
                }
            }
        }
Ejemplo n.º 49
0
    // ONLY USED BY THE MAP EDITOR
    public void CreateEmptyWorld(Vector2 size)
    {
        // create a new array
        world = WorldController.singleton.world;
        worldSize = size;
        WorldController.singleton.chunkSize = chunkSize;

        // create the world chunk array
        // get the sizes for the array
        int chunkXSize = Mathf.CeilToInt(size.x/chunkSize);
        int chunkYSize = Mathf.CeilToInt(size.y/chunkSize);
        // create the array
        worldChunks = new WorldChunk[chunkXSize,chunkYSize];
        // determine the offset required so that the world starts at 0,0
        Vector3 extraPos = new Vector3(chunkSize/2,0,chunkSize/2);

        // fill in the array
        for(int i=0;i<worldChunks.GetLength(0);i++){
            for(int j=0;j<worldChunks.GetLength(1);j++){
                // instantiate a new chunk
                GameObject newChunk =  (GameObject)Instantiate(chunkPrefab,Vector3.zero,Quaternion.identity);
                // set the position
                worldChunks[i,j] = newChunk.GetComponent<WorldChunk>();
                worldChunks[i,j].SetChunk(new Vector3(i*chunkSize,0,j*chunkSize)+extraPos,i,j);
                if(worldContainer != null){
                    newChunk.transform.parent = worldContainer;
                }
            }
        }

        // random thing here
        /*for(int n=0;n<ripple.Length;n++){
        if(n < (ripple.Length-1)){
            ripple[n] = ripple[n+1];
        }
        else{
            ripple[n] = ripple[0];
        }
        }*/

        // populate the array
        for(int i=0;i<world.GetLength(0);i++){
            for(int j=0;j<world.GetLength(1);j++){

                // for minecraft like world, do this
                //world[i,j] = new MapTile((byte)(j+i));

                // draw some borders
                if((i==0 || i==(size.x-1)) || (j==0 || j==(size.y-1))){
                    world[i,j] = new MapTile(10);
                }
                else{
                    world[i,j] = new MapTile(1);
                }

            }

        }
        // create the world mesh

        CreateNewWorldMesh();
        // TODO remove this
        MapEditor.CreateColliders();
        /*CreateWorldMesh(size);
        floorMeshFilter.mesh = floorMesh;
        wallMeshFilter.mesh = wallMesh;
        print ("Floor:");
        print ("Total Vertices: "+floorMesh.vertexCount);
        print ("Total Triangles: "+(floorMesh.triangles.Length/3));

        print ("Walls:");
        print ("Total Vertices: "+wallMesh.vertexCount);
        print ("Total Triangles: "+(wallMesh.triangles.Length/3));*/
    }
Ejemplo n.º 50
0
    // TO BE USED IN GAME
    // also used to load a new level
    public void CreateLoadedWorldMesh(Vector2 size)
    {
        // create a new array
        world = WorldController.singleton.world;
        worldSize = size;
        WorldController.singleton.chunkSize = chunkSize;

        // create the world chunk array
        // get the sizes for the array
        int chunkXSize = Mathf.CeilToInt(size.x/chunkSize);
        int chunkYSize = Mathf.CeilToInt(size.y/chunkSize);
        // create a new array
        worldChunks = new WorldChunk[chunkXSize,chunkYSize];
        // determine the offset required so that the world starts at 0,0
        Vector3 extraPos = new Vector3(chunkSize/2,0,chunkSize/2);

        // fill in the array
        for(int i=0;i<worldChunks.GetLength(0);i++){
            for(int j=0;j<worldChunks.GetLength(1);j++){
                // instantiate a new chunk
                GameObject newChunk =  (GameObject)Instantiate(chunkPrefab,Vector3.zero,Quaternion.identity);
                // set the position
                worldChunks[i,j] = newChunk.GetComponent<WorldChunk>();
                worldChunks[i,j].SetChunk(new Vector3(i*chunkSize,0,j*chunkSize)+extraPos,i,j);
                if(worldContainer != null){
                    newChunk.transform.parent = worldContainer;
                }
            }
        }

        CreateNewWorldMesh();
    }
		public WorldMap(int maxWidth, int maxHeight)
		{
			this.MaxWidth = maxWidth;
			this.MaxHeight = maxHeight;
			this._tiles = new MapTile[this.MaxWidth, this.MaxHeight];
		}
Ejemplo n.º 52
0
 void Start()
 {
     mainCam = Camera.main;
     // setup the brush sizes
     SetupMesh();
     SetupGUIRects();
     SetupFilePaths();
     WorldController.singleton.CreateWorld(new Vector2(64,64));
     world = WorldController.singleton.world;
 }
Ejemplo n.º 53
0
 public void Init(int w, int h)
 {
     Width = w; Height = h;
     tiles = new MapTile[w, h];
     descs = new Tuple<Position, obj>[0];
 }
Ejemplo n.º 54
0
        public void PrepareMap()
        {
            this.Tiles = null;
            this.Tiles = new Tile[this.mainMap.MapDimensions.X, this.mainMap.MapDimensions.Y];
            for (int i = 0; i < this.mainMap.MapDimensions.X; i++)
            {
                for (int j = 0; j < this.mainMap.MapDimensions.Y; j++)
                {
                    this.Tiles[i, j] = new Tile();
                    this.Tiles[i, j].Position = new Point(i, j);
                    TerrainDetail terrainDetailByPositionNoCheck = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(this.Tiles[i, j].Position);

                    if (terrainDetailByPositionNoCheck != null)
                    {
                        if (terrainDetailByPositionNoCheck.Textures.BasicTextures.Count > 0)
                        {
                            this.Tiles[i, j].TileTexture = terrainDetailByPositionNoCheck.Textures.BasicTextures[((i * 7) + (j * 11)) % terrainDetailByPositionNoCheck.Textures.BasicTextures.Count];
                        }
                    }
                }
            }

            this.MapTiles = null;
            this.MapTiles = new MapTile[this.mainMap.NumberOfTiles, this.mainMap.NumberOfTiles];
            for (int i = 0; i < this.mainMap.NumberOfTiles; i++)
            {
                for (int j = 0; j < this.mainMap.NumberOfTiles; j++)
                {
                    this.MapTiles[i, j] = new MapTile();
                    this.MapTiles[i, j].Position = new Point(i, j);
                    this.MapTiles[i, j].number = (i + j * this.mainMap.NumberOfTiles).ToString();
                    /*TerrainDetail terrainDetailByPositionNoCheck = this.screen.Scenario.GetTerrainDetailByPositionNoCheck(this.Tiles[i, j].Position);

                    if (terrainDetailByPositionNoCheck != null)
                    {
                        if (terrainDetailByPositionNoCheck.Textures.BasicTextures.Count > 0)
                        {
                            this.Tiles[i, j].TileTexture = terrainDetailByPositionNoCheck.Textures.BasicTextures[((i * 7) + (j * 11)) % terrainDetailByPositionNoCheck.Textures.BasicTextures.Count];
                        }
                        else
                        {
                            this.Tiles[i, j].TileTexture = this.screen.Textures.TerrainTextures[this.mainMap.MapData[i, j]];
                        }
                    }*/
                }
            }
        }
 public void setTileMap(MapTile[,] map)
 {
     tileMap = map;
 }
Ejemplo n.º 56
0
 /// <summary>
 /// Initializes the grid of the map with the grid passed as a reference
 /// </summary>
 /// <param name="view">The grid that is to become this map's grid</param>
 public void InitializeGrid(MapTile[,] view)
 {
     Grid = view;
 }
Ejemplo n.º 57
0
        public void ReadXml(XmlReader reader)
        {
            reader.ReadStartElement();

            m_width = reader.ReadElementContentAsInt();
            m_height = reader.ReadElementContentAsInt();
            m_map = new MapTile[m_width, m_height];

            for (int i = 0; i < m_width; ++i)
            {
                for (int j = 0; j < m_height; ++j)
                {
                    m_map[i, j] = new MapTile();
                    m_map[i, j].ReadXml(reader);
                }
            }

            // Read Map Features
            m_mapObjects = new List<IMapObjectCore>();

            ReadListFromXMLCore readDelegate = new ReadListFromXMLCore(delegate
            {
                string typeString = reader.ReadElementContentAsString();
                MapObject newObj = MapObjectFactory.Instance.CreateMapObject(typeString);
                newObj.ReadXml(reader);
                m_mapObjects.Add(newObj);
            });
            ListSerialization.ReadListFromXML(reader, readDelegate);

            // Read Monsters
            m_monsterList = new List<Monster>();

            readDelegate = new ReadListFromXMLCore(delegate
            {
                string typeString = reader.ReadElementContentAsString();
                int baseLevel = reader.ReadElementContentAsInt();
                Monster newObj = MonsterFactory.Instance.CreateMonster(typeString, baseLevel);
                newObj.ReadXml(reader);
                m_monsterList.Add(newObj);
            });
            ListSerialization.ReadListFromXML(reader, readDelegate);

            // Read Items
            m_items = new List<Pair<Item, Point>>();

            readDelegate = new ReadListFromXMLCore(delegate
            {
                string typeString = reader.ReadElementContentAsString();
                Item newItem = ItemFactory.Instance.CreateBaseItem(typeString);
                newItem.ReadXml(reader);
                Point position = new Point();
                position = position.ReadXml(reader);
                m_items.Add(new Pair<Item, Point>(newItem, position));
            });
            ListSerialization.ReadListFromXML(reader, readDelegate);

            reader.ReadEndElement();
        }
Ejemplo n.º 58
0
 public void BuildVillage()
 {
     map = myGame.map.MapTiles;
 }
Ejemplo n.º 59
0
 public MapGrid(short width, short height)
 {
     this.Grid = new MapTile[width, height];
 }
Ejemplo n.º 60
0
        public void Generate()
        {
            int room_count = Random.Range(this.minimumRoomCount, this.maximumRoomCount);
            int min_size = this.min_size;
            int max_size = this.max_size;

            map_size = (maximumRoomCount + roomMargin) * max_size ;
            map = new MapTile[map_size, map_size];

            for (var x = 0; x < map_size; x++) {
                for (var y = 0; y < map_size; y++) {
                    map[x,y] = new MapTile();
                    map[x,y].type = 0;
                }
            }
            rooms = new List<Room> ();

            this.roomMarginTemp = this.roomMargin;
            for (var i = 0; i < room_count; i++) {

                Room room = new Room();
                if(rooms.Count == 0) {
                    room.x = Random.Range(10,20);
                    room.y = Random.Range(10,20);
                    room.w = Random.Range(min_size, max_size);
                    room.h = Random.Range(min_size, max_size);
                }
                else{
                    Room lastRoom = rooms[rooms.Count -1];

                    if (lastRoom.x > 1 + max_size) {
                        room.x = Random.Range(1  , lastRoom.x + lastRoom.w  + this.roomMargin);
                    }
                    else {
                        room.x = Random.Range(lastRoom.x  , lastRoom.x  + lastRoom.w + this.roomMargin);
                    }

                    if (lastRoom.y > 1 + max_size) {
                        room.y = Random.Range(1 , lastRoom.y  + lastRoom.h + this.roomMargin);
                    }
                    else {
                        room.y = Random.Range(lastRoom.y , lastRoom.y  + lastRoom.h + this.roomMargin);
                    }

                    room.w = Random.Range(min_size, max_size);
                    room.h = Random.Range(min_size, max_size);
                }

                bool doesCollide = this.DoesCollide(room,0);

                if (doesCollide && prune) {
                    i--;
                    this.roomMargin += 1;
                }
                else {
                    this.roomMargin = roomMarginTemp;
                    room.w--;
                    room.h--;

                    rooms.Add(room);
                }
            }

            //corridor making
            if (maximumRoomCount != 1) {
                for (int i = 0; i < 10; i++) {
                    Room roomA = null;
                    Room roomB = null;
                    while (roomA == roomB) {
                        roomA = rooms[Random.Range(0, rooms.Count)];
                        roomB = rooms[Random.Range(0, rooms.Count)];
                    }

                    var pointA = new Room();
                    pointA.x = Random.Range(roomA.x, roomA.x + roomA.w);
                    pointA.y = Random.Range(roomA.y, roomA.y + roomA.h);

                    var pointA2 = new Room();
                    pointA2.x = pointA.x + 1;
                    pointA2.y = pointA.y;

                    var pointB = new Room();
                    pointB.x = Random.Range(roomB.x, roomB.x + roomB.w);
                    pointB.y = Random.Range(roomB.y, roomB.y + roomB.h);

                    var pointB2 = new Room();
                    pointB2.x = pointB.x;
                    pointB2.y = pointB.y + 1;

                    roomA.connectedTo = roomB;

                    while ( (pointB.x != pointA.x) || (pointB.y != pointA.y) || (pointB2.x != pointA2.x) || (pointB2.y != pointA2.y) ) {
                        if (pointB.x != pointA.x) {
                            if (pointB.x > pointA.x) {
                                pointB.x--;
                            }
                            else {
                                pointB.x++;
                            }
                        }
                        else if (pointB.y != pointA.y) {
                            if (pointB.y > pointA.y) {
                                pointB.y--;
                            }
                            else {
                                pointB.y++;
                            }
                        }

                        if (pointB2.x != pointA2.x) {
                            if (pointB2.x > pointA2.x) {
                                pointB2.x--;
                            }
                            else {
                                pointB2.x++;
                            }
                        }
                        else if (pointB2.y != pointA2.y) {
                            if (pointB2.y > pointA2.y) {
                                pointB2.y--;
                            }
                            else {
                                pointB2.y++;
                            }
                        }

                        map[pointB.x,pointB.y].type = 3;
                        map[pointB2.x, pointB2.y].type = 3;

                    }

                }
            }
            //room making
            for (int i = 0; i < rooms.Count; i++) {
                Room room = rooms[i];
                for (int x = room.x; x < room.x + room.w; x++) {
                    for (int y = room.y; y < room.y + room.h; y++) {
                        map[x,y].type = 1;
                        map[x,y].room = room;

                    }
                }
            }

            //walls
            for (int x = 0; x < map_size -1  ; x++) {
                for (int y = 0; y < map_size -1 ; y++) {
                    if (map[x,y].type == 0) {
                        if(    (map[x + 1,y].type == 1 || map[x + 1,y].type == 3)
                            || (map[x,y + 1].type == 1 || map[x,y + 1].type == 3)
                            || (x > 0 && (map[x - 1,y].type == 1 || map[x - 1,y].type == 3))
                            || (y > 0 && (map[x,y - 1].type == 1 || map[x,y - 1].type == 3)) )
                        {
                                map[x,y].type = 2;
                        }

                    }
                }
            }

            //corners
            for (int x = 0; x < map_size -1  ; x++) {
                for (int y = 0; y < map_size -1 ; y++) {
                    if (map[x,y + 1].type == 2 && map[x + 1,y].type == 2 && roomsandfloors.Contains(map[x + 1,y +1].type) ) {
                        map[x,y].type = 4;
                    }
                    if(y > 0){
                        if (map[x + 1,y].type == 2 && map[x,y - 1].type == 2 && roomsandfloors.Contains(map[x + 1,y - 1].type) ) {
                            map[x,y].type = 5;
                        }
                    }
                    if(x > 0){
                        if (map[x - 1,y].type == 2 && map[x,y + 1].type == 2 && roomsandfloors.Contains(map[x - 1,y + 1].type) ) {
                            map[x,y].type = 7;
                        }
                    }
                    if(x > 0 && y >0){
                        if (map[x - 1,y].type == 2 && map[x,y - 1].type == 2 && roomsandfloors.Contains(map[x - 1,y - 1].type) ) {
                            map[x,y].type = 6;
                        }
                    }
                }
            }

            //find far away room
            goalRoom = rooms[rooms.Count -1 ];
            if (goalRoom != null) {
                goalRoom.x = goalRoom.x + (goalRoom.w / 2);
                goalRoom.y = goalRoom.y + (goalRoom.h / 2);
            }
            //starting point
            startRoom = rooms[0];
            startRoom.x = startRoom.x + (startRoom.w / 2);
            startRoom.y = startRoom.y + (startRoom.h / 2);
        }