Exemplo n.º 1
0
        public void LoadLevel()
        {
            List <FloatShape> Bodies    = new List <FloatShape>();
            XDocument         Doc       = XDocument.Load(@"Content\Levels\Level1.xml");
            XElement          SizeElem  = Doc.Root.Element("FloatSize");
            FloatSize         WorldSize = Loader.DeserializeObject(SizeElem.ToString(), typeof(FloatSize)) as FloatSize;

            width  = WorldSize.X;
            height = WorldSize.Y;

            foreach (XElement Elem in Doc.Root.Elements())
            {
                if (Elem.Name == "FloatRect")
                {
                    Bodies.Add(Loader.DeserializeObject(Elem.ToString(), typeof(FloatRect)) as FloatRect);
                }
                else
                if (Elem.Name == "FloatCircle")
                {
                    Bodies.Add(Loader.DeserializeObject(Elem.ToString(), typeof(FloatCircle)) as FloatCircle);
                }
                else
                if (Elem.Name == "FloatPolygon")
                {
                    Bodies.Add(Loader.DeserializeObject(Elem.ToString(), typeof(FloatPolygon)) as FloatPolygon);
                }
                else
                if (Elem.Name == "FloatLine")
                {
                    Bodies.Add(Loader.DeserializeObject(Elem.ToString(), typeof(FloatLine)) as FloatLine);
                }
            }

            foreach (FloatRect Rect in Bodies)
            {
                units.Add(Rect.Name, new Wall(this,
                                              new Vector2(Rect.Left + Rect.Width / 2,
                                                          Rect.Top + Rect.Height / 2),
                                              new Vector2(Rect.Width, Rect.Height),
                                              content.Load <Texture2D>("Textures/Box"), null, camera));
            }
        }
Exemplo n.º 2
0
 private void MakeFloat(bool isNegative, bool negativeExponent, ulong integerPart, ulong fractionalPart, int fractionalPartLength, ulong exponent)
 {
     DoubleValue  = (double)((!isNegative) ? 1 : (-1)) * ((double)integerPart + (double)fractionalPart / Math.Pow(10.0, fractionalPartLength)) * Math.Pow(10.0, (long)((!negativeExponent) ? 1 : (-1)) * (long)exponent);
     MinFloat     = FloatSize.Double;
     IsFractional = true;
     if (DoubleValue < 0.0)
     {
         IsNegative = true;
         if (DoubleValue >= -3.4028234663852886E+38)
         {
             FloatValue = (float)DoubleValue;
             MinFloat   = FloatSize.Single;
         }
     }
     else if (DoubleValue <= 3.4028234663852886E+38)
     {
         FloatValue = (float)DoubleValue;
         MinFloat   = FloatSize.Single;
     }
 }
Exemplo n.º 3
0
        private void MakeFloat(bool isNegative, bool negativeExponent, ulong integerPart, ulong fractionalPart, int fractionalPartLength, ulong exponent)
        {
            DoubleValue  = (isNegative ? -1 : 1) * ((double)integerPart + (double)fractionalPart / Math.Pow(10, fractionalPartLength)) * Math.Pow(10, (negativeExponent ? -1 : 1) * (long)exponent);
            MinFloat     = FloatSize.Double;
            IsFractional = true;

            if (DoubleValue < 0)
            {
                IsNegative = true;

                if (DoubleValue >= -Single.MaxValue)
                {
                    FloatValue = (float)DoubleValue;
                    MinFloat   = FloatSize.Single;
                }
            }
            else if (DoubleValue <= Single.MaxValue)
            {
                FloatValue = (float)DoubleValue;
                MinFloat   = FloatSize.Single;
            }
        }
Exemplo n.º 4
0
        void SerializeWorld(string XMLFile)
        {
            XmlWriterSettings Settings = new XmlWriterSettings();

            Settings.Indent      = true;
            Settings.IndentChars = "    ";
            XmlWriter Writer = XmlWriter.Create(XMLFile, Settings);

            Writer.WriteStartDocument();
            Writer.WriteStartElement("Bodies");
            Writer.WriteRaw(Environment.NewLine);

            Bodies.ForEach(Body => { Body.Normalize((float)(udRealWidth.Value / udWidth.Value), (float)(udRealHeight.Value / udHeight.Value));
                                     SerializeObject(Writer, Body); });
            FloatSize S = new FloatSize(udRealWidth.Value, udRealHeight.Value);

            SerializeObject(Writer, S);

            Writer.WriteEndElement();
            Writer.WriteEndDocument();
            Writer.Close();
        }
