Esempio n. 1
0
        private static bool CanPlaceTile(Tile t, Grid <BorderKind> terrainId, int tileX, int tileY, out int matches)
        {
            matches = 0;
            for (int x = 0; x <= t.Width; x++)
            {
                for (int y = 0; y <= t.Height; y++)
                {
                    if (tileX + x >= terrainId.Width ||
                        tileY + y >= terrainId.Height)
                    {
                        return(false);
                    }

                    BorderKind terrain1 = t.TerrainId[x, y];
                    BorderKind terrain2 = terrainId[tileX + x, tileY + y];
                    if (!terrain1.IsCompatible(terrain2))
                    {
                        return(false);
                    }
                    if (terrain1 == terrain2)
                    {
                        matches++;
                    }
                    else if (t.IsLarge)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        public Tile GetDefaultTile(TerrainKind terrain, int layer)
        {
            BorderKind        terrainId = terrain.LayerTerrainId[layer];
            Grid <BorderKind> g         = new Grid <BorderKind>(2, 2);

            g[0, 0] = g[0, 1] = g[1, 0] = g[1, 1] = terrainId;

            return(GetTile(null, 0, 0, g, false, null));
        }
Esempio n. 3
0
 public bool IsCompatible(BorderKind kind)
 {
     if (kind == this)
     {
         return(true);
     }
     foreach (BorderKind test in compatible)
     {
         if (test == kind)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
        private Tile CreateTileFromTileSource(Bitmap image, Grid <BorderKind> squares, int baseX, int baseY, int left, int top, int width, int height)
        {
            // Extract the correct subgrid as an array
            BorderKind[] tileBorders = new BorderKind[(width + 1) * (height + 1)];
            for (int x = 0; x <= width; x++)
            {
                for (int y = 0; y <= height; y++)
                {
                    tileBorders[x + y * (width + 1)] = squares[left + x, top + y];
                }
            }

            // Create a tile
            Tile tile = new Tile(image, baseX + TileWidth * left, baseY + TileHeight * top,
                                 TileWidth * width, TileHeight * height, width, height, tileBorders);

            return(tile);
        }
Esempio n. 5
0
        private void MapForm_Load(object sender, EventArgs e)
        {
            BorderKind.MakeCompatible(BorderKind.Wall, BorderKind.Wall2);
            BorderKind.MakeCompatible(BorderKind.Wall, BorderKind.Water);

            try
            {
                TileSet tileSet = TileSet.Load(@"Data\Simple.mdts");
                Debug.Assert(tileSet != null);

                document.NewMap(tileSet);

                document.FillTerrainList(tileSet);
            }
            catch (FileNotFoundException exception)
            {
                MessageBox.Show("There was an error loading the default tileset. Please ensure you have the .NET Framework version 3.5 installed.\n" + exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
        }
Esempio n. 6
0
 public static void MakeCompatible(BorderKind kind1, BorderKind kind2)
 {
     kind1.compatible.Add(kind2);
     kind2.compatible.Add(kind1);
 }
Esempio n. 7
0
        private void AddTileSource(TileSourceDefinition source, Stream stream)
        {
            Bitmap image = new Bitmap(stream);

            Grid <bool> useSquares = new Grid <bool>(source.MapWidth, source.MapHeight);

            for (int x = 0; x < source.MapWidth; x++)
            {
                for (int y = 0; y < source.MapHeight; y++)
                {
                    useSquares[x, y] = true;
                }
            }

            BorderKind[] borderKinds = new BorderKind[source.BorderKinds.Count()];
            for (int i = 0; i < source.BorderKinds.Count(); i++)
            {
                borderKinds[i] = FindBorderKind(source.BorderKinds[i]);
            }

            Grid <BorderKind> squares = new Grid <BorderKind>(source.MapWidth, source.MapHeight);

            for (int x = 0; x < source.MapWidth; x++)
            {
                for (int y = 0; y < source.MapHeight; y++)
                {
                    squares[x, y] = borderKinds[source.Squares[x + y * source.MapWidth]];
                }
            }

            int baseX = TileXOffset - source.ImageLeft;
            int baseY = TileYOffset - source.ImageTop;

            // Add special tiles
            foreach (SpecialTileDefinition special in source.SpecialTiles)
            {
                int  left   = special.Left;
                int  top    = special.Top;
                int  width  = special.Width;
                int  height = special.Height;
                Tile tile   = CreateTileFromTileSource(image, squares, baseX, baseY, left, top, width, height);

                // Add it?
                if (special.AutoPlace)
                {
                    TileList.Add(tile);
                }

                // Squares inside the special tile are not normal squares
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        useSquares[left + x, top + y] = false;
                    }
                }
            }

            // Add normal tiles, except those excluded as part of special tiles.
            for (int x = 0; x < source.MapWidth - 1; x++)
            {
                for (int y = 0; y < source.MapHeight - 1; y++)
                {
                    if (useSquares[x, y])
                    {
                        Tile tile = CreateTileFromTileSource(image, squares, baseX, baseY, x, y, 1, 1);
                        TileList.Add(tile);
                    }
                }
            }
        }