示例#1
0
 public PengObjectExample(string name, PengWorld world, int test1, float test2, string test3)
     : base(name, world)
 {
     Test1 = test1;
     Test2 = test2;
     Test3 = test3;
 }
        public virtual void Load(PengWorld world, XElement xWorld)
        {
            Contract.Requires(world != null);
            Contract.Requires(xWorld != null);

            foreach (XElement xObj in xWorld.XPathSelectElements(TA.XPathObjects))
            {
                List<ObjectArgumentInfo> args = new List<ObjectArgumentInfo>();
                args.Add(new ObjectArgumentInfo(typeof(string), xObj.Attribute(TA.ObjectID).Value));
                Type objectType;
                if (xObj.Attribute(TA.ObjectType) != null)
                {
                    objectType = Type.GetType(xObj.Attribute(TA.ObjectType).Value);
                    foreach (XElement xArg in xWorld.XPathSelectElements(TA.XPathObjectArgs))
                    {
                        if (xArg.Attribute(TA.ArgumentType) != null)
                            args.Add(GetObjectArgFromXml(xArg));
                    }
                }
                else
                    objectType = typeof(PengObject);

                var ctor = objectType.GetConstructor(args.ConvertAll(x => x.Type).ToArray());
                PengObject obj = (PengObject)ctor.Invoke(args.ConvertAll(x => x.Value).ToArray());
                obj.LoadFromXml(xObj);
            }
        }
示例#3
0
文件: Ball.cs 项目: fiftin/Pengball
        public Ball(string name, PengWorld world, Vector2 leftStartPos, Vector2 rightStartPos, float radius, PlayerSide side)
            : base(name, world)
        {
            this.radius = radius;
            LeftStartPos = leftStartPos;
            RightStartPos = rightStartPos;
            InitialSide = side;

            Inititalize();
        }
示例#4
0
文件: Player.cs 项目: fiftin/Pengball
 public Player(string id, PengWorld world, PlayerSide side, Vector2 startPosition)
     : base(id, world)
 {
     Side = side;
     StartPosition = startPosition;
     JumpImpulse = DefaultJumpImpulse;
     Velocity = DefaultVelocity;
     ListenContacts = true;
     Initialize();
 }
示例#5
0
 public ComputerPlayer(string id, PengWorld world, PlayerSide side, Vector2 startPosition)
     : base(id, world, side, startPosition)
 {
     string screenplay = ((PengballWorld)world).Screenplay;
     screenplay = screenplay.Replace("ComputerPlayer", "Player");
     parallelWorld = new PengballWorld(null, world.Content, false, screenplay, false);
     parallelWorld.Tag = "parallelWorld";
     ((PengballWorld)world).Loaded += new EventHandler(world_Loaded);
     TargetPositionOffset = 0.07f;
     TargetPositionRandomOffset = 0.05f;
 }
示例#6
0
        private ObjectArg[] GetObjectArgs(PengObjectInfo objInfo, PengWorld world, Func<string, Type> typeProvider)
        {
            ObjectArg[] ret = new ObjectArg[objInfo.Arguments.Length + 2];
            ret[0] = new ObjectArg(typeof(string), objInfo.Name);
            ret[1] = new ObjectArg(typeof(PengWorld), world);
            for (int i = 0; i < objInfo.Arguments.Length; i++ )
            {
                ret[i + 2] = ToObjectArg(objInfo.Arguments[i], typeProvider);
            }

            return ret;
        }
示例#7
0
 public ManualPlayer(string id, PengWorld world, PlayerSide dir, Vector2 startPosition)
     : base(id, world, dir, startPosition)
 {
     if (dir == PlayerSide.Left)
     {
         UpKey = Keys.W;
         LeftKey = Keys.A;
         RightKey = Keys.D;
     }
     else
     {
         UpKey = Keys.Up;
         LeftKey = Keys.Left;
         RightKey = Keys.Right;
     }
 }