Exemplo n.º 5
0
        private void MakeInteger(bool isNegative, ulong integerPart)
        {
            IsNegative = isNegative;

            if (!IsNegative)
            {
                ULongValue = integerPart;
                MinInteger = IntegerSize.UInt64;

                if (ULongValue <= Int64.MaxValue)
                {
                    LongValue  = (long)ULongValue;
                    MinInteger = IntegerSize.Int64;
                }

                if (ULongValue <= UInt32.MaxValue)
                {
                    UIntValue  = (uint)ULongValue;
                    MinInteger = IntegerSize.UInt32;
                }

                if (ULongValue <= Int32.MaxValue)
                {
                    IntValue   = (int)ULongValue;
                    MinInteger = IntegerSize.Int32;
                }

                if (ULongValue <= UInt16.MaxValue)
                {
                    UShortValue = (ushort)ULongValue;
                    MinInteger  = IntegerSize.UInt16;
                }

                if (ULongValue <= (ulong)Int16.MaxValue)
                {
                    ShortValue = (short)ULongValue;
                    MinInteger = IntegerSize.Int16;
                }

                if (ULongValue <= Byte.MaxValue)
                {
                    ByteValue  = (byte)ULongValue;
                    MinInteger = IntegerSize.UInt8;
                }

                if (ULongValue <= (ulong)SByte.MaxValue)
                {
                    SByteValue = (sbyte)ULongValue;
                    MinInteger = IntegerSize.Int8;
                }

                DoubleValue = ULongValue;
                MinFloat    = FloatSize.Double;

                if (DoubleValue <= Single.MaxValue)
                {
                    FloatValue = (float)DoubleValue;
                    MinFloat   = FloatSize.Single;
                }
            }
            else
            {
                LongValue  = -(long)integerPart;
                MinInteger = IntegerSize.Int64;

                if (LongValue >= Int32.MinValue)
                {
                    IntValue   = (int)LongValue;
                    MinInteger = IntegerSize.Int32;
                }

                if (LongValue >= Int16.MinValue)
                {
                    ShortValue = (short)LongValue;
                    MinInteger = IntegerSize.Int16;
                }

                if (LongValue >= SByte.MinValue)
                {
                    SByteValue = (sbyte)LongValue;
                    MinInteger = IntegerSize.Int8;
                }

                DoubleValue = LongValue;
                MinFloat    = FloatSize.Double;

                if (DoubleValue >= -Single.MaxValue)
                {
                    FloatValue = (float)DoubleValue;
                    MinFloat   = FloatSize.Single;
                }
            }
        }
Exemplo n.º 6
0
        private void MakeFloat(bool isNegative, bool negativeExponent, ulong integerPart, ulong fractionalPart, int fractionalPartLength, ulong exponent) {
            DoubleValue = (isNegative ? -1 : 1) * ((double)integerPart + (double)fractionalPart / Math.Pow(10, fractionalPartLength)) * Math.Pow(10, (negativeExponent ? -1 : 1) * (long)exponent);
            MinFloat = FloatSize.Double;
            IsFractional = true;

            if (DoubleValue < 0) {
                IsNegative = true;

                if (DoubleValue >= -Single.MaxValue) {
                    FloatValue = (float)DoubleValue;
                    MinFloat = FloatSize.Single;
                }
            } else if (DoubleValue <= Single.MaxValue) {
                FloatValue = (float)DoubleValue;
                MinFloat = FloatSize.Single;
            }
        }
