Exemple #1
0
        public Sphere(Game game, World world, Vector2 position, float density)
        {
            texture = new TexturedGameEntity(game, position, 0f, "Images/sphere1", 1f);

            var origin = new Vector2(texture.Width/2f, texture.Height/2f);
            var body = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(origin.X), density);
            body.Restitution = 0.4f;
            body.OnCollision += Body_OnCollision;
            body.Friction = 50f;
            body.BodyType = BodyType.Dynamic;
            sphere = new TexturedPhysicsEntity(game, world, CollisionCategoriesSettings.Sphere,texture, body, origin);
            //body.CollidesWith = ~CollisionCategoriesSettings.Terrain;
        }
Exemple #2
0
        public BigWheel(Game game, World world, Vector2 position)
        {
            var texture = new TexturedGameEntity(game, position, 0, "Images/bigWheel", 1);
            var body = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(texture.Width/2), 1f);
            body.BodyType = BodyType.Dynamic;
            wheel = new TexturedPhysicsEntity(game, world, Category.Cat31, texture, body, new Vector2(texture.Width/2f, texture.Height/2f));

            revJoint = JointFactory.CreateFixedRevoluteJoint(world, wheel.Body, Vector2.Zero, ConvertUnits.ToSimUnits(wheel.Position));
            revJoint.MotorEnabled = true;
            revJoint.MotorSpeed = 3000;
            /*revJoint.MaxMotorTorque = 3000;
            revJoint.LimitEnabled = true;
            revJoint.UpperLimit = 3000;*/
        }
Exemple #3
0
        public Landscape(Game game, World world, float screenHeight, string[] images, Category collisionCategory, float zIndex)
        {
            parts = new List<TexturedPhysicsEntity>();

            for (int i = 0; i < images.Length; i++)
            {
                var part = new TexturedPhysicsEntity(game, world, collisionCategory, new TexturedGameEntity(game, 0, images[i], zIndex), 1f, BodyType.Static);
                parts.Add(part);

                if (i == 0) // Position the first part accordingly; all of the rest will follow
                {
                    part.X = part.Center.X;
                }
                else
                {
                    part.X = part.Center.X + (parts[i - 1].Width*i);
                }
                part.Y = screenHeight - (part.Height - part.Center.Y);

                Width += part.Width;
            }
        }
Exemple #4
0
        public Vehicle(Game game, World world, Vector2 position)
        {
            var chassisTexture = new TexturedGameEntity(game, position, 0, "Images/vehicle_body", 1);
            parts = new List<PhysicsGameEntity>();

            var chassisBody = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(chassisTexture.Width), ConvertUnits.ToSimUnits(chassisTexture.Height), 10f, ConvertUnits.ToSimUnits(chassisTexture.Position));
            body = new TexturedPhysicsEntity(game, world, CollisionCategoriesSettings.Vehicle, chassisTexture, chassisBody, new Vector2(chassisTexture.Width/2f, chassisTexture.Height/2f));

            //var bodyVertices = new FileTextureReader(@"VerticesList\vehicle.txt").GetVertices();
            //body = new TexturedPhysicsEntity(game,world,chassisTexture,bodyVertices,BodyType.Dynamic,10f);

            float axisWidth = 5, axisHeight = 50;
            Vector2 axisCentroid = new Vector2(axisWidth/2f, axisHeight/2f);
            PhysicsGameEntity leftAxis = new PhysicsGameEntity(game, world, CollisionCategoriesSettings.Vehicle, BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(axisWidth), ConvertUnits.ToSimUnits(axisHeight), 10f, ConvertUnits.ToSimUnits(new Vector2(body.Position.X - 50, body.Position.Y + 15))), axisCentroid),
                rightAxis = new PhysicsGameEntity(game, world, CollisionCategoriesSettings.Vehicle, BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(axisWidth), ConvertUnits.ToSimUnits(axisHeight), 10f, ConvertUnits.ToSimUnits(new Vector2(body.Position.X + 68, body.Position.Y + 15))), axisCentroid);

            leftAxis.Angle = MathHelper.ToRadians(90);

            leftWheel = new TexturedPhysicsEntity(game, world, CollisionCategoriesSettings.Vehicle, new TexturedGameEntity(game, new Vector2(leftAxis.Position.X, leftAxis.Position.Y + 20), 0, "Images/wheel_left", 1), 10f, BodyType.Static);
            rightWheel = new TexturedPhysicsEntity(game, world, CollisionCategoriesSettings.Vehicle, new TexturedGameEntity(game, new Vector2(rightAxis.Position.X, rightAxis.Position.Y + 20), 0, "Images/wheel_right", 1), 10f, BodyType.Static);
            ApplyToWheels();
            parts.Add(body);
            parts.Add(leftWheel);
            parts.Add(rightWheel);
            parts.Add(leftAxis);
            parts.Add(rightAxis);

            parts.ForEach(p => SetPartDynamics(p.Body));

            leftAxisJoint = JointFactory.CreateRevoluteJoint(world, leftAxis.Body, leftWheel.Body, Vector2.Zero);
            rightAxisJoint = JointFactory.CreateRevoluteJoint(world, rightAxis.Body, rightWheel.Body, Vector2.Zero);

            //body.Body.BodyType = BodyType.Kinematic;
            //JointFactory.CreateDistanceJoint(world, leftWheel.Body, rightWheel.Body, Vector2.Zero, Vector2.Zero);

            JointFactory.CreateWeldJoint(world, body.Body, leftAxis.Body, ConvertUnits.ToSimUnits(leftAxis.Position));// ConvertUnits.ToSimUnits(new Vector2(axis1.Position.X - 40, axis1.Position.Y)), Vector2.Zero);// ConvertUnits.ToSimUnits(new Vector2(0,body.Position.Y)));
            JointFactory.CreateWeldJoint(world, body.Body, rightAxis.Body, ConvertUnits.ToSimUnits(rightAxis.Position));//ConvertUnits.ToSimUnits(new Vector2(axis2.Position.X + 80, axis2.Position.Y)), Vector2.Zero);
        }
Exemple #5
0
 void ApplyToWheel(TexturedPhysicsEntity wheel)
 {
     wheel.Body.Friction = 5;
     wheel.Body.Restitution = 0.2f;
 }