Пример #1
0
 public SpriteTileInfo() : base()
 {
     SpriteTP_Blend = new TexturePageInfo();
     Group          = 0;
     Parameter      = 0;
     State          = 0;
 }
Пример #2
0
 public SpriteTileInfo(Int16 destx, Int16 desty, byte pgsrcx, byte pgsrcy, UInt16 clut, TexturePageInfo tpi, UInt16 group, byte param, byte state) :
     base(destx, desty, pgsrcx, pgsrcy, clut)
 {
     SpriteTP_Blend = tpi;
     Group          = group;
     Parameter      = param;
     State          = state;
 }
Пример #3
0
        private TileMap ReadTileMap(UInt32 offset, UInt32 nextoffset)
        {
            LayerType LayerIndex = 0;
            UInt16    type, pos, count;
            Int16     destx, desty;
            byte      pgsrcx, pgsrcy;
            UInt16    clut;
            UInt16    textinfo;
            UInt16    group;
            byte      parameter;
            byte      state;
            TileMap   map = new TileMap();
            int       i;

            reader.BaseStream.Seek(offset, SeekOrigin.Begin);
            Int16 maxx = 0;
            Int16 maxy = 0;

            for (i = 0; i < 4; i++)
            {
                map.Offsets[i] = reader.ReadUInt32();
            }
            //read LayerInfos
            Layer     layer     = new Layer(LayerIndex);
            LayerPage layerpage = new LayerPage();

            while (reader.BaseStream.Position < offset + map.Offsets[0])
            {
                type = reader.ReadUInt16();
                if (type == 0x7FFE)
                {
                    //End of layer
                    pos   = reader.ReadUInt16();
                    count = reader.ReadUInt16();
                    layerpage.TexturePageId = pos;
                    layer.LayerPages.Add(layerpage);
                    layerpage = new LayerPage();
                }
                else if (type == 0x7FFF)
                {
                    map.Layers.Add(layer);
                    LayerIndex++;
                    layer = new Layer(LayerIndex);
                }
                else
                {
                    pos   = reader.ReadUInt16();
                    count = reader.ReadUInt16();
                    LayerInfo li = new LayerInfo(type, pos, count);
                    layerpage.LayerInfos.Add(li);
                }
            }
            //read TileInfos
            reader.BaseStream.Position = offset + map.Offsets[0];
            foreach (LayerPage lp in map.Layers[0].LayerPages)
            {
                foreach (LayerInfo li in lp.LayerInfos)
                {
                    for (int tilenum = 0; tilenum < li.TileCount; tilenum++)
                    {
                        destx       = reader.ReadInt16();
                        desty       = reader.ReadInt16();
                        map.OriginX = Math.Min(map.OriginX, destx);
                        map.OriginY = Math.Min(map.OriginY, desty);
                        maxx        = Math.Max(maxx, destx);
                        maxy        = Math.Max(maxy, desty);
                        pgsrcx      = reader.ReadByte();
                        pgsrcy      = reader.ReadByte();
                        clut        = reader.ReadUInt16();
                        TileInfo tile = new TileInfo(destx, desty, pgsrcx, pgsrcy, clut);
                        li.Tiles.Add(tile);
                    }
                }
            }
            //read TextureInfos
            reader.BaseStream.Position = offset + map.Offsets[1];
            while (reader.BaseStream.Position < offset + map.Offsets[2])
            {
                textinfo = reader.ReadUInt16();
                TexturePageInfo ti = new TexturePageInfo(textinfo);
                map.TexturePageInfos.Add(ti);
            }
            //read SpriteInfos
            reader.BaseStream.Position = offset + map.Offsets[2];
            while (reader.BaseStream.Position < offset + map.Offsets[3])
            {
                destx       = reader.ReadInt16();
                desty       = reader.ReadInt16();
                map.OriginX = Math.Min(map.OriginX, destx);
                map.OriginY = Math.Min(map.OriginY, desty);
                maxx        = Math.Max(maxx, destx);
                maxy        = Math.Max(maxy, desty);
                pgsrcx      = reader.ReadByte();
                pgsrcy      = reader.ReadByte();
                clut        = reader.ReadUInt16();
                textinfo    = reader.ReadUInt16();
                TexturePageInfo tpi = new TexturePageInfo(textinfo);
                group     = reader.ReadUInt16();
                parameter = reader.ReadByte();
                state     = reader.ReadByte();
                SpriteTileInfo si = new SpriteTileInfo(destx, desty, pgsrcx, pgsrcy, clut, tpi, group, parameter, state);
                map.SpriteTileInfos.Add(si);
            }
            //read ExtraInfos

            map.Width  = (UInt16)(Math.Abs(maxx - map.OriginX) + 16);
            map.Height = (UInt16)(Math.Abs(maxy - map.OriginY) + 16);
            return(map);
        }
