Exemplo n.º 1
0
        //todo add type
        void Create(ushort inx, ushort iny, ushort inz)
        {
            sizeX = inx;
            sizeY = iny;
            sizeZ = inz;

            spawnPos = new pos { x = (ushort)((sizeX * 32) / 2), y = (ushort)(((sizeY * 32) / 2) + 64), z = (ushort)((sizeZ * 32) / 2), pitch = 0, yaw = 0 };

            blocks = new byte[sizeX * sizeY * sizeZ];

            ushort half = (ushort)(sizeY / 2);
            for (ushort x = 0; x < sizeX; ++x)
            {
                for (ushort z = 0; z < sizeZ; ++z)
                {
                    for (ushort y = 0; y < sizeY; ++y)
                    {
                        if (y != half)
                        {
                            SetTile(x, y, z, (byte)((y >= half) ? Blocks.Air : Blocks.Dirt));
                        }
                        else
                        {
                            SetTile(x, y, z, (byte)Blocks.Grass);
                        }
                    }
                }
            }

            physics = new PhysicsHandler(this, true);

            LevelHandler.levels.Add(this);
        }
Exemplo n.º 2
0
        void Load(string _name)
        {
            string tempPath = levelFolder + "/" + _name + compressedExtension;
            if (!File.Exists(tempPath)) throw new FileNotFoundException("Could not find file!", tempPath);

            FileStream fileStream = new FileStream(tempPath, FileMode.Open);
            GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);

            byte[] header = new byte[headerSize];
            gzipStream.Read(header, 0, headerSize);
            name = encode.GetString(header, 0, 64).Trim();
            sizeX = BitConverter.ToUInt16(header, 64);
            sizeY = BitConverter.ToUInt16(header, 66);
            sizeZ = BitConverter.ToUInt16(header, 68);
            spawnPos = new pos();
            spawnPos.x = BitConverter.ToUInt16(header, 70);
            spawnPos.y = BitConverter.ToUInt16(header, 72);
            spawnPos.z = BitConverter.ToUInt16(header, 74);
            spawnPos.pitch = header[76];
            spawnPos.pitch = header[77];

            bool physics = BitConverter.ToBoolean(header, 78);
            bool realistic = BitConverter.ToBoolean(header, 78);

            this.physics = new PhysicsHandler(this, physics);
            this.physics.realistic = realistic;

            int blockCount = sizeX * sizeY * sizeZ;
            blocks = new byte[blockCount];
            gzipStream.Read(blocks, 0, blockCount);

            gzipStream.Close();
            fileStream.Close();

            LevelHandler.levels.Add(this);
        }
Exemplo n.º 3
0
        internal void Unload()
        {
            LevelHandler.levels.Remove(this);

            foreach (Player p in PlayerHandler.Players.Values.ToArray())
            {
                if (p.oldLevel == this) p.oldLevel = null;
                if (p.level == this) p.SwitchMap(LevelHandler.lobby);
            }

            foreach (Player pl in players.ToArray())
            {
                try
                {
                    pl.SendKick("Internal Error (level has been unloaded)");
                }
                catch { }
            }

            FullSave();

            physics.shouldStop = true;
            physics = null;

            blocks = new byte[0];
        }