// class functions
 public void DrawTileset(Tile[] tileset_tiles)
 {
     for (int y = 0; y < 4; y++)
     {
         for (int x = 0; x < 4; x++)
         {
             for (int z = 0; z < 4; z++)
             {
                 // for palette index 1
                 byte status = 0x04;
                 byte index  = (byte)(y * 16 + (x * 2) + (z % 2));
                 index += z >= 2 ? (byte)8 : (byte)0;
                 Subtile source = Do.DrawSubtile(index, status, graphics, palettes.Palettes, 0x20);
                 tileset_tiles[y * 16 + x].Subtiles[z]     = source;
                 tileset_tiles[y * 16 + x + 8].Subtiles[z] = source;
                 // for palette index 1
                 status = 0x44;
                 index ^= 7;
                 source = Do.DrawSubtile(index, status, graphics, palettes.Palettes, 0x20);
                 tileset_tiles[y * 16 + x + 4].Subtiles[z]  = source;
                 tileset_tiles[y * 16 + x + 12].Subtiles[z] = source;
             }
         }
     }
 }
예제 #2
0
 // constructors
 public Tile(int index)
 {
     this.index  = index; // set tile Number
     this.pixels = new int[16 * 16];
     for (int p = 0; p < 4; p++)
     {
         subtiles[p] = new Subtile(0, new byte[0x20], 0, new int[16], false, false, false, false);
     }
 }
        // assemblers
        public void Assemble(int width, int height)
        {
            int offset = 0;

            for (int q = 0; q < 4; q++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Tile tile = tileset_tiles[(y * width + x) + (q * 256)];
                        if (tile == null)
                        {
                            continue;
                        }
                        for (int s = 0; s < 4; s++)
                        {
                            offset  = y * (width * 2 * 2 * 2) + (x * 2 * 2);
                            offset += (s % 2) * 2;
                            offset += (s / 2) * (width * 2 * 2);
                            offset += (q * 256) * 8;
                            Subtile subtile = tile.Subtiles[s];
                            if (subtile == null)
                            {
                                continue;
                            }
                            Bits.SetShort(tileset_bytes, offset, (ushort)subtile.Index);
                            tileset_bytes[offset + 1] |= (byte)(subtile.Palette << 2);
                            Bits.SetBit(tileset_bytes, offset + 1, 5, subtile.Priority1);
                            Bits.SetBit(tileset_bytes, offset + 1, 6, subtile.Mirror);
                            Bits.SetBit(tileset_bytes, offset + 1, 7, subtile.Invert);
                        }
                    }
                }
            }
            Model.EditTilesetsBF[battlefield.TileSet] = true;
            if (battlefield.GraphicSetA < 0xC8)
            {
                Buffer.BlockCopy(graphics, 0, Model.GraphicSets[battlefield.GraphicSetA + 0x48], 0, 0x2000);
            }
            if (battlefield.GraphicSetB < 0xC8)
            {
                Buffer.BlockCopy(graphics, 0x2000, Model.GraphicSets[battlefield.GraphicSetB + 0x48], 0, 0x1000);
            }
            if (battlefield.GraphicSetC < 0xC8)
            {
                Buffer.BlockCopy(graphics, 0x3000, Model.GraphicSets[battlefield.GraphicSetC + 0x48], 0, 0x1000);
            }
            if (battlefield.GraphicSetD < 0xC8)
            {
                Buffer.BlockCopy(graphics, 0x4000, Model.GraphicSets[battlefield.GraphicSetD + 0x48], 0, 0x1000);
            }
            if (battlefield.GraphicSetE < 0xC8)
            {
                Buffer.BlockCopy(graphics, 0x5000, Model.GraphicSets[battlefield.GraphicSetE + 0x48], 0, 0x1000);
            }
        }
예제 #4
0
 public void CopyTo(Subtile dest)
 {
     dest.Index     = this.index;
     dest.Palette   = this.palette;
     dest.Priority1 = this.priority1;
     dest.Mirror    = this.mirror;
     dest.Invert    = this.invert;
     this.pixels.CopyTo(dest.Pixels, 0);
     this.colors.CopyTo(dest.Colors, 0);
 }
