Beispiel #1
0
    public Tiles(int sizex, int sizey)
    {
        sizex += 2;
        sizey += 2;
        if (sizex > MaxSize.X || sizey > MaxSize.Y)
        {
            throw new Exception("Size of level is too big");
        }
        tiles    = new Tile[sizey, sizex];
        PosTiles = new PosGroup <Tile>(0, 0, sizex * Tile.Size.X * 2, sizey * Tile.Size.Y * 2, Tile.Size.X * 2, Tile.Size.Y * 2);

        movingTiles = new Group <Tile>();
        Color       = Color.White;
        BorderTile t = new BorderTile();

        for (int i = 1; i < sizex - 1; i++)
        {
            AddTileInternal(i, 0, t);
            AddTileInternal(i, sizey - 1, t);
        }
        for (int i = 0; i < sizey; i++)
        {
            AddTileInternal(0, i, t);
            AddTileInternal(sizex - 1, i, t);
        }
    }
        private bool CanBeEntranceTile(BorderTile borderTile)
        {
            foreach (var entranceTemplate in entranceTemplates)
            {
                if (CompareNeighboursArrays(borderTile.NeighboursArray, entranceTemplate))
                {
                    return(true);
                }
            }

            return(false);
        }
    BorderTile CreateBoarderTile(Tile t_tile)
    {
        if (t_tile.GetOwnerID() == -1)
        {
            BorderTile borderTile = new BorderTile();

            borderTile.m_tile = t_tile;
            borderTile.m_tile.SetOwnerID(GetOwnerID());
            borderTile.m_object = Instantiate(m_borderTileImage, t_tile.GetPostion(), t_tile.transform.rotation);

            Color borderColor = m_owner.GetColor();

            borderTile.m_object.GetComponent <SpriteRenderer>().color = borderColor;

            return(borderTile);
        }

        return(null);
    }
Beispiel #4
0
    public void Clear()
    {
        tiles = new Tile[tiles.GetLength(0), tiles.GetLength(1)];
        BorderTile t = new BorderTile();

        for (int i = 1; i < tiles.GetLength(1) - 1; i++)
        {
            AddTileInternal(i, 0, t);
            AddTileInternal(i, tiles.GetLength(0) - 1, t);
        }
        for (int i = 0; i < tiles.GetLength(0); i++)
        {
            AddTileInternal(0, i, t);
            AddTileInternal(tiles.GetLength(1) - 1, i, t);
        }
        PosTiles = new PosGroup <Tile>(0, 0, GetLength(1) * Tile.Size.X * 2, GetLength(0) *
                                       Tile.Size.Y * 2, Tile.Size.X * 2, Tile.Size.Y * 2);

        movingTiles = new Group <Tile>();
    }
        private List <BorderTile> RandomEntrance(List <BorderTile> possibleEntrance)
        {
            List <BorderTile> entrances = new List <BorderTile>();

            int   maxEntranceCount           = 4;
            float acceptableEntranceDistance = 7;

            for (int i = 0; i < maxEntranceCount && possibleEntrance.Any(); ++i)
            {
                BorderTile randomEntrance = possibleEntrance[random.Next(0, possibleEntrance.Count)];

                if (!entrances.Any(e => Vector2Int.CalculateDistance(randomEntrance.Position, e.Position) < acceptableEntranceDistance))
                {
                    entrances.Add(randomEntrance);
                    possibleEntrance.Remove(randomEntrance);
                }
            }

            return(entrances);
        }
    bool SetupBorderTile(Tile t_tile)
    {
        BorderTile borderTile = CreateBoarderTile(t_tile);

        if (borderTile != null)
        {
            borderTile.m_object.transform.SetParent(transform);
            m_food       += borderTile.m_tile.GetFood();
            m_production += borderTile.m_tile.GetProduction();
            m_borderTiles.Add(borderTile);

            if (borderTile.m_tile.GetResourceTile() != null)
            {
                m_resourceTiles.Add(borderTile.m_tile);
            }

            return(true);
        }

        return(false);
    }