Beispiel #1
0
        internal void DrawLevel()
        {
            if (!loaded)
            {
                return;
            }
            LevelGfx.Clear(palette[0]);
            LevelImg8bpp.Clear();
            Point pnlcur = Panel1.PointToClient(Cursor.Position);

            for (int y = Math.Max(VScrollBar1.Value / 32, 0); y <= Math.Min((VScrollBar1.Value + (Panel1.Height - 1)) / 32, map.GetLength(1) - 1); y++)
            {
                for (int x = Math.Max(HScrollBar1.Value / 32, 0); x <= Math.Min((HScrollBar1.Value + (Panel1.Width - 1)) / 32, map.GetLength(0) - 1); x++)
                {
                    if (map[x, y].Tile < tiles.Count)
                    {
                        LevelImg8bpp.DrawBitmapComposited(flippedtiles[map[x, y].List][map[x, y].Tile], new Point(x * 32 - HScrollBar1.Value, y * 32 - VScrollBar1.Value));
                    }
                }
            }
            LevelGfx.DrawImage(LevelImg8bpp.ToBitmap(palette), 0, 0, LevelImg8bpp.Width, LevelImg8bpp.Height);
            BitmapBits bmp2 = new BitmapBits(tiles[tileList1.SelectedIndex]);

            bmp2.Rotate((byte)domainUpDown1.SelectedIndex);
            bmp2.Flip(checkBox1.Checked, false);
            LevelGfx.DrawImage(bmp2.ToBitmap(palette),
                               new Rectangle((((pnlcur.X + HScrollBar1.Value) / 32) * 32) - HScrollBar1.Value, (((pnlcur.Y + VScrollBar1.Value) / 32) * 32) - VScrollBar1.Value, 32, 32),
                               0, 0, 32, 32,
                               GraphicsUnit.Pixel, imageTransparency);
            PanelGfx.DrawImage(LevelBmp, 0, 0, Panel1.Width, Panel1.Height);
        }
Beispiel #2
0
 private void Button3_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog fd = new OpenFileDialog())
     {
         fd.DefaultExt = "cm_";
         fd.Filter     = "CM_ Files|*.cm_|All Files|*.*";
         if (fd.ShowDialog() == DialogResult.OK)
         {
             TextBox2.Text = fd.FileName;
             byte[] file = SZDDComp.SZDDComp.Decompress(fd.FileName);
             if (BitConverter.ToInt32(file, 0) != 0x4C524353)
             {
                 MessageBox.Show("Not a valid tile file.");
                 return;
             }
             tiles = new List <BitmapBits>();
             tiles.Add(new BitmapBits(32, 32));
             int numSprites = BitConverter.ToInt32(file, 8);
             int spriteOff  = BitConverter.ToInt32(file, 0xC);
             for (int i = 0; i < numSprites; i++)
             {
                 int    data   = (i * 4) + 0x18;
                 int    width  = BitConverter.ToInt16(file, data);
                 int    height = BitConverter.ToInt16(file, data + 2);
                 byte[] sprite = new byte[(width / 2) * height];
                 Array.Copy(file, spriteOff, sprite, 0, sprite.Length);
                 spriteOff += sprite.Length;
                 BitmapBits bmp = new BitmapBits(width, height, sprite);
                 tiles.Add(bmp);
                 for (int l = 0; l < 8; l++)
                 {
                     BitmapBits bmp2 = new BitmapBits(bmp);
                     bmp2.Rotate(l & 3);
                     bmp2.Flip((l & 4) == 4, false);
                     flippedtiles[l].Add(bmp2);
                 }
             }
             tileList1.SelectedIndex = 0;
             tileList1.ChangeSize();
             tileList1.Invalidate();
             DrawLevel();
         }
     }
 }