示例#1
0
 private Level(Polygon startPolygon, Vector startPosition, Vector exitPosition)
 {
     Polygons.Add(startPolygon);
     Objects.Add(LevObject.StartObject(startPosition));
     Objects.Add(LevObject.ExitObject(exitPosition));
     UpdateBounds();
 }
示例#2
0
 private LevObject(LevObject o)
 {
     AnimationNumber = o.AnimationNumber;
     AppleType       = o.AppleType;
     Position        = o.Position.Clone();
     Type            = o.Type;
 }
示例#3
0
        private void LoadFromBytes(byte[] level)
        {
            Size          = level.Length;
            LevStartMagic = Encoding.UTF8.GetString(level, 0, 5);
            if (!IsElmaLevel && !IsAcrossLevel && !IsLeb)
            {
                throw new LevelException(
                          "Unknown file type. This is neither an Elma level, an Across level nor a LEB file.");
            }

            var sp = 7;

            if (IsAcrossLevel)
            {
                sp -= 2;
            }
            Identifier = BitConverter.ToInt32(level, sp);
            sp        += 4;
            for (var i = 0; i <= 3; i++)
            {
                Integrity[i] = BitConverter.ToDouble(level, sp);
                sp          += 8;
            }

            Title = Utils.ReadNullTerminatedString(level, sp, 60);
            if (IsAcrossLevel)
            {
                sp = 100;
            }
            else
            {
                sp                = 94;
                LgrFile           = Utils.ReadNullTerminatedString(level, sp, 16);
                sp               += 16;
                GroundTextureName = Utils.ReadNullTerminatedString(level, sp, 12).ToLower();
                sp               += 10;
                SkyTextureName    = Utils.ReadNullTerminatedString(level, sp, 12).ToLower();
                sp               += 10;
            }

            var polygonCount = (int)Math.Round(BitConverter.ToDouble(level, sp) - MagicDouble);

            sp += 8;
            var objectCount = -1;

            if (IsLeb)
            {
                objectCount = (int)Math.Round(BitConverter.ToDouble(level, sp) - MagicDouble);
                sp         += 8;
            }

            var isGrassPolygon = false;

            Polygons = new List <Polygon>();
            for (var i = 0; i < polygonCount; i++)
            {
                int numVertice;
                if (IsAcrossLevel)
                {
                    numVertice = level[sp] + 256 * level[sp + 1];
                    sp        += 4;
                }
                else
                {
                    numVertice     = level[sp + 4] + 256 * level[sp + 5];
                    sp            += 8;
                    isGrassPolygon = level[sp - 8] == 1;
                }

                var poly = new Polygon();
                for (var j = 0; j < numVertice; j++)
                {
                    var x = BitConverter.ToDouble(level, sp);
                    var y = BitConverter.ToDouble(level, sp + 8);
                    poly.Add(new Vector(x, y));
                    sp += 16;
                }

                poly.IsGrass = isGrassPolygon;
                Polygons.Add(poly);
            }

            if (!IsLeb)
            {
                objectCount = (int)Math.Round(BitConverter.ToDouble(level, sp) - MagicDouble);
                sp         += 8;
            }

            Apples = new List <LevObject>();
            var startFound = false;

            for (var i = 0; i < objectCount; i++)
            {
                var x          = BitConverter.ToDouble(level, sp);
                var y          = BitConverter.ToDouble(level, sp + 8);
                var objectType = (ObjectType)(level[sp + 16]);
                if (objectType == ObjectType.Start)
                {
                    startFound = true;
                }

                var appleType = AppleType.Normal;
                var animNum   = 0;
                if (!IsAcrossLevel)
                {
                    appleType = (AppleType)(BitConverter.ToInt32(level, sp + 20));
                    animNum   = BitConverter.ToInt32(level, sp + 24);
                    sp       += 28;
                }
                else
                {
                    sp += 20;
                }

                var objectToAdd = new LevObject(new Vector(x, y), objectType, appleType, animNum + 1);
                Objects.Add(objectToAdd);
                if (objectType == ObjectType.Apple)
                {
                    Apples.Add(objectToAdd);
                }
            }

            if (!startFound)
            {
                Objects.Add(new LevObject(new Vector(0, 0), ObjectType.Start, AppleType.Normal));
            }

            if (!IsAcrossLevel)
            {
                var numberOfPicturesPlusTextures = (int)Math.Round(BitConverter.ToDouble(level, sp) - MagicDouble2);
                sp += 8;
                for (var i = 0; i < numberOfPicturesPlusTextures; i++)
                {
                    if (level[sp] == 0)
                    {
                        _textureData.Add(new LevelFileTexture(Utils.ReadNullTerminatedString(level, sp + 10, 10),
                                                              Utils.ReadNullTerminatedString(level, sp + 20, 10),
                                                              new Vector(BitConverter.ToDouble(level, sp + 30),
                                                                         BitConverter.ToDouble(level, sp + 38)),
                                                              BitConverter.ToInt32(level, sp + 46),
                                                              ((ClippingType)(BitConverter.ToInt32(level, sp + 50)))));
                    }
                    else
                    {
                        _textureData.Add(new LevelFileTexture(Utils.ReadNullTerminatedString(level, sp, 10), null,
                                                              new Vector(BitConverter.ToDouble(level, sp + 30),
                                                                         BitConverter.ToDouble(level, sp + 38)),
                                                              BitConverter.ToInt32(level, sp + 46),
                                                              ((ClippingType)(BitConverter.ToInt32(level, sp + 50)))));
                    }
                    sp += 54;
                }
            }

            if (sp != level.Length)
            {
                sp += 4; //Skip end of data magic number
                CryptTop10(level, sp);
                try
                {
                    Top10.SinglePlayer = ReadTop10Part(level, sp, (a, b, t) => new Top10EntrySingle(a, b, t));
                    Top10.MultiPlayer  = ReadTop10Part(level, sp + 344, (a, b, t) => new Top10EntryMulti(a, b, t));
                }
                catch (IndexOutOfRangeException)
                {
                    throw new LevelException(
                              "Top 10 list is corrupted. The list will be cleared if you save the level.");
                }
            }

            UpdateBounds();
        }
