예제 #1
0
    private void BuildArea()
    {
        int numAreas = _width * _height / 50;

        _mapAreas = new List <TDArea>();

        int i = 1, counter = 0;

        while (i <= numAreas)
        {
            int areaSizeX = Random.Range(3, 5);
            int areaSizeY = Random.Range(3, 5);

            TDArea area = new TDArea(Random.Range(0, _width - areaSizeX), Random.Range(0, _height - areaSizeY), areaSizeX, areaSizeY);
            if (!AreaCollides(area))
            {
                _mapAreas.Add(area);
                i++;
                MakeArea(area, Random.Range(1, 4));
            }

            counter++;
            if (counter == 500)
            {
                break;                             // infinite loop safety
            }
        }
    }
예제 #2
0
 private void MakeGrassArea(TDArea area)
 {
     for (int x = 0; x < area.width; x++)
     {
         for (int y = 0; y < area.height; y++)
         {
             _tiles[area.top + y, area.left + x].SetTileType((int)TILE_TYPE.GRASS);
         }
     }
 }
예제 #3
0
    private bool AreaCollides(TDArea a)
    {
        foreach (TDArea b in _mapAreas)
        {
            if (a.CollidesWith(b))
            {
                return(true);
            }
        }

        return(false);
    }
예제 #4
0
 private void MakeWallArea(TDArea area)
 {
     for (int x = 0; x < area.width; x++)
     {
         for (int y = 0; y < area.height; y++)
         {
             //if (x == 0 || x == area.width - 1 || y == 0 || y == area.height - 1)
             //	_tiles[area.top+y, area.left+x].SetTileType((int)TILE_TYPE.WALL);
             //else
             //	_tiles[area.top+y, area.left+x].SetTileType((int)TILE_TYPE.GROUND);
             _tiles[area.top + y, area.left + x].SetTileType((int)TILE_TYPE.WALL);
         }
     }
 }
예제 #5
0
    private void MakeArea(TDArea area, int random)
    {
        switch (random)
        {
        case (int)AREA_STYLE.WALL:
            MakeWallArea(area);
            break;

        case (int)AREA_STYLE.GRASS:
            MakeGrassArea(area);
            break;

        case (int)AREA_STYLE.WATER:
            MakeWaterArea(area);
            break;
        }
    }
예제 #6
0
    public bool CollidesWith(TDArea other)
    {
        if (left > other.right + 1)
        {
            return(false);
        }

        if (top > other.bottom + 1)
        {
            return(false);
        }

        if (right < other.left - 1)
        {
            return(false);
        }

        if (bottom < other.top - 1)
        {
            return(false);
        }

        return(true);
    }