// drawing functions public void DrawTileset(byte[] tileset, Tile[] tileSet) { byte temp, tile; Subtile source; int offset = 0; for (int i = 0; i < tileSet.Length; i++) { for (int z = 0; z < 2; z++) { tile = tileset[offset++]; // GFX set? temp = tileset[offset++]; // Palette Set? source = Do.DrawSubtile(tile, temp, graphicSet, paletteSet.Palettes, 0x20); tileSet[i].Subtiles[z] = source; } offset += 60; // jump forward in buffer to grab correct 8x8 tiles for (int a = 2; a < 4; a++) { tile = tileset[offset++]; temp = tileset[offset++]; source = Do.DrawSubtile(tile, temp, graphicSet, paletteSet.Palettes, 0x20); tileSet[i].Subtiles[a] = source;; } if ((i - 15) % 16 == 0) { offset += 64; } offset -= 64; // jump back in buffer so that we can start the next 16x16 tile } }
// Tileset creation public void BuildTilesetTiles(byte[] src, Tile[] dst) { int offset = 0; for (int i = 0; i < dst.Length; i++) { for (int z = 0; z < 2; z++) { ushort tile = (ushort)(Bits.GetShort(src, offset) & 0x03FF); offset++; byte temp = src[offset++]; var source = Do.DrawSubtile(tile, temp, Graphics, paletteSet.Palettes, 0x20); dst[i].Subtiles[z] = source; } offset += 60; // jump forward in buffer to grab correct 8x8 tiles for (int a = 2; a < 4; a++) { ushort tile = (ushort)(Bits.GetShort(src, offset) & 0x03FF); offset++; byte temp = src[offset++]; var source = Do.DrawSubtile(tile, temp, Graphics, paletteSet.Palettes, 0x20); dst[i].Subtiles[a] = source; } if ((i - 15) % 16 == 0) { offset += 64; } offset -= 64; // jump back in buffer so that we can start the next 16x16 tile } }
public void BuildTilesetTiles(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; } } } }
private Subtile CreateNewSubtile() { return(Do.DrawSubtile((ushort)this.subtileIndex.Value, (byte)this.subtilePalette.Value, this.subtileStatus.GetItemChecked(0), this.subtileStatus.GetItemChecked(1), this.subtileStatus.GetItemChecked(2), graphics, paletteSet.Palettes, format)); }
// class functions public void DrawTileset(byte[] src, Tile[] dst, byte[] graphics, byte format) { byte status = 0; ushort tilenum = 0; Subtile subtile; int offset = 0; for (int i = 0; i < Width / 16; i++) { for (int y = 0; y < Height; y++) { for (int x = i * 16; x < i * 16 + 16; x++) { int index = y * Width + x; if (index >= dst.Length) { continue; } for (int z = 0; z < 4; z++) { if (z == 2) { offset += tilesize * 30; } if (tilesize == 2) { tilenum = (ushort)(Bits.GetShort(src, offset++) & 0x03FF); status = src[offset++]; } else { tilenum = src[offset++]; status = (byte)(palette_bytes[tilenum] << 2); } subtile = Do.DrawSubtile(tilenum, status, graphics, paletteSet.Palettes, format); dst[index].Subtiles[z] = subtile; } if (x < i * 16 + 15) { offset -= tilesize * 32; } } } } }
/// <summary> /// Refreshes the tileset's Tile array using the updated data from an animation. /// </summary> /// <param name="animation">The animation containing the updated data to analyze.</param> /// <param name="length">The length of the tileset's binary data.</param> public void RefreshTileset(Animation animation, int length) { this.Graphics = animation.GraphicSet; for (int i = 0; i < length / 8; i++) { for (int z = 0; z < 4; z++) { Subtile source; if (animation.Codec == 1) { source = Do.DrawSubtile((byte)Tiles[i].Subtiles[z].Index, 0, Graphics, Palette, 0x10); } else { source = Do.DrawSubtile((byte)Tiles[i].Subtiles[z].Index, 0, Graphics, Palette, 0x20); } Tiles[i].Subtiles[z] = source; } } }
/// <summary> /// Converts a tileset's binary data to a manageable array of Tile instances. /// </summary> /// <param name="dst"></param> /// <param name="src"></param> public void ParseTileset(Tile[] dst, byte[] src) { byte temp; ushort tile; Subtile source; int offset = 0; int i = 0; for (; i < dst.Length; i++) { if (i > 0 && i % 8 == 0) { offset += 32; } if (Bits.GetShort(src, offset) == 0xFFFF) { break; } else { for (int z = 0; z < 2; z++) { if (offset >= src.Length - 1) { return; } tile = (ushort)(Bits.GetShort(src, offset++) & 0x03FF); temp = src[offset++]; if (animation.Codec == 1) { source = Do.DrawSubtile(tile, temp, Graphics, Palette, 0x10); } else { source = Do.DrawSubtile(tile, temp, Graphics, Palette, 0x20); } dst[i].Subtiles[z] = source; } offset += 28; // jump forward in buffer to grab correct 8x8 tiles for (int a = 2; a < 4; a++) { if (offset >= src.Length - 1) { return; } tile = (ushort)(Bits.GetShort(src, offset++) & 0x03FF); temp = src[offset++]; if (animation.Codec == 1) { source = Do.DrawSubtile(tile, temp, Graphics, Palette, 0x10); } else { source = Do.DrawSubtile(tile, temp, Graphics, Palette, 0x20); } dst[i].Subtiles[a] = source; } offset -= 32; // jump back in buffer so that we can start the next 16x16 tile } } for (; i < 64; i++) // fill up the rest with empty tiles { for (int z = 0; z < 4; z++) { if (animation.Codec == 1) { source = Do.DrawSubtile(0, 0, Graphics, Palette, 0x10); } else { source = Do.DrawSubtile(0, 0, Graphics, Palette, 0x20); } dst[i].Subtiles[z] = source; } } }