示例#4
0
        private void LoadFromStream(Stream data)
        {
            var lev = new BinaryReader(data, Encoding.ASCII);

            LevStartMagic = lev.ReadString(5);
            if (!IsElmaLevel && !IsAcrossLevel && !IsLeb)
            {
                throw new BadFileException(
                          "Unknown file type. This is neither an Elma level, an Across level nor a LEB file.");
            }

            if (!IsAcrossLevel)
            {
                lev.ReadInt16();
            }

            Identifier = lev.ReadInt32();
            for (var i = 0; i < 4; i++)
            {
                Integrity[i] = lev.ReadDouble();
            }

            Title = lev.ReadNullTerminatedString(IsAcrossLevel ? 59 : 51);
            if (!IsAcrossLevel)
            {
                LgrFile           = lev.ReadNullTerminatedString(16);
                GroundTextureName = lev.ReadNullTerminatedString(10).ToLower();
                SkyTextureName    = lev.ReadNullTerminatedString(10).ToLower();
            }

            var polygonCount = (int)Math.Round(lev.ReadDouble() - MagicDouble);
            var objectCount  = -1;

            if (IsLeb)
            {
                objectCount = (int)Math.Round(lev.ReadDouble() - MagicDouble);
            }

            Polygons = new List <Polygon>();
            for (var i = 0; i < polygonCount; i++)
            {
                var isGrassPolygon = false;
                if (!IsAcrossLevel)
                {
                    isGrassPolygon = lev.ReadInt32() == 1;
                }

                var numVertice = lev.ReadInt32();
                var poly       = new Polygon();
                for (var j = 0; j < numVertice; j++)
                {
                    var x = lev.ReadDouble();
                    var y = lev.ReadDouble();
                    poly.Add(new Vector(x, y));
                }

                poly.IsGrass = isGrassPolygon;
                Polygons.Add(poly);
            }

            if (!IsLeb)
            {
                objectCount = (int)Math.Round(lev.ReadDouble() - MagicDouble);
            }

            var startFound = false;

            for (var i = 0; i < objectCount; i++)
            {
                var x          = lev.ReadDouble();
                var y          = lev.ReadDouble();
                var objectType = (ObjectType)lev.ReadInt32();
                if (objectType == ObjectType.Start)
                {
                    startFound = true;
                }

                var appleType = AppleType.Normal;
                var animNum   = 0;
                if (!IsAcrossLevel)
                {
                    appleType = (AppleType)lev.ReadInt32();
                    animNum   = lev.ReadInt32();
                }

                var objectToAdd = new LevObject(new Vector(x, y), objectType, appleType, animNum + 1);
                Objects.Add(objectToAdd);
            }

            if (!startFound)
            {
                Objects.Add(new LevObject(new Vector(0, 0), ObjectType.Start, AppleType.Normal));
            }

            if (!IsAcrossLevel)
            {
                var numberOfPicturesPlusTextures = (int)Math.Round(lev.ReadDouble() - MagicDouble2);
                for (var i = 0; i < numberOfPicturesPlusTextures; i++)
                {
                    var pictureName = lev.ReadNullTerminatedString(10);
                    var textureName = lev.ReadNullTerminatedString(10);
                    var maskName    = lev.ReadNullTerminatedString(10);
                    var x           = lev.ReadDouble();
                    var y           = lev.ReadDouble();
                    var distance    = lev.ReadInt32();
                    var clipping    = (ClippingType)lev.ReadInt32();
                    if (pictureName == "")
                    {
                        _textureData.Add(new LevelFileTexture(textureName,
                                                              maskName, new Vector(x, y),
                                                              distance,
                                                              clipping));
                    }
                    else
                    {
                        _textureData.Add(new LevelFileTexture(pictureName,
                                                              null, new Vector(x, y),
                                                              distance,
                                                              clipping));
                    }
                }
            }

            HandleLevEndRead(lev);
            UpdateBounds();
        }