예제 #5
0
        public void DrawOverlapsTileSet(OverlapTile[] tileset)
        {
            int offset = 0x1CEA00;
            int index = 0, loc = 0, place = 0;

            int[] palette = new int[16];
            for (int i = 0; i < palette.Length; i++)
            {
                palette[i] = Color.Black.ToArgb();
            }
            Subtile source;

            Tile[] subtiles;
            for (int i = 0; i < tileset.Length; i++)   // for all 104 overlap tiles
            {
                subtiles = new Tile[4];
                for (int o = 0; o < subtiles.Length; o++)
                {
                    subtiles[o] = new Tile(o);
                }
                for (int a = 0; a < 4; a++) // the four 16x16 tiles in an overlap tile
                {
                    index  = Model.ROM[i * 5 + a + offset];
                    place  = (i / 8) * 32;
                    place += ((i % 8) * 2) + (a % 2) + ((a / 2) * 16);
                    subtiles[a].Mirror = Bits.GetBit(Model.ROM, i * 5 + 4 + offset, ((a * 2) + 1) ^ 7);
                    subtiles[a].Invert = Bits.GetBit(Model.ROM, i * 5 + 4 + offset, (a * 2) ^ 7);
                    if (index != 0)
                    {
                        index--;
                        loc    = index % 8 * 0x40;
                        loc   += index / 8 * 0x400;
                        source = new Subtile(index, graphicSet, loc, palette, false, false, false, false);
                        subtiles[a].Subtiles[0] = source;
                        source = new Subtile(index, graphicSet, loc + 0x20, palette, false, false, false, false);
                        subtiles[a].Subtiles[1] = source;
                        source = new Subtile(index, graphicSet, loc + 0x200, palette, false, false, false, false);
                        subtiles[a].Subtiles[2] = source;
                        source = new Subtile(index, graphicSet, loc + 0x220, palette, false, false, false, false);
                        subtiles[a].Subtiles[3] = source;
                    }
                    else
                    {
                        source = new Subtile(index, new byte[0x20], 0, palette, false, false, false, false);
                        subtiles[a].Subtiles[0] = source;
                        subtiles[a].Subtiles[1] = source;
                        subtiles[a].Subtiles[2] = source;
                        subtiles[a].Subtiles[3] = source;
                    }
                    tileset[i].SetSubtile(subtiles[a], a);
                }
            }
        }
예제 #6
0
        // spawning
        public Subtile Copy()
        {
            Subtile copy = new Subtile();

            copy.Pixels    = new int[this.pixels.Length]; this.Pixels.CopyTo(copy.Pixels, 0);
            copy.Colors    = new int[this.colors.Length]; this.Colors.CopyTo(copy.Colors, 0);
            copy.Priority1 = this.priority1;
            copy.Mirror    = this.mirror;
            copy.Invert    = this.invert;
            copy.Index     = this.index;
            copy.Palette   = this.palette;
            return(copy);
        }
예제 #7
0
        // spawning
        public Tile Copy()
        {
            Tile copy = new Tile(this.index);

            for (int i = 0; i < 4; i++)
            {
                Subtile source = subtiles[i].Copy();
                copy.Subtiles[i] = source;
            }
            copy.Mirror = mirror;
            copy.Invert = invert;
            return(copy);
        }
예제 #8
0
            // public functions
            public void DrawSubtiles(byte[] graphics, int[] palette, bool gridplane)
            {
                int stop = 0;

                if (gridplane)
                {
                    if (subtile_bytes == null)
                    {
                        return;
                    }
                    switch (format)
                    {
                    case 0: stop = 9; break;

                    case 1:
                    case 2: stop = 12; break;

                    case 3: stop = 16; break;
                    }
                    subtile_tiles = new Subtile[16];
                    for (int i = 0; i < stop; i++)
                    {
                        if (subtile_bytes[i] != 0)
                        {
                            subtile_tiles[i] = new Subtile(subtile_bytes[i] - 1, graphics, (subtile_bytes[i] - 1) * 0x20, palette, false, false, false, false);
                        }
                        else
                        {
                            subtile_tiles[i] = new Subtile(0, new byte[0x20], 0, new int[16], false, false, false, false);
                        }
                    }
                }
                else
                {
                    subtile_tiles = new Subtile[4];
                    for (int i = 0; i < 4; i++)
                    {
                        if (subtile_bytes[i] != 0)
                        {
                            subtile_tiles[i] = new Subtile(subtile_bytes[i] - 1, graphics, (subtile_bytes[i] - 1) * 0x20, palette, false, false, false, false);
                        }
                        else
                        {
                            subtile_tiles[i] = new Subtile(0, new byte[0x20], 0, new int[16], false, false, false, false);
                        }
                    }
                }
            }
