Ejemplo n.º 1
0
        public void writeWorld(WorldBase world, String name)
        {
            for (int kx = -world.tileGenRadious; kx <= world.tileGenRadious; kx++)
            {
                for (int ky = -world.tileGenRadious; ky <= world.tileGenRadious; ky++)
                {
                    Directory.CreateDirectory(name + "\\");
                    using (BinaryWriter writer = new BinaryWriter(File.Open(name + "\\" + kx + "-" + ky + ".cnk", FileMode.Create)))
                    {
                        for (int x = 0; x <= Chunk.tilesPerChunk; x++)
                        {
                            for (int y = 0; y <= Chunk.tilesPerChunk; y++)
                            {
                                TileType type = world.getBlock(new Point(Chunk.tilesPerChunk * kx + x, Chunk.tilesPerChunk * ky + y));
                                if (type != null)
                                {
                                    writer.Write(type.TILEID);
                                }
                                else
                                {
                                    writer.Write(-1);
                                }
                            }
                        }

                        for (int x = 0; x <= Chunk.tilesPerChunk; x++)
                        {
                            for (int y = 0; y <= Chunk.tilesPerChunk; y++)
                            {
                                TileType type = world.getBackgroundBlock(new Point(Chunk.tilesPerChunk * kx + x, Chunk.tilesPerChunk * ky + y));
                                if (type != null)
                                {
                                    writer.Write(type.TILEID);
                                }
                                else
                                {
                                    writer.Write(-1);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void writeDecoration(WorldBase world, Point lowerLeft, Point origin, Point topRight, String name)
        {
            using (BinaryWriter writer = new BinaryWriter(File.Open(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Saved Games/MapData", name), FileMode.Create)))
            {
                writer.Write(topRight.X - lowerLeft.X + 1); //write decoration width
                writer.Write(lowerLeft.Y - topRight.Y + 1); //write decoration height
                writer.Write(origin.X - lowerLeft.X);       //write decoration offset x
                writer.Write(topRight.Y - origin.Y);        //write decoration offset y

                int numWrites = 4;
                for (int x = lowerLeft.X; x <= topRight.X; x++)
                {
                    for (int y = topRight.Y; y <= lowerLeft.Y; y++)
                    {
                        if (world.getBlock(new Point(x, y)) == TileTypeReferencer.AIR)
                        {
                            writer.Write(-1);
                        }
                        else
                        {
                            writer.Write(world.getBlock(new Point(x, y)).TILEID);
                        }
                        numWrites++;
                    }
                }

                for (int x = lowerLeft.X; x <= topRight.X; x++)
                {
                    for (int y = topRight.Y; y <= lowerLeft.Y; y++)
                    {
                        TileType type = world.getBackgroundBlock(new Point(x, y));
                        if (type == null)
                        {
                            writer.Write(-1);
                        }
                        else
                        {
                            writer.Write(type.TILEID);
                        }
                        numWrites++;
                    }
                }
            }
        }