Ejemplo n.º 1
0
        public void Write(Writer writer)
        {
            writer.Write(Unknown);
            writer.Write(PlayerType);

            writer.Write((byte)Animations.Count);

            byte SheetCnt = (byte)SpriteSheets.Length;

            for (int i = 0; i < SpriteSheets.Length; ++i)
            {
                writer.WriteRSDKString(SpriteSheets[i]);
            }

            for (int i = 0; i < Animations.Count; ++i)
            {
                Animations[i].Write(writer);
            }
            writer.Close();
        }
Ejemplo n.º 2
0
        internal void Write(Writer writer)
        {
            //Checks To make sure that the file can be saved correctly

            int num_of_objects = objects.Count;

            if (num_of_objects > MaxObjectCount)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Number of objects above 1100!");
            }

            // Save zone name
            writer.WriteRSDKString(Title);

            // Write the Stage Init Data
            writer.Write(Music);
            writer.Write(Background);
            writer.Write((byte)(PlayerXpos >> 8));
            writer.Write((byte)(PlayerXpos & 0xFF));
            writer.Write((byte)(PlayerYPos >> 8));
            writer.Write((byte)(PlayerYPos & 0xFF));

            // Write number of objects
            writer.Write((byte)(num_of_objects >> 8));
            writer.Write((byte)(num_of_objects & 0xFF));

            objects = objects.OrderBy(o => o.id).ToList();

            // Write object data
            for (int n = 0; n < num_of_objects; n++)
            {
                Object obj = objects[n];

                obj.Write(writer);
            }
            writer.Close();
        }
Ejemplo n.º 3
0
        internal void Write(Writer writer)
        {
            writer.Write((byte)Layers.Count);
            writer.Write((byte)HLines.Count);

            for (int lc = 0; lc < HLines.Count; lc++)
            {
                HLines[lc].Write(writer);
            }

            writer.Write((byte)VLines.Count);

            for (int lc = 0; lc < VLines.Count; lc++)
            {
                VLines[lc].Write(writer);
            }

            for (int i = 0; i < Layers.Count; i++) //Read BG Layers
            {
                Layers[i].Write(writer);
            }

            writer.Close();
        }
Ejemplo n.º 4
0
        public void Write(Writer writer, bool dcGFX = false, bool raw = false)
        {
            if (gfxImage == null)
            {
                throw new Exception("Image is NULL");
            }

            if (gfxImage.Palette == null || gfxImage.Palette.Entries.Length == 0)
            {
                throw new Exception("Only indexed images can be converted to GFX format.");
            }

            if (gfxImage.Width > 65535)
            {
                throw new Exception("GFX Images can't be wider than 65535 pixels");
            }

            if (gfxImage.Height > 65535)
            {
                throw new Exception("GFX Images can't be higher than 65535 pixels");
            }

            int num_pixels = gfxImage.Width * gfxImage.Height;

            int[] pixels = new int[num_pixels]; //Pallete Indexes

            // Images can't contain index 255
            for (int x = 0; x < num_pixels; x++)
            {
                if (pixels[x] == 255)
                {
                    throw new Exception("Images to be converted to GFX format can't contain index 255.");
                }
            }

            int pix = 0;

            if (raw) //get data from "data" array
            {
                for (int h = 0; h < height; h++)
                {
                    for (int w = 0; w < width; w++)
                    {
                        pixels[pix] = data[pix];
                        pix++;
                    }
                }
            }
            else //Get Data from Bitmap Class
            {
                for (int h = 0; h < gfxImage.Height; h++)
                {
                    for (int w = 0; w < gfxImage.Width; w++)
                    {
                        pixels[pix++] = Get8bppImagePixel(gfxImage, new Point(w, h));
                    }
                }
            }

            if (dcGFX)
            {
                byte z = 0;
                writer.Write(z);
            }

            // Output width and height
            writer.Write((byte)(gfxImage.Width >> 8));
            writer.Write((byte)(gfxImage.Width & 0xff));

            writer.Write((byte)(gfxImage.Height >> 8));
            writer.Write((byte)(gfxImage.Height & 0xff));

            for (int i = 0; i < gfxImage.Palette.Entries.Length; i++)
            {
                GFXpal[i].R = gfxImage.Palette.Entries[i].R;
                GFXpal[i].G = gfxImage.Palette.Entries[i].G;
                GFXpal[i].B = gfxImage.Palette.Entries[i].B;
            }

            // Output palette
            for (int x = 0; x < 255; x++)
            {
                writer.Write(GFXpal[x].R);
                writer.Write(GFXpal[x].G);
                writer.Write(GFXpal[x].B);
            }

            // Output data
            int p   = 0;
            int cnt = 0;

            for (int x = 0; x < num_pixels; x++)
            {
                if (pixels[x] != p && x > 0)
                {
                    rle_write(writer, p, cnt, dcGFX);
                    cnt = 0;
                }
                p = pixels[x];
                cnt++;
            }

            rle_write(writer, p, cnt, dcGFX);

            // End of GFX file
            writer.Write((byte)0xFF);
            writer.Write((byte)0xFF);

            writer.Close();
        }
Ejemplo n.º 5
0
        internal void Write(Writer writer)
        {
            //Checks To make sure that the file can be saved correctly

            if (width >= 256)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Level width in tiles > 255.");
            }

            if (height >= 256)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Level height in tiles > 255.");
            }

            int num_of_objects = objects.Count;

            if (num_of_objects > MaxObjectCount)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Number of objects above 1100!");
            }

            // Separate path components
            String dirname  = Path.GetDirectoryName(writer.GetFilename());
            String basename = "\\" + Path.GetFileNameWithoutExtension(writer.GetFilename());

            String itmPath = dirname + basename + ".itm";

            // Create item file
            Writer ITMwriter = new Writer(itmPath);

            // Save width and height
            writer.Write((byte)width);
            writer.Write((byte)height);

            // Save map data
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    writer.Write((byte)MapLayout[y][x]);
                }
            }

            // Close map file
            writer.Close();

            // Save zone name
            ITMwriter.WriteRSDKString(Title);

            // Write the Stage Init Data
            ITMwriter.Write(Music);
            ITMwriter.Write(Background);
            ITMwriter.Write((byte)(PlayerXpos >> 8));
            ITMwriter.Write((byte)(PlayerXpos & 0xFF));
            ITMwriter.Write((byte)(PlayerYPos >> 8));
            ITMwriter.Write((byte)(PlayerYPos & 0xFF));

            // Write number of objects
            ITMwriter.Write((byte)(num_of_objects >> 8));
            ITMwriter.Write((byte)(num_of_objects & 0xFF));

            // Write object data
            for (int n = 0; n < num_of_objects; n++)
            {
                Object obj = objects[n];

                obj.Write(ITMwriter);
            }
            ITMwriter.Close();
        }