Exemplo n.º 1
0
        public void DrawAt(TileSet tileSet, MapState mapState, Random rng, int squareX, int squareY)
        {
            bool needReSelect;

            needReSelect = false;

            int tileXmin = squareX;
            int tileXmax = squareX + 2;
            int tileYmin = squareY;
            int tileYmax = squareY + 2;

            SetTerrainBase(mapState, squareX, squareY, terrain);
            tileSet.SelectTiles(mapState, rng, tileXmin, tileYmin, tileXmax, tileYmax);

            for (int x = 0; x <= 1; x++)
            {
                for (int y = 0; y <= 1; y++)
                {
                    if (HasNullTile(mapState, squareX + x, squareY + y))
                    {
                        for (int x2 = 0; x2 <= 1; x2++)
                        {
                            for (int y2 = 0; y2 <= 1; y2++)
                            {
                                if (x != x2 || y != y2)
                                {
                                    if (IncompatibleTerrain(mapState.GetSquareKind(squareX + x - x2, squareY + y - y2), terrain))
                                    {
                                        SetTerrainBase(mapState, squareX + x - x2, squareY + y - y2, tileSet.TerrainByIndex[0]);
                                        if (x - x2 < 0)
                                        {
                                            tileXmin = squareX - 1;
                                        }
                                        if (x - x2 > 0)
                                        {
                                            tileXmax = squareX + 3;
                                        }
                                        if (y - y2 < 0)
                                        {
                                            tileYmin = squareY - 1;
                                        }
                                        if (y - y2 > 0)
                                        {
                                            tileYmax = squareY + 3;
                                        }
                                    }
                                }
                            }
                        }
                        needReSelect = true;
                    }
                }
            }
            if (needReSelect)
            {
                SetTerrainBase(mapState, squareX, squareY, terrain);
                tileSet.SelectTiles(mapState, rng, tileXmin, tileYmin, tileXmax, tileYmax);
            }
        }
Exemplo n.º 2
0
        public static Grid <BorderKind> MakeTerrainSubMap(MapState mapState, int tileX, int tileY, int tileXLimit, int tileYLimit, int layer)
        {
            Grid <BorderKind> terrainMap = new Grid <BorderKind>(tileXLimit - tileX + 1, tileYLimit - tileY + 1);

            for (int y = 0; y < terrainMap.Height; y++)
            {
                for (int x = 0; x < terrainMap.Width; x++)
                {
                    terrainMap[x, y] = mapState.GetSquareKind(tileX + x - 1, tileY + y - 1).LayerTerrainId[layer];
                }
            }
            return(terrainMap);
        }
Exemplo n.º 3
0
 private void PaintSynthetic(Graphics target, int layer, int x, int y, int destX, int destY)
 {
     // No tile. Synthesize one
     for (int subX = 0; subX <= 1; subX++)
     {
         for (int subY = 0; subY <= 1; subY++)
         {
             TerrainKind squareKind = state.GetSquareKind(x + subX - 1, y + subY - 1);
             Tile        defaultTile = tileSet.GetDefaultTile(squareKind, layer);
             int         sourceX, sourceY, sourceWidth, sourceHeight;
             if (subX == 0)
             {
                 sourceX     = 0;
                 sourceWidth = tileSet.TileXOffset;
             }
             else
             {
                 sourceX     = tileSet.TileXOffset;
                 sourceWidth = tileSet.TileWidth - tileSet.TileXOffset;
             }
             if (subY == 0)
             {
                 sourceY      = 0;
                 sourceHeight = tileSet.TileYOffset;
             }
             else
             {
                 sourceY      = tileSet.TileYOffset;
                 sourceHeight = tileSet.TileHeight - tileSet.TileYOffset;
             }
             Rectangle rect = new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight);
             if (defaultTile != null)
             {
                 defaultTile.DrawToGraphics(target, destX, destY, rect);
             }
         }
     }
     target.DrawRectangle(new Pen(Color.FromArgb(255, 255, 0, 0)),
                          new Rectangle(destX, destY, tileSet.TileWidth - 1, tileSet.TileWidth - 1));
 }
Exemplo n.º 4
0
        private void SelectLargeTiles(MapState mapState, Random rng, int tileX, int tileY, int tileXLimit, int tileYLimit)
        {
            if (rng == null)
            {
                return;
            }

            int width  = mapState.Width;
            int height = mapState.Height;

            if (tileX < 0)
            {
                tileX = 0;
            }
            if (tileY < 0)
            {
                tileY = 0;
            }
            if (tileXLimit >= width)
            {
                tileXLimit = width - 1;
            }
            if (tileYLimit >= height)
            {
                tileYLimit = height - 1;
            }

            for (int layer = 0; layer < 4; layer++)
            {
                Grid <BorderKind> terrainId = new Grid <BorderKind>(width + 2, height + 2);
                for (int y = 0; y < terrainId.Height; y++)
                {
                    for (int x = 0; x < terrainId.Width; x++)
                    {
                        terrainId[x, y] = mapState.GetSquareKind(x - 1, y - 1).LayerTerrainId[layer];
                    }
                }
                for (int x = 0; x < tileXLimit; x++)
                {
                    for (int y = 0; y < tileYLimit; y++)
                    {
                        if (rng.NextDouble() < 0.5)
                        {
                            continue;
                        }

                        Tile oldTile = mapState.GetTile(layer, x, y);
                        if (oldTile == null || oldTile.IsLarge)
                        {
                            continue;
                        }

                        Tile t = GetTile(rng, x, y, terrainId, true, null);
                        if (t != null)
                        {
                            if (x + t.Width - 1 < tileX)
                            {
                                continue;
                            }
                            if (y + t.Height - 1 < tileY)
                            {
                                continue;
                            }

                            if (CanPlaceLargeTile(mapState, t, layer, x, y))
                            {
                                PlaceLargeTile(mapState, t, layer, x, y);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 public bool NeedsDraw(MapState state, int squareX, int squareY)
 {
     return(state.GetSquareKind(squareX, squareY) != terrain);
 }