Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="game"></param>
 /// <param name="world"></param>
 /// <param name="position">The top left corner</param>
 /// <param name="width">The width of the container</param>
 /// <param name="height">The height of a container</param>
 public Water(Game game, SpriteBatch spriteBatch, World world, Vector2 position, float width, float height)
 {
     sprite = new LoopSpriteAnimator(game, spriteBatch, game.Content.Load<Texture2D>("Images/Sprites/gb"), 200, 6, 1, 6);
     position = new Vector2(position.X + width/2,position.Y + height/2);
     texture = new TexturedGameEntity(game, position,0,"Images/water",0.3f);
     var container = new AABB(ConvertUnits.ToSimUnits(position),ConvertUnits.ToSimUnits(width),ConvertUnits.ToSimUnits(height));
     var buoyancy = new BuoyancyController(container, 1.1f, 2, 1, world.Gravity);
     world.AddController(buoyancy);
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;*/
        }
Ejemplo n.º 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);
        }