Exemplo n.º 1
0
        public override JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                dim /= 100;
                FarActor actor = new FarActor();
                actor.body          = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;
                Vector2  center = new Vector2(-dim.X, -dim.Y) / 2.0f;
                Vertices box    = PolygonTools.CreateRectangle(dim.X / 2.0f, dim.Y / 2.0f, center, 0);
                for (int i = 0; i < box.Count(); i++)
                {
                    Vector2 vert = box[i];
                    vert.X += dim.X / 2.0f;
                    vert.Y += dim.Y / 2.0f;
                    box[i]  = vert;
                    vert    = box[i];
                }
                PolygonShape shape = new PolygonShape(box, 1.0f);
                actor.BodyState = bodytype;
                actor.body.CreateFixture(shape, 1.0f);
                actor.Position = pos;
                actor.Width    = dim.X * 100;
                actor.Height   = dim.Y * 100;

                actors.Add(actor);
                return(actor);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public override JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                radius /= 100;
                FarActor actor = new FarActor();
                actor.body          = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;

                Vector2 center = new Vector2(-radius, -radius) / 2.0f;
                //  FarseerPhysics.Settings.MaxPolygonVertices = 33;
                Vertices sphere = PolygonTools.CreateCircle(radius, 32);

                PolygonShape shape = new PolygonShape(sphere, 1.0f);
                actor.BodyState = bodytype;
                actor.body.CreateFixture(shape, 1.0f);
                actor.Position = pos;
                actor.Width    = radius;
                actor.Height   = radius;

                actors.Add(actor);
                return(actor);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        FarseerPhysics.Dynamics.BodyType GetBodyType(JabActor.BodyType type)
        {
            switch (type)
            {
            case BodyType.DYNAMIC:
                return(FarseerPhysics.Dynamics.BodyType.Dynamic);

            case BodyType.STATIC:
                return(FarseerPhysics.Dynamics.BodyType.Kinematic);
            }
            //System.Windows.MessageBox.Show("ERROR: Body type provided invalid for FarWorld");

            return(FarseerPhysics.Dynamics.BodyType.Static);
        }
Exemplo n.º 4
0
 public PhysicSprite(Vector2 dim, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
     : base()
 {
     TextureDir = imagedir;
     Width      = dim.X;
     Height     = dim.Y;
     JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
     if (!dynamic)
     {
         type = JabActor.BodyType.STATIC;
     }
     body          = world.CreateBox(dim, pos, type);
     body.UserData = this;
     this.world    = world;
     DoDimensions  = true;
     DoHandle      = true;
 }
Exemplo n.º 5
0
        public PhysicSprite(float radius, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
            : base()
        {
            TextureDir = imagedir;
            Width      = radius;
            Height     = radius;
            JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
            if (!dynamic)
            {
                type = JabActor.BodyType.STATIC;
            }
            body          = world.CreateSphere(radius / 2.0f, pos, type);
            body.UserData = this;
            this.world    = world;

            // Initialize();
        }
Exemplo n.º 6
0
 public abstract JabActor CreateFromTriangles(List <Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 7
0
 public abstract JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 8
0
 public abstract JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 9
0
 public PhysicShape(JabWorld world, JabActor.BodyType bodytype)
     : base()
 {
     this.bodyType = bodytype;
     this.world    = world;
 }
Exemplo n.º 10
0
        public override JabActor CreateFromTriangles(List <Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                FarActor actor = new FarActor();
                actor.body          = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;

                //FarseerPhysics.Settings.MaxPolygonVertices = 33;

                for (int i = 0; i < triangles.Count; i++)
                {
                    Vector2[] tri = new Vector2[3];
                    tri[0] = triangles[i] / 100.0f;
                    ++i;
                    tri[1] = triangles[i] / 100.0f;
                    ++i;
                    tri[2] = triangles[i] / 100.0f;

                    Vertices     vertices = new Vertices(tri);
                    PolygonShape shape    = new PolygonShape(vertices, 1.0f);
                    actor.body.CreateFixture(shape, 1.0f);
                }

                actor.BodyState = bodytype;
                actor.Position  = pos;

                actors.Add(actor);
                return(actor);
            }
            catch (Exception e)
            {
                //System.Windows.MessageBox.Show(e.ToString());
            }

            return(null);
        }
Exemplo n.º 11
0
 public PhysicShape(JabWorld world, JabActor.BodyType bodytype)
     : base()
 {
     this.bodyType = bodytype;
     this.world = world;
 }
Exemplo n.º 12
0
        public List <JabActor> CreateBodies(XElement elements)
        {
            List <JabActor> bodies  = new List <JabActor>();
            var             items   = elements.Descendants("Items");
            var             element = elements.Descendants("CustomProperties").Descendants("Property");

            float  layerDepth     = 0;
            float  mass           = 0.25f;
            string type           = "";
            float  friction       = 0.5f;
            float  density        = 15.0f;
            float  restitution    = 0;
            bool   dynamic        = true;
            float  angulardamping = 0;

            foreach (var property in element)
            {
                if (property.Attribute("Name") != null)
                {
                    string name = property.Attribute("Name").Value;
                    if (name == "LayerDepth")
                    {
                        layerDepth = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Mass")
                    {
                        mass = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Friction")
                    {
                        friction = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Type")
                    {
                        type = property.Descendants("string").First <XElement>().Value;
                    }
                    else if (name == "Density")
                    {
                        density = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Restitution")
                    {
                        restitution = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                    else if (name == "Dynamic")
                    {
                        dynamic = property.Descendants("string").First <XElement>().Value.ToLowerInvariant() == "true";
                    }
                    else if (name == "AngularDamping")
                    {
                        angulardamping = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture);
                    }
                }
            }

            List <Sprite> baseSprites = CreateSprites(elements);

            for (int i = 0; i < baseSprites.Count; i++)
            {
                Sprite s    = baseSprites[i];
                float  posx = s.PosX;
                float  posy = s.PosY;

                float rot = s.Rot;

                float width  = s.ScaleX * s.Width;
                float height = s.ScaleY * s.Height;

                JabActor.BodyType bodyState = JabActor.BodyType.DYNAMIC;
                JabActor          actor     = null;
                if (!dynamic)
                {
                    bodyState = JabActor.BodyType.STATIC;
                }

                if (type == "Circle")
                {
                    actor = world.CreateSphere(width, new Vector2(posx, posy), bodyState);
                }
                else
                {
                    actor = world.CreateBox(new Vector2(width, height), new Vector2(posx, posy), bodyState);
                }

                actor.Friction       = friction;
                actor.Mass           = mass;
                actor.Restitution    = restitution;
                actor.Mass           = mass;
                actor.Rot            = rot;
                actor.Friction       = friction;
                actor.PosZ           = layerDepth;
                actor.Restitution    = restitution;
                actor.Density        = density;
                actor.AngularDamping = angulardamping;

                bodies.Add(actor);
            }

            return(bodies);
        }