示例#8
0
        public void Load(PengWorld world, XmlReader reader, Func<string, Type> typeProvider)
        {
            Contract.Requires(world != null);
            Contract.Requires(reader != null);
            Contract.Requires(typeProvider != null);

            XmlSerializer serializer = new XmlSerializer(typeof(PengEngine.Internal.PengWorldInfo));
            var worldInfo = (PengWorldInfo)serializer.Deserialize(reader);
            foreach (var objInfo in worldInfo.Objects)
            {
                Type objType = typeProvider(objInfo.TypeName);
                ObjectArg[] args = GetObjectArgs(objInfo, world, typeProvider);
                var objCtor = objType.GetConstructor(Array.ConvertAll(args, x => x.Type));
                var obj = (PengObject)objCtor.Invoke(Array.ConvertAll(args, x => x.Value));
                obj.Load(objInfo.Content);
                foreach (var prop in objInfo.Properties)
                    SetObjectPropertyValue(obj, prop, world);
            }
        }
示例#9
0
        private void SetObjectPropertyValue(object obj, PengPropertyInfo prop, PengWorld world)
        {
            Contract.Requires(obj != null);
            Contract.Requires(prop != null);

            var propInfo = obj.GetType().GetProperty(prop.Name);
            object propValue;
            if (propInfo.PropertyType == typeof(int))
                propValue = int.Parse(prop.Value, System.Globalization.CultureInfo.InvariantCulture);
            else if (propInfo.PropertyType == typeof(float))
                propValue = float.Parse(prop.Value, System.Globalization.CultureInfo.InvariantCulture);
            else if (propInfo.PropertyType == typeof(string))
                propValue = prop.Value;
            else if (propInfo.PropertyType == typeof(Texture2D))
                propValue = world.LoadContent<Texture2D>(prop.Value);
            else if (propInfo.PropertyType == typeof(Vector2))
                propValue = ParseVector2(prop.Value);
            else if (propInfo.PropertyType.IsEnum)
                propValue = Enum.Parse(propInfo.PropertyType, prop.Value);
            else
                throw new Exception();
            propInfo.SetValue(obj, propValue, null);
        }
        public void Load(PengWorld world, XmlReader reader)
        {
            //Contract.Requires(world != null);
            //Contract.Requires(uri != null);

            XDocument document = XDocument.Load(reader);
            Load(world, document.Root);
        }
示例#11
0
 public void TestLoad()
 {
     PengWorld world = new PengWorld();
     string worldXml = @"<world>
     <objects>
     <object name='obj1' type='PengEngineTest.PengObjectExample'>
     <arguments>
         <argument type='System.Int32'>
             <value>45</value>
         </argument>
         <argument type='System.Single'>
             <value>56.34</value>
         </argument>
         <argument type='System.String'>
             <value>Hello, World!</value>
         </argument>
     </arguments>
     <properties>
         <property name='Test5'>
             <value>76.2</value>
         </property>
     </properties>
     <content>
     <![CDATA[
     <root>
     <test4>Test4</test4>
     </root>
     ]]>
     </content>
     </object>
     </objects>
     </world>";
     PengXmlWorldLoader.Instance.Load(world, XmlReader.Create(new StringReader(worldXml)), x => Type.GetType(x));
     var obj1 = (PengObjectExample)world.Objects["obj1"];
     Assert.AreEqual(45, obj1.Test1);
     Assert.AreEqual(56.34f, obj1.Test2);
     Assert.AreEqual("Hello, World!", obj1.Test3);
     Assert.AreEqual("Test4", obj1.Test4);
     Assert.AreEqual(76.2f, obj1.Test5);
 }
示例#12
0
文件: Tree.cs 项目: fiftin/Pengball
 public Tree(string name, PengWorld world)
     : base(name, world)
 {
     Initialize();
 }
示例#13
0
文件: Actor.cs 项目: fiftin/Pengball
 public Actor(string name, PengWorld world)
     : base(name, world)
 {
 }
示例#14
0
 public PengBlock(string name, PengWorld world, Vector2 size)
     : base(name, world)
 {
     Size = size;
     Initialize();
 }
示例#15
0
文件: Game1.cs 项目: fiftin/Pengball
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // TODO: use this.Content to load your game content here
     world = new PengballWorld(GraphicsDevice, Content);
     //world.DebugMode = true;
 }