예제 #9
0
        public void Assemble(int width)
        {
            int offset = 0;

            if (Type != TilesetType.Mode7)
            {
                for (int l = 0; l < tilesets_tiles.Length; l++)
                {
                    if (tilesets_tiles[l] == null)
                    {
                        continue;
                    }
                    for (int y = 0; y < tilesets_tiles[l].Length / width; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            Tile tile = tilesets_tiles[l][y * width + x];
                            for (int s = 0; s < 4; s++)
                            {
                                offset  = y * (width * 8) + (x * 4);
                                offset += (s % 2) * 2;
                                offset += (s / 2) * (width * 4);
                                Subtile subtile = tile.Subtiles[s];
                                if (subtile == null)
                                {
                                    continue;
                                }
                                Bits.SetShort(tilesets_bytes[l], offset, (ushort)subtile.Index);
                                tilesets_bytes[l][offset + 1] |= (byte)(subtile.Palette << 2);
                                Bits.SetBit(tilesets_bytes[l], offset + 1, 5, subtile.Priority1);
                                Bits.SetBit(tilesets_bytes[l], offset + 1, 6, subtile.Mirror);
                                Bits.SetBit(tilesets_bytes[l], offset + 1, 7, subtile.Invert);
                            }
                        }
                    }
                }
                if (Type == TilesetType.Level)
                {
                    Model.EditTilesets[levelMap.TilesetL1 + 0x20] = true;
                    Model.EditTilesets[levelMap.TilesetL2 + 0x20] = true;
                    Model.EditTilesets[levelMap.TilesetL3]        = true;
                    //
                    Buffer.BlockCopy(graphics, 0, Model.GraphicSets[levelMap.GraphicSetA + 0x48], 0, 0x2000);
                    Buffer.BlockCopy(graphics, 0x2000, Model.GraphicSets[levelMap.GraphicSetB + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x3000, Model.GraphicSets[levelMap.GraphicSetC + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x4000, Model.GraphicSets[levelMap.GraphicSetD + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x5000, Model.GraphicSets[levelMap.GraphicSetE + 0x48], 0, 0x1000);
                    //
                    Model.EditGraphicSets[levelMap.GraphicSetA + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetB + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetC + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetD + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetE + 0x48] = true;
                }
                else if (Type == TilesetType.SideScrolling)
                {
                    Buffer.BlockCopy(graphics, 0, Model.MinecartSSGraphics, 0, graphics.Length);
                }
                else if (Type == TilesetType.Title)
                {
                    Buffer.BlockCopy(tilesets_bytes[0], 0, Model.TitleData, 0, 0x1000);
                    Buffer.BlockCopy(tilesets_bytes[1], 0, Model.TitleData, 0x1000, 0x1000);
                    Buffer.BlockCopy(tilesets_bytes[2], 0, Model.TitleData, 0xBBE0, 0x300);
                    Buffer.BlockCopy(graphics, 0, Model.TitleData, 0x6C00, 0x4FE0);
                    Buffer.BlockCopy(graphicsL3, 0x40, Model.TitleData, 0xBEE0, 0x1B80);
                }
                else if (Type == TilesetType.Opening)
                {
                    Buffer.BlockCopy(tilesets_bytes[0], 0, Model.OpeningData, 0, 0x480);
                    Buffer.BlockCopy(graphics, 0, Model.OpeningData, 0x480, 0x1340);
                }
            }
            else
            {
                if (Tileset_tiles == null)
                {
                    return;
                }
                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        int i = y * 16 + x;
                        for (int z = 0; z < 4; z++)
                        {
                            offset  = y * (width * 4) + (x * 2);
                            offset += z % 2;
                            offset += (z / 2) * (width * 2);
                            Subtile subtile = Tileset_tiles[i].Subtiles[z];
                            byte    tilenum = (byte)subtile.Index;
                            subtile_bytes[offset]  = tilenum;
                            palette_bytes[tilenum] = (byte)subtile.Palette;
                        }
                    }
                }
                Buffer.BlockCopy(graphics, 0, Model.MinecartM7Graphics, 0, graphics.Length);
            }
        }
