예제 #1
0
파일: World.cs 프로젝트: EdgeKiller/Crafty
        /// <summary>
        /// Load all information
        /// </summary>
        public static void Load(string worldName)
        {
            // Load all tiles
            byte[] buffer;
            try
            {
                buffer = File.ReadAllBytes("world/" + worldName + "/" + worldName + ".cw");
            }
            catch(Exception ex)
            {
                throw ex;
            }
            for (int y = 0; y < Tiles.GetLength(1); y++)
            {
                using (MemoryStream ms = new MemoryStream(buffer))
                {
                    using (BinaryReader br = new BinaryReader(ms))
                    {
                        for (int x = 0; x < Tiles.GetLength(0); x++)
                        {
                            Tiles[x, y] = new Tile(br.ReadInt32(), new Point(x, y));
                        }
                    }
                }
            }

            // Init variables
            Camera.SetPosition(0, 0);
        }
예제 #2
0
파일: World.cs 프로젝트: EdgeKiller/Crafty
        /// <summary>
        /// Generate a random map with perlin noise
        /// </summary>
        /// <param name="worldName">World's name</param>
        /// <param name="seed">Seed</param>
        private static void Generate(string worldName, int seed)
        {
            for (int x = 0; x < Tiles.GetLength(0); x++)
            {
                for (int y = 0; y < Tiles.GetLength(1); y++)
                {
                    Tiles[x, y] = new Tile(0, new Point(x,y));
                }
            }

            Tiles[0, 10] = new Tile(2, new Point(0, 10));
            Tiles[1, 10] = new Tile(1, new Point(1,10));
            Tiles[3, 15] = new Tile(2, new Point(3, 15));

            Save(worldName);
        }