コード例 #1
0
        private Info fullLoad()
        {
            plane = new SpecialBitmap(dir2 + "plane.png");
            Info n = new Info(plane.Width / 128, plane.Height / 128);

            n.Tiles = new List<Tiles>();
            List<int> pallet = new List<int>();

            int last;
            for (int y = 0; y < plane.Height; y += 8)
            {
                for (int x = 0; x < plane.Width; x += 8)
                {
                    int[][] gm = Help.init2D<int>(8, 8);
                    for (int _y = 0; _y < 8; _y++)
                    {
                        for (int _x = 0; _x < 8; _x++)
                        {
                            var pind = 0;
                            var m = plane.GetPixel(x + _x, y + _y);
                            if ((pind = pallet.IndexOf(m)) == -1)
                            {
                                pallet.Add(m);
                                pind = pallet.Count;
                            }
                            gm[_x ][_y ] = pind;
                        }
                    }

                    if (!n.Tiles.Any(a => (last = colorsEqual(a.colors, gm)) != -1))
                    {
                        Console.WriteLine("Tiles: " + n.Tiles.Count);

                        Tiles dm;
                        n.Tiles.Add(dm = new Tiles() { colors = gm });
                        dm.setInfo(n);
                    }
                }
            }



            Console.WriteLine("tp");


            for (int y = 0; y < plane.Height; y += 16)
            {
                for (int x = 0; x < plane.Width; x += 16)
                {
                    Tile[] gm = new Tile[4];
                    for (int _y = 0; _y < 2; _y++)
                    {
                        for (int _x = 0; _x < 2; _x++)
                        {
                            int[][] cm = Help.init2D<int>(8, 8);
                            for (int __y = 0; __y < 8; __y++)
                            {
                                for (int __x = 0; __x < 8; __x++)
                                {
                                    var d = plane.GetPixel(x + _x * 8 + __x, y + _y * 8 + __y);
                                    cm[__x ][ __y ] = pallet.IndexOf(d);
                                }
                            }
                            last = -1;

                            Tiles mj;
                            if ((mj = n.Tiles.FirstOrDefault(a => (last = colorsEqual(a.colors, cm)) != -1)) != null)
                            {
                                Tile md;
                                gm[_x + _y * 2] = (md = new Tile(n.Tiles.IndexOf(mj), last));
                                md.setInfo(n);
                            }
                            else
                            {
                                Tile md;
                                gm[_x + _y * 2] = (md = new Tile(0, 0));
                                md.setInfo(n);
                            }
                        }
                    }
                    if (!n.Blocks.Any(a => a.Equals(gm)))
                    {
                        Console.WriteLine("peices: " + n.Blocks.Count);
                        n.Blocks.Add(new TilePiece(gm));
                    }
                }
            }

            Console.WriteLine("chunks ");

            var b = new SpecialBitmap(dir2 + "ChunkList.png");
            int inj = 0;
            var inc = 0;
            for (int offy = 0; offy < b.Height; offy += 128)
            {
                for (int offx = 0; offx < b.Width; offx += 128)
                {

                    int[][] j = Help.init2D<int>(8, 8);

                    for (int d = 0; d < 8; d++)
                    {
                        for (int k = 0; k < 8; k++)
                        {
                            int[] mc = new int[16 * 16];
                            for (int _x = 0; _x < 16; _x++)
                            {
                                for (int _y = 0; _y < 16; _y++)
                                {
                                    var m = b.GetPixel(k * 16 + offx + _x, d * 16 + offy + _y);
                                    var dl = m;
                                    mc[_x + _y * 16] = pallet.IndexOf(dl);
                                }
                            }
                            var ddf = n.Blocks.FirstOrDefault(a => a.Compare(mc));
                            if (ddf != null && n.Blocks.IndexOf(ddf) > -1)
                            {
                                j[k][d] = n.Blocks.IndexOf(ddf);
                                Console.WriteLine("chunk: " + n.Blocks.IndexOf(ddf));

                            }
                            else
                            {
                                Console.WriteLine(inj++);
                            }

                        }
                    }

                    TileChunk fd;
                    n.Chunks.Add(fd = new TileChunk(j));
                    fd.hLayer = Help.init2D<int>(8,8);
                    fd.setInfo(n);

                }
            }
            b.close();
            inj = 0;
            var highs = getColors(n, plane, pallet);
            int ind = 0;
            foreach (var high in highs)
            {
                
                var x = ind % n.LevelWidth;
                var y = ind / n.LevelWidth;

                ind++;

                var mcd = n.Chunks.FirstOrDefault(a => a.Compare(high));
                if (mcd != null)
                {
                    n.ChunkMap[x][y] = n.Chunks.IndexOf(mcd);
                }
                else
                {
                    Console.WriteLine(inj++);
                }
            }
            highs = getColors(n, dir2 + "plane highs.png", pallet);
            for (int index = 0; index < highs.Length; index++)
            {

                var x = index % n.LevelWidth;
                var y = index / n.LevelWidth;



                int[] high = highs[index];
                TileChunk ch = n.Chunks[n.ChunkMap[x][y]];
                ch.hLayer = Help.init2D<int>(8, 8);

                for (int i = 0; i < ch.tilePieces.Length; i++)
                {
                    int _x = i % 8;
                    int _y = i / 8;

                    TilePiece tp = n.Blocks[ch.tilePieces[_x][_y]];
                    bool good = true;
                    bool allbalck = true;
                    for (int j = 0; j < 16; j++)
                    {
                        for (int k = 0; k < 16; k++)
                        {
                            int p = tp.getPixel(j, k);
                            if (p != 0) allbalck = false;
                            if (high[(_x * 16 + j) + (_y * 16 + k) * 128] != p)
                            {
                                good = false;
                                break;
                            }
                        }
                    }
                    if (allbalck) continue;
                    ch.hLayer[_x][_y] = good ? 1 : 0;
                }

            }

            Console.WriteLine("solid ");

            solidLoad(n);
            n.Palette = pallet.Select(a =>
            {
                var c = Color.FromArgb(a);

                return
                    ((c.R.ToString("X").Length == 1 ? "0" : "") + c.R.ToString("X")) +
                    ((c.G.ToString("X").Length == 1 ? "0" : "") + c.G.ToString("X")) +
                    ((c.B.ToString("X").Length == 1 ? "0" : "") + c.B.ToString("X"));

            }).ToArray();

            save(n);
            Application.Exit();
            /*         n.highPlane = highs.Select(a =>
            {
                var firstOrDefault = n.Chunks.FirstOrDefault(bc => compareBitmap(bc, a));
                if (firstOrDefault != null)
                    return firstOrDefault.Index;
                else
                    return 0;
            }).ToArray();
               var lows = getColors(n, dir2 + "plane low.png");

               n.lowPlane = new List<int>(lows.Select(a =>
               {
                       var firstOrDefault = n.getChunk().FirstOrDefault(bc => compareBitmap(bc, a));
                if (firstOrDefault != null)
                    return firstOrDefault.Index;
                else
                    return (byte) 0;
               }).AsParallel());*/





            save(n);
            return n;
        }
コード例 #2
0
 public TilePiece(Tile[] gm)
 {
     tiles = gm;
 }
コード例 #3
0
 public bool Equals(Tile other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.State == State && other.TileIndex == TileIndex;
 }