Ejemplo n.º 1
0
        public Joints(SoundEffect hn, SoundEffect rotv, seeSaw ss, HelicopterBase hb, HelicopterRotor hr, HelicopterSkid hs, HelicopterTail ht, HelicopterTailRotor htr, HelicopterClawHolder hch, HelicopterClawHinge hchinge, HelicopterClawItemHolder hcih)
        {
            engineOn = false;       // Set the engine to off

            hBase = hb;
            hRotor = hr;
            hSkid = hs;
            hTail = ht;
            hTailRotor = htr;
            hClawHolder = hch;
            hClawHinge = hchinge;
            hClawItemHolder = hcih;
            seeSaw = ss;

            helicopterNoise = hn;
            hnInstance = helicopterNoise.CreateInstance();          // New instance of sound effect
            hnInstance.Volume = 0.6f;
            hnInstance.IsLooped = true;

            rideOfTheValkyries = rotv;
            rotvInstance = rideOfTheValkyries.CreateInstance();     // New instance of sound effect
            rotvInstance.Volume = 0.6f;
            rotvInstance.IsLooped = true;

            hBaseRotorJoint = new RevoluteJoint(hBase.helicopter.body, hRotor.rotor.body, hBase.helicopter.body.Position, Vector3.Up);  // Joint for rotor on top of helicopter
            hBaseRotorJoint.Motor.Settings.MaximumForce = 200;
            hBaseRotorJoint.Motor.IsActive = false;

            // Well joints for skids on bottom of helicopter and tail, attach each entity to the helicopter
            hTailJoint = new WeldJoint(hTail.tail.body, hBase.helicopter.body);
            hSkidJoint1 = new WeldJoint(hSkid.skid1.body, hBase.helicopter.body);
            hSkidJoint2 = new WeldJoint(hSkid.skid2.body, hBase.helicopter.body);

            hTailRotorJoint = new RevoluteJoint(hTailRotor.tailRotor.body, hTail.tail.body, hTailRotor.tailRotor.body.Position, Vector3.Right); // Joint for rotor on tail of the helicopter
            hTailRotorJoint.Motor.Settings.MaximumForce = 180;
            hTailRotorJoint.Motor.IsActive = false;

            hClawHolderJoint = new SwivelHingeJoint(hBase.helicopter.body, hClawHolder.clawHolder.body, hBase.helicopter.body.Position, Vector3.Right);    // Joint for claw holder below helicopter

            hClawHolderJoint.HingeLimit.IsActive = true;
            hClawHolderJoint.HingeLimit.MinimumAngle = -MathHelper.Pi / 45;
            hClawHolderJoint.HingeLimit.MaximumAngle = MathHelper.Pi / 45;

            // 4 similar joints for hinge joints between the claw holder and a part of the claw
            // The hinges code was created with help from the examuse ple Bepu Physics demo available from the website
            hClawHingeJoint1 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge1.body, hClawHolder.clawHolder.body.Position, Vector3.Forward);
            hClawHingeJoint1.Motor.IsActive = true;
            hClawHingeJoint1.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint1.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;     // Damping to quicken the claw contracting
            hClawHingeJoint1.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;   // Stop the claw from over moving on the axis

            hClawHingeJoint1.Limit.IsActive = true;
            hClawHingeJoint1.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint1.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint2 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge2.body, hClawHolder.clawHolder.body.Position, Vector3.Backward);
            hClawHingeJoint2.Motor.IsActive = true;
            hClawHingeJoint2.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint2.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint2.Limit.IsActive = true;
            hClawHingeJoint2.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint2.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint3 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge3.body, hClawHolder.clawHolder.body.Position, Vector3.Right);
            hClawHingeJoint3.Motor.IsActive = true;
            hClawHingeJoint3.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint3.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint3.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint3.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint3.Limit.IsActive = true;
            hClawHingeJoint3.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint3.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint4 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge4.body, hClawHolder.clawHolder.body.Position, Vector3.Left);
            hClawHingeJoint4.Motor.IsActive = true;
            hClawHingeJoint4.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint4.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint4.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint4.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint4.Limit.IsActive = true;
            hClawHingeJoint4.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint4.Limit.MaximumAngle = MathHelper.PiOver4;

            // More weld joints as the claw pieces are made up off two different sections
            hClawItemHolderJoint1 = new WeldJoint(hClawHinge.clawHinge1.body, hClawItemHolder.clawItemHolder1.body);
            hClawItemHolderJoint2 = new WeldJoint(hClawHinge.clawHinge2.body, hClawItemHolder.clawItemHolder2.body);
            hClawItemHolderJoint3 = new WeldJoint(hClawHinge.clawHinge3.body, hClawItemHolder.clawItemHolder3.body);
            hClawItemHolderJoint4 = new WeldJoint(hClawHinge.clawHinge4.body, hClawItemHolder.clawItemHolder4.body);

            // Joint for the seesaw with the ball located on it
            seeSawJoint = new RevoluteJoint(seeSaw.seeSawHolder.body, seeSaw.seeSawBoard.body, seeSaw.seeSawHolder.body.Position, Vector3.Forward);

            revoluteJoints.Add(hBaseRotorJoint);
            revoluteJoints.Add(hTailRotorJoint);
            revoluteJoints.Add(hClawHingeJoint1);
            revoluteJoints.Add(hClawHingeJoint2);
            revoluteJoints.Add(hClawHingeJoint3);
            revoluteJoints.Add(hClawHingeJoint4);
            revoluteJoints.Add(seeSawJoint);

            weldJoints.Add(hTailJoint);
            weldJoints.Add(hSkidJoint1);
            weldJoints.Add(hSkidJoint2);
            weldJoints.Add(hClawItemHolderJoint1);
            weldJoints.Add(hClawItemHolderJoint2);
            weldJoints.Add(hClawItemHolderJoint3);
            weldJoints.Add(hClawItemHolderJoint4);

            entities.Add(hBase.helicopter);
            entities.Add(hRotor.rotor);
            entities.Add(hSkid.skid1);
            entities.Add(hSkid.skid2);
            entities.Add(hTail.tail);
            entities.Add(hTailRotor.tailRotor);
            entities.Add(hClawHolder.clawHolder);

            entities.Add(hClawHinge.clawHinge1);
            entities.Add(hClawHinge.clawHinge2);
            entities.Add(hClawHinge.clawHinge3);
            entities.Add(hClawHinge.clawHinge4);
            entities.Add(hClawItemHolder.clawItemHolder1);
            entities.Add(hClawItemHolder.clawItemHolder2);
            entities.Add(hClawItemHolder.clawItemHolder3);
            entities.Add(hClawItemHolder.clawItemHolder4);

            for (int i = 0; i < revoluteJoints.Count; i++)      // Add all the revolute joints to the space
            {
                Game1.Instance.Space.Add(revoluteJoints.ElementAt(i));
            }

            for (int i = 0; i < weldJoints.Count; i++)          // Add all the weld joints to the space
            {
                Game1.Instance.Space.Add(weldJoints.ElementAt(i));
            }

            Game1.Instance.Space.Add(hClawHolderJoint);     // Add the swivel hinge joint to the space
        }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            camera = new Camera();

            children = new List<GameEntity>();

            children.Add(camera);       // Add the camera to the list of children

            random = new Random();

            controls = Content.Load<Texture2D>("Helicopter Controls");

            groundEntity = new Ground();
            otherEntities = new OtherEntities();
            hBase = new HelicopterBase();
            hRotor = new HelicopterRotor();
            hSkid = new HelicopterSkid();
            hTail = new HelicopterTail();
            hTailRotor = new HelicopterTailRotor();
            hClawHolder = new HelicopterClawHolder();
            hClawHinge = new HelicopterClawHinge();
            hClawItemHolder = new HelicopterClawItemHolder();
            seeSaw = new seeSaw();
            helicopterNoise = Content.Load<SoundEffect>("Helicopter Sound Effect");
            rideOfTheValkyries = Content.Load<SoundEffect>("ROTV");

            base.Initialize();
        }