Пример #4
0
        private void RefreshTileMap()
        {
            tilemap = new Bitmap(field.TileMap.Width, field.TileMap.Height, PixelFormat.Format32bppArgb);
            Graphics gBmp = Graphics.FromImage(tilemap);

            gBmp.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            gBmp.FillRectangle(Brushes.Black, 0, 0, field.TileMap.Width, field.TileMap.Height);
            gBmp.Dispose();
            Color transparentcolor = Color.FromArgb(255, 0, 0, 0);
            bool  transparent;

            if (chkBackground.Checked)
            {
                foreach (LayerPage l in field.TileMap.Layers[0].LayerPages)
                {
                    TexturePageInfo tpi = field.TileMap.TexturePageInfos[l.TexturePageId];
                    foreach (LayerInfo li in l.LayerInfos)
                    {
                        foreach (TileInfo ti in li.Tiles)
                        {
                            PaletteId = ti.ClutNumber;
                            for (int offsety = 0; offsety < 16; offsety++)
                            {
                                for (int offsetx = 0; offsetx < 16; offsetx += 2)
                                {
                                    Texture t        = mim.Textures[tpi.PageY];
                                    int     sourcey  = ti.TexPageSourceY + offsety;
                                    int     sourcex  = (ti.TexPageSourceX + offsetx) / 2 + ((tpi.PageX * 64) - t.X);
                                    int     destx    = ti.DestinationX - field.TileMap.OriginX + offsetx;
                                    int     desty    = ti.DestinationY - field.TileMap.OriginY + offsety;
                                    int     pixelidx = (sourcey * t.Width) + sourcex;
                                    int     pixel1   = t.Pixels[pixelidx] & 0xFF;
                                    int     pixel2   = t.Pixels[pixelidx] >> 8;
                                    Color   color1   = mim.Clut[PaletteId].Entries[pixel1].Color;
                                    Color   color2   = mim.Clut[PaletteId].Entries[pixel2].Color;
                                    transparent = color1.Equals(transparentcolor) ^ mim.Clut[PaletteId].Entries[pixel1].STP;
                                    if (!transparent)
                                    {
                                        tilemap.SetPixel(destx, desty, color1);
                                    }
                                    transparent = color2.Equals(transparentcolor) ^ mim.Clut[PaletteId].Entries[pixel2].STP;
                                    if (!transparent)
                                    {
                                        tilemap.SetPixel(destx + 1, desty, color2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (chkSprites.Checked)
            {
                foreach (SpriteTileInfo si in field.TileMap.SpriteTileInfos)
                {
                    PaletteId = si.ClutNumber;
                    TexturePageInfo tpi = si.SpriteTP_Blend;
                    for (int offsety = 0; offsety < 16; offsety++)
                    {
                        for (int offsetx = 0; offsetx < 16; offsetx += 2)
                        {
                            Texture t        = mim.Textures[tpi.PageY];
                            int     sourcey  = si.TexPageSourceY + offsety;
                            int     sourcex  = (si.TexPageSourceX + offsetx) / 2 + ((tpi.PageX * 64) - t.X);
                            int     destx    = si.DestinationX - field.TileMap.OriginX + offsetx;
                            int     desty    = si.DestinationY - field.TileMap.OriginY + offsety;
                            int     pixelidx = (sourcey * t.Width) + sourcex;
                            int     pixel1   = t.Pixels[pixelidx] & 0xFF;
                            int     pixel2   = t.Pixels[pixelidx] >> 8;
                            Color   color1   = mim.Clut[PaletteId].Entries[pixel1].Color;
                            Color   color2   = mim.Clut[PaletteId].Entries[pixel2].Color;
                            if ((si.Parameter & 0x80) == 0x80)
                            {
                                Color oldcolor1 = tilemap.GetPixel(destx, desty);
                                Color oldcolor2 = tilemap.GetPixel(destx + 1, desty);
                                Color newcolor1 = Color.Black, newcolor2 = Color.Black;
                                if (tpi.BlendingMode == 1 || tpi.BlendingMode == 3)
                                {
                                    newcolor1 = Color.FromArgb(255,
                                                               Math.Min(255, oldcolor1.R + color1.R),
                                                               Math.Min(255, oldcolor1.G + color1.G),
                                                               Math.Min(255, oldcolor1.B + color1.B));
                                    newcolor2 = Color.FromArgb(255,
                                                               Math.Min(255, oldcolor2.R + color2.R),
                                                               Math.Min(255, oldcolor2.G + color2.G),
                                                               Math.Min(255, oldcolor2.B + color2.B));
                                }
                                else if (tpi.BlendingMode == 2)
                                {
                                    newcolor1 = Color.FromArgb(255,
                                                               Math.Max(0, oldcolor1.R - color1.R),
                                                               Math.Max(0, oldcolor1.G - color1.G),
                                                               Math.Max(0, oldcolor1.B - color1.B));
                                    newcolor2 = Color.FromArgb(255,
                                                               Math.Max(0, oldcolor2.R - color2.R),
                                                               Math.Max(0, oldcolor2.G - color2.G),
                                                               Math.Max(0, oldcolor2.B - color2.B));
                                }
                                tilemap.SetPixel(destx, desty, newcolor1);
                                tilemap.SetPixel(destx + 1, desty, newcolor2);
                            }
                            else
                            {
                                transparent = color1.Equals(transparentcolor) ^ mim.Clut[PaletteId].Entries[pixel1].STP;
                                if (!transparent)
                                {
                                    tilemap.SetPixel(destx, desty, color1);
                                }
                                transparent = color2.Equals(transparentcolor) ^ mim.Clut[PaletteId].Entries[pixel2].STP;
                                if (!transparent)
                                {
                                    tilemap.SetPixel(destx + 1, desty, color2);
                                }
                            }
                        }
                    }
                }
            }

            pbTileMap.Image = tilemap;
            pbTileMap.Invalidate();
        }