Exemplo n.º 1
0
        ///<Summary>
        /// This calls the base function and then attaches a motor between the upper body and wheel
        ///</Summary>
        public override void LoadContent(World world, String AssetName, Vector2 position, float Scale)
        {
            base.LoadContent(world, AssetName, position, Scale);

            //Create a joint between the upper body and wheel to hold the body upright
            fixedAngleJoint = JointFactory.CreateFixedAngleJoint(world, body);

            //Attach motor
            motor = JointFactory.CreateRevoluteJoint(world, body, wheel, Vector2.Zero);
            motor.MotorEnabled = true;
            motor.MaxMotorTorque = 1000f;
            motor.MotorSpeed = 0;

            //Make sure that the 2 bodies don't collide
            wheel.IgnoreCollisionWith(body);
            body.IgnoreCollisionWith(wheel);

            //Cause the wheel to firmly grip the surface
            wheel.Friction = float.MaxValue;

            this.world = world;
        }
Exemplo n.º 2
0
        public override void Create(World world, float Xoffset)
        {
            _jumpSound = _content.Load<SoundEffect>("Sounds\\jump");
            _dragSound = _content.Load<SoundEffect>("Sounds\\drag");
            _bounceSound = _content.Load<SoundEffect>("Sounds\\smash");
            base.Create(world, Xoffset);
            _moveState = MoveState.AIR;
            _body = FixtureFactory.CreateRectangle(_world, 1, 1.5f, 1, Position);
            _body.Body.BodyType = BodyType.Dynamic;
            _body.Restitution = 0.3f;
            _body.Friction = 0.5f;
            _joints.Add(JointFactory.CreateFixedAngleJoint(_world, _body.Body));
            _wheel = FixtureFactory.CreateCircle(_world, 1 / 2.0f, 1, _body.Body.Position + new Vector2(0, -(0.5f * 1.5f)));
            _wheel.Body.BodyType = BodyType.Dynamic;
            _joints.Add(JointFactory.CreateRevoluteJoint(_world, _body.Body, _wheel.Body, Vector2.Zero));
            _body.CollisionFilter.IgnoreCollisionWith(_wheel);
            _wheel.CollisionFilter.IgnoreCollisionWith(_body);
            _wheel.Friction = 1.0f;
            _fixtures.Add(_body);
            _fixtures.Add(_wheel);
            _body.UserData = this;
            _wheel.UserData = this;

            // Create a break for when the player isn't moving so friction can act on the player properly
            _wheelBreak = JointFactory.CreateFixedAngleJoint(_world, _wheel.Body);
            _wheelBreak.Enabled = true;

            _body.OnCollision += new OnCollisionEventHandler(OnCollision);
            _body.OnSeparation += new OnSeparationEventHandler(OnSeparation);

            _wheel.OnCollision += new OnCollisionEventHandler(OnCollision);
            _wheel.OnSeparation += new OnSeparationEventHandler(OnSeparation);
        }