Exemplo n.º 7
0
        private void MakeInteger(bool isNegative, ulong integerPart) {
            IsNegative = isNegative;

            if (!IsNegative) {
                ULongValue = integerPart;
                MinInteger = IntegerSize.UInt64;

                if (ULongValue <= Int64.MaxValue) {
                    LongValue = (long)ULongValue;
                    MinInteger = IntegerSize.Int64;
                }

                if (ULongValue <= UInt32.MaxValue) {
                    UIntValue = (uint)ULongValue;
                    MinInteger = IntegerSize.UInt32;
                }

                if (ULongValue <= Int32.MaxValue) {
                    IntValue = (int)ULongValue;
                    MinInteger = IntegerSize.Int32;
                }

                if (ULongValue <= UInt16.MaxValue) {
                    UShortValue = (ushort)ULongValue;
                    MinInteger = IntegerSize.UInt16;
                }

                if (ULongValue <= (ulong)Int16.MaxValue) {
                    ShortValue = (short)ULongValue;
                    MinInteger = IntegerSize.Int16;
                }

                if (ULongValue <= Byte.MaxValue) {
                    ByteValue = (byte)ULongValue;
                    MinInteger = IntegerSize.UInt8;
                }

                if (ULongValue <= (ulong)SByte.MaxValue) {
                    SByteValue = (sbyte)ULongValue;
                    MinInteger = IntegerSize.Int8;
                }

                DoubleValue = ULongValue;
                MinFloat = FloatSize.Double;

                if (DoubleValue <= Single.MaxValue) {
                    FloatValue = (float)DoubleValue;
                    MinFloat = FloatSize.Single;
                }
            } else {
                LongValue = -(long)integerPart;
                MinInteger = IntegerSize.Int64;

                if (LongValue >= Int32.MinValue) {
                    IntValue = (int)LongValue;
                    MinInteger = IntegerSize.Int32;
                }

                if (LongValue >= Int16.MinValue) {
                    ShortValue = (short)LongValue;
                    MinInteger = IntegerSize.Int16;
                }

                if (LongValue >= SByte.MinValue) {
                    SByteValue = (sbyte)LongValue;
                    MinInteger = IntegerSize.Int8;
                }

                DoubleValue = LongValue;
                MinFloat = FloatSize.Double;

                if (DoubleValue >= -Single.MaxValue) {
                    FloatValue = (float)DoubleValue;
                    MinFloat = FloatSize.Single;
                }
            }
        }
Exemplo n.º 8
0
 private void MakeInteger(bool isNegative, ulong integerPart)
 {
     IsNegative = isNegative;
     if (!IsNegative)
     {
         ULongValue = integerPart;
         MinInteger = IntegerSize.UInt64;
         if (ULongValue <= long.MaxValue)
         {
             LongValue  = (long)ULongValue;
             MinInteger = IntegerSize.Int64;
         }
         if (ULongValue <= uint.MaxValue)
         {
             UIntValue  = (uint)ULongValue;
             MinInteger = IntegerSize.UInt32;
         }
         if (ULongValue <= int.MaxValue)
         {
             IntValue   = (int)ULongValue;
             MinInteger = IntegerSize.Int32;
         }
         if (ULongValue <= 65535)
         {
             UShortValue = (ushort)ULongValue;
             MinInteger  = IntegerSize.UInt16;
         }
         if (ULongValue <= 32767)
         {
             ShortValue = (short)ULongValue;
             MinInteger = IntegerSize.Int16;
         }
         if (ULongValue <= 255)
         {
             ByteValue  = (byte)ULongValue;
             MinInteger = IntegerSize.UInt8;
         }
         if (ULongValue <= 127)
         {
             SByteValue = (sbyte)ULongValue;
             MinInteger = IntegerSize.Int8;
         }
         DoubleValue = ULongValue;
         MinFloat    = FloatSize.Double;
         if (DoubleValue <= 3.4028234663852886E+38)
         {
             FloatValue = (float)DoubleValue;
             MinFloat   = FloatSize.Single;
         }
     }
     else
     {
         LongValue  = (long)(0L - integerPart);
         MinInteger = IntegerSize.Int64;
         if (LongValue >= int.MinValue)
         {
             IntValue   = (int)LongValue;
             MinInteger = IntegerSize.Int32;
         }
         if (LongValue >= -32768)
         {
             ShortValue = (short)LongValue;
             MinInteger = IntegerSize.Int16;
         }
         if (LongValue >= -128)
         {
             SByteValue = (sbyte)LongValue;
             MinInteger = IntegerSize.Int8;
         }
         DoubleValue = LongValue;
         MinFloat    = FloatSize.Double;
         if (DoubleValue >= -3.4028234663852886E+38)
         {
             FloatValue = (float)DoubleValue;
             MinFloat   = FloatSize.Single;
         }
     }
 }