예제 #10
0
        // assemblers
        public void Assemble(int width, int layer)
        {
            if (tilesets_tiles[layer] == null)
            {
                return;
            }
            //
            int offset = 0;

            if (Type == TilesetType.Level || Type == TilesetType.Title)
            {
                for (int y = 0; y < tilesets_tiles[layer].Length / width; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        int index = y * width + x;
                        if (index >= tilesets_tiles[layer].Length)
                        {
                            continue;
                        }
                        Tile tile = tilesets_tiles[layer][index];
                        for (int s = 0; s < 4; s++)
                        {
                            offset  = y * (width * 8) + (x * 4);
                            offset += (s % 2) * 2;
                            offset += (s / 2) * (width * 4);
                            Subtile subtile = tile.Subtiles[s];
                            if (subtile == null)
                            {
                                continue;
                            }
                            Bits.SetShort(tilesets_bytes[layer], offset, (ushort)subtile.Index);
                            tilesets_bytes[layer][offset + 1] |= (byte)(subtile.Palette << 2);
                            Bits.SetBit(tilesets_bytes[layer], offset + 1, 5, subtile.Priority1);
                            Bits.SetBit(tilesets_bytes[layer], offset + 1, 6, subtile.Mirror);
                            Bits.SetBit(tilesets_bytes[layer], offset + 1, 7, subtile.Invert);
                        }
                    }
                }
                if (Type == TilesetType.Level)
                {
                    if (layer == 0)
                    {
                        Model.EditTilesets[levelMap.TilesetL1 + 0x20] = true;
                    }
                    if (layer == 1)
                    {
                        Model.EditTilesets[levelMap.TilesetL2 + 0x20] = true;
                    }
                    if (layer == 2)
                    {
                        Model.EditTilesets[levelMap.TilesetL3] = true;
                    }
                    //
                    Buffer.BlockCopy(graphics, 0, Model.GraphicSets[levelMap.GraphicSetA + 0x48], 0, 0x2000);
                    Buffer.BlockCopy(graphics, 0x2000, Model.GraphicSets[levelMap.GraphicSetB + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x3000, Model.GraphicSets[levelMap.GraphicSetC + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x4000, Model.GraphicSets[levelMap.GraphicSetD + 0x48], 0, 0x1000);
                    Buffer.BlockCopy(graphics, 0x5000, Model.GraphicSets[levelMap.GraphicSetE + 0x48], 0, 0x1000);
                    //
                    Model.EditGraphicSets[levelMap.GraphicSetA + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetB + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetC + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetD + 0x48] = true;
                    Model.EditGraphicSets[levelMap.GraphicSetE + 0x48] = true;
                }
                else if (Type == TilesetType.Title)
                {
                    Buffer.BlockCopy(tilesets_bytes[0], 0, Model.TitleData, 0, 0x1000);
                    Buffer.BlockCopy(tilesets_bytes[1], 0, Model.TitleData, 0x1000, 0x1000);
                    Buffer.BlockCopy(tilesets_bytes[2], 0, Model.TitleData, 0xBBE0, 0x300);
                    Buffer.BlockCopy(graphics, 0, Model.TitleData, 0x6C00, 0x4FE0);
                    Buffer.BlockCopy(graphicsL3, 0x40, Model.TitleData, 0xBEE0, 0x1B80);
                }
            }
            else
            {
                Assemble(width);
            }
        }