Exemplo n.º 1
0
        public static ushort[,] RenderMap(ROM game, Bitmap mapImage, Bitmap tileset, Bitmap attributeImage, Bitmap attributeBlocks, Map map)
        {
            FastPixel tp  = new FastPixel(tileset);
            FastPixel mp  = new FastPixel(mapImage);
            FastPixel ap  = new FastPixel(attributeImage);
            FastPixel abp = new FastPixel(attributeBlocks);

            ushort[,] MapData = new ushort[map.Width, map.Height];
            BinaryReader ReadROM = new BinaryReader(File.Open(game.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));

            tp.rgbValues  = new byte[tileset.Width * tileset.Height * 4];
            mp.rgbValues  = new byte[mapImage.Width * mapImage.Height * 4];
            ap.rgbValues  = new byte[attributeImage.Width * attributeImage.Height * 4];
            abp.rgbValues = new byte[attributeBlocks.Width * attributeBlocks.Height * 4];

            mp.Lock();
            tp.Lock();
            ap.Lock();
            abp.Lock();

            int TileSrcX, TileSrcY, AttSrcX, AttSrcY, DestX, DestY;

            ReadROM.BaseStream.Position = map.MapData - 0x8000000;
            for (int y = 0; y < map.Height; y++)
            {
                DestY = y * 16;
                for (int x = 0; x < map.Width; x++)
                {
                    MapData[x, y] = ReadROM.ReadUInt16();

                    int Tile      = MapData[x, y] & 0x3FF;
                    int Attribute = MapData[x, y] >> 10;

                    TileSrcX = (Tile % 8) * 16;
                    TileSrcY = (Tile / 8) * 16;
                    AttSrcX  = (Attribute % 8) * 16;
                    AttSrcY  = (Attribute / 8) * 16;
                    DestX    = x * 16;

                    for (int px = 0; px < 16; px++)
                    {
                        for (int py = 0; py < 16; py++)
                        {
                            mp.SetPixel(DestX + px, DestY + py, tp.GetPixel(TileSrcX + px, TileSrcY + py)); // Draw map
                            ap.SetPixel(DestX + px, DestY + py, abp.GetPixel(AttSrcX + px, AttSrcY + py));  // Draw attribute map
                        }
                    }
                }
            }

            mp.Unlock(true);
            tp.Unlock(true);
            ap.Unlock(true);
            abp.Unlock(true);

            ReadROM.Close();
            return(MapData);
        }
Exemplo n.º 2
0
        public static void RenderAttributes(Bitmap attributeImage, Bitmap attributeBlocks, Map map)
        {
            FastPixel ap  = new FastPixel(attributeImage);
            FastPixel abp = new FastPixel(attributeBlocks);

            ap.rgbValues  = new byte[attributeImage.Width * attributeImage.Height * 4];
            abp.rgbValues = new byte[attributeBlocks.Width * attributeBlocks.Height * 4];

            ap.Lock();
            abp.Lock();

            int SrcX, SrcY, DestX, DestY;

            for (int y = 0; y < map.Height; y++)
            {
                DestY = y * 16;
                for (int x = 0; x < map.Width; x++)
                {
                    int Att = map.MapTileData[x, y] >> 10;

                    SrcX  = (Att % 8) * 16;
                    SrcY  = (Att / 8) * 16;
                    DestX = x * 16;

                    for (int px = 0; px < 16; px++)
                    {
                        for (int py = 0; py < 16; py++)
                        {
                            ap.SetPixel(DestX + px, DestY + py, abp.GetPixel(SrcX + px, SrcY + py));
                        }
                    }
                }
            }

            ap.Unlock(true);
            abp.Unlock(true);
        }