Ejemplo n.º 1
0
        public SingleMap()
        {
            world = new World(new Vector2(0, 9.8f)); // That'd be cool to have gravity as a map property, so you could play 0G levels

            testFigure = new LocalPlayer(world, new Vector2(480 * MainGame.PIXEL_TO_METER, 480 * MainGame.PIXEL_TO_METER), Category.Cat1, Color.Red);
            dummyFigure = new StickFigure(world, new Vector2(150 * MainGame.PIXEL_TO_METER, 900 * MainGame.PIXEL_TO_METER), Category.Cat2, Color.Green);
            weapon = new TestWeapon(world, new Vector2(640 * MainGame.PIXEL_TO_METER, 480 * MainGame.PIXEL_TO_METER));
            walls = new List<Wall>();
            walls.Add(new Wall(world, 480 * MainGame.PIXEL_TO_METER, 700 * MainGame.PIXEL_TO_METER, 960 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 16 * MainGame.PIXEL_TO_METER, 540 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 1080 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 960 * MainGame.PIXEL_TO_METER, 1040 * MainGame.PIXEL_TO_METER, 1920 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1500 * MainGame.PIXEL_TO_METER, 960 * MainGame.PIXEL_TO_METER, 870 * MainGame.PIXEL_TO_METER, 120 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1450 * MainGame.PIXEL_TO_METER, 865 * MainGame.PIXEL_TO_METER, 248 * MainGame.PIXEL_TO_METER, 98 * MainGame.PIXEL_TO_METER, -(float)Math.PI / 6));
            walls.Add(new Wall(world, 1735 * MainGame.PIXEL_TO_METER, 840 * MainGame.PIXEL_TO_METER, 402 * MainGame.PIXEL_TO_METER, 176 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1904 * MainGame.PIXEL_TO_METER, 540 * MainGame.PIXEL_TO_METER, 32 * MainGame.PIXEL_TO_METER, 1080 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1859 * MainGame.PIXEL_TO_METER, 717 * MainGame.PIXEL_TO_METER, 109 * MainGame.PIXEL_TO_METER, 123 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1600 * MainGame.PIXEL_TO_METER, 570 * MainGame.PIXEL_TO_METER, 122 * MainGame.PIXEL_TO_METER, 104 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 1320 * MainGame.PIXEL_TO_METER, 487 * MainGame.PIXEL_TO_METER, 113 * MainGame.PIXEL_TO_METER, 107 * MainGame.PIXEL_TO_METER, 0.0f));
            walls.Add(new Wall(world, 180 * MainGame.PIXEL_TO_METER, 300 * MainGame.PIXEL_TO_METER, 41 * MainGame.PIXEL_TO_METER, 370 * MainGame.PIXEL_TO_METER, 0.0f));

            bulletList = new List<Bullet>();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Orients arms in necessary position
        /// </summary>
        private void UpdateArms()
        {
            // Update strength of arms based on health
            leftElbow.MaxImpulse = maxImpulse * health[leftLowerArm] * health[leftUpperArm];
            leftShoulder.MaxImpulse = maxImpulse * health[torso] * health[leftUpperArm];
            rightElbow.MaxImpulse = maxImpulse * health[rightLowerArm] * health[rightUpperArm];
            rightShoulder.MaxImpulse = maxImpulse * health[torso] * health[rightUpperArm];

            if (!Aiming && !throwing && !switchingHands)
            {
                // Rest arms at side
                if (weapon == null || weapon.Type == Weapon.WeaponType.Light || weapon.Type == Weapon.WeaponType.Explosive || weapon.Type == Weapon.WeaponType.Melee)
                {
                    leftShoulder.TargetAngle = FindClosestAngle(3 * MathHelper.PiOver4, torso.Rotation, leftShoulder.TargetAngle);
                    rightShoulder.TargetAngle = FindClosestAngle(-3 * MathHelper.PiOver4, torso.Rotation, rightShoulder.TargetAngle);
                    leftElbow.TargetAngle = MathHelper.PiOver4;
                    rightElbow.TargetAngle = -MathHelper.PiOver4;
                }
                else if (weapon.Type == Weapon.WeaponType.Medium || weapon.Type == Weapon.WeaponType.Heavy)
                {
                    if (leftHanded)
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(3 * MathHelper.PiOver4, torso.Rotation, leftShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(-3 * MathHelper.PiOver4, torso.Rotation, rightShoulder.TargetAngle);
                        leftElbow.TargetAngle = MathHelper.PiOver2;
                        rightElbow.TargetAngle = -MathHelper.PiOver4;
                    }
                    else
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(3 * MathHelper.PiOver4, torso.Rotation, leftShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(-3 * MathHelper.PiOver4, torso.Rotation, rightShoulder.TargetAngle);
                        leftElbow.TargetAngle = MathHelper.PiOver4;
                        rightElbow.TargetAngle = -MathHelper.PiOver2;
                    }
                }
            }
            else if (Aiming && !throwing)
            {
                // Aim weapon in direction
                float angle = -(float)Math.Atan2(aimVector.Y, aimVector.X);
                if (weapon == null || weapon.Type == Weapon.WeaponType.Light)
                {
                    leftShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, leftShoulder.TargetAngle);
                    rightShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, rightShoulder.TargetAngle);
                    leftElbow.TargetAngle = 0f;
                    rightElbow.TargetAngle = 0f;
                }
                else if (weapon.Type == Weapon.WeaponType.Medium || weapon.Type == Weapon.WeaponType.Heavy)
                {
                    if (leftHanded)
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, leftShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(angle + (angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? -MathHelper.PiOver4 : -3 * MathHelper.PiOver4), torso.Rotation, rightShoulder.TargetAngle);
                        leftElbow.TargetAngle = 0f;
                        rightElbow.TargetAngle = angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? -MathHelper.PiOver2 : MathHelper.PiOver2;
                    }
                    else
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(angle + (angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? -MathHelper.PiOver4 : -3 * MathHelper.PiOver4), torso.Rotation, rightShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, leftShoulder.TargetAngle);
                        leftElbow.TargetAngle = angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? -MathHelper.PiOver2 : MathHelper.PiOver2;
                        rightElbow.TargetAngle = 0f;
                    }
                }
                else if (weapon.Type == Weapon.WeaponType.Explosive || weapon.Type == Weapon.WeaponType.Melee)
                {
                    if (leftHanded)
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(angle + (angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? MathHelper.Pi : 0), torso.Rotation, leftShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, rightShoulder.TargetAngle);
                        leftElbow.TargetAngle = 0f;
                        rightElbow.TargetAngle = 0f;
                    }
                    else
                    {
                        leftShoulder.TargetAngle = FindClosestAngle(angle - MathHelper.PiOver2, torso.Rotation, rightShoulder.TargetAngle);
                        rightShoulder.TargetAngle = FindClosestAngle(angle + (angle >= MathHelper.PiOver2 || angle <= -MathHelper.PiOver2 ? MathHelper.Pi : 0), torso.Rotation, leftShoulder.TargetAngle);
                        leftElbow.TargetAngle = 0f;
                        rightElbow.TargetAngle = 0f;
                    }
                }

                Aiming = false;
            }
            else if (throwing)
            {
                // Throw weapon
                leftShoulder.TargetAngle = FindClosestAngle(-(float)Math.Atan2(aimVector.Y, aimVector.X) - MathHelper.PiOver2, torso.Rotation, leftShoulder.TargetAngle);
                rightShoulder.TargetAngle = FindClosestAngle(-(float)Math.Atan2(aimVector.Y, aimVector.X) - MathHelper.PiOver2, torso.Rotation, rightShoulder.TargetAngle);
                leftElbow.TargetAngle = 0f;
                rightElbow.TargetAngle = 0f;

                if (weapon != null)
                {
                    if (world.JointList.Contains(weaponJoint))
                        world.RemoveJoint(weaponJoint);
                    if (world.JointList.Contains(r_weaponJoint))
                        world.RemoveJoint(r_weaponJoint);
                    weapon.BeingHeld = false;
                    weapon.Body.LinearVelocity = aimVector / aimVector.Length() * 10f + this.torso.LinearVelocity;
                    this.weapon = null;
                }

                AngleJoint[] joints = new AngleJoint[] { leftShoulder, leftElbow, rightShoulder, rightElbow };
                if (JointsAreInPosition(joints))
                    throwing = false;
            }
            else if (switchingHands)
            {
                if (weapon != null)
                {
                    if (leftHanded)
                    {
                        // If you don't have a right hand to switch to, cancel the action
                        if (health[rightLowerArm] <= 0)
                            switchingHands = false;
                        else
                        {
                            // Move left hand to right position
                            leftShoulder.TargetAngle = FindClosestAngle(0f, rightShoulder.TargetAngle, 0f);
                            leftElbow.TargetAngle = rightElbow.TargetAngle;
                            AngleJoint[] joints = new AngleJoint[] { leftShoulder, leftElbow };
                            if (JointsAreInPosition(joints) || (LeftHandPosition - RightHandPosition).Length() < 0.1f)
                            {
                                if (world.JointList.Contains(weaponJoint))
                                    world.RemoveJoint(weaponJoint);
                                if (world.JointList.Contains(r_weaponJoint))
                                    world.RemoveJoint(r_weaponJoint);
                                leftHanded = false;
                                this.weapon.Position = RightHandPosition;
                                r_weaponJoint = JointFactory.CreateRevoluteJoint(world, rightLowerArm, this.weapon.Body, Vector2.Zero);
                                weaponJoint = JointFactory.CreateAngleJoint(world, rightLowerArm, this.weapon.Body);
                                float angle = weapon.Body.Rotation - rightLowerArm.Rotation;
                                weaponJoint.TargetAngle = (int)(angle / MathHelper.TwoPi) * MathHelper.TwoPi;
                                weaponJoint.CollideConnected = false;
                                weaponJoint.MaxImpulse = 100f;
                                switchingHands = false;
                            }
                        }
                    }
                    else
                    {
                        // If you don't have a left hand to switch to, cancel the action
                        if (health[leftLowerArm] <= 0)
                            switchingHands = false;
                        else
                        {
                            // Move right hand to left hand position
                            rightShoulder.TargetAngle = FindClosestAngle(0f, leftShoulder.TargetAngle, 0f);
                            rightElbow.TargetAngle = leftElbow.TargetAngle;
                            AngleJoint[] joints = new AngleJoint[] { rightShoulder, rightElbow };
                            if (JointsAreInPosition(joints) || (LeftHandPosition - RightHandPosition).Length() < 0.1f)
                            {
                                if (world.JointList.Contains(weaponJoint))
                                    world.RemoveJoint(weaponJoint);
                                if (world.JointList.Contains(r_weaponJoint))
                                    world.RemoveJoint(r_weaponJoint);
                                leftHanded = true;
                                this.weapon.Position = LeftHandPosition;
                                r_weaponJoint = JointFactory.CreateRevoluteJoint(world, leftLowerArm, this.weapon.Body, Vector2.Zero);
                                weaponJoint = JointFactory.CreateAngleJoint(world, leftLowerArm, this.weapon.Body);
                                float angle = weapon.Body.Rotation - leftLowerArm.Rotation;
                                weaponJoint.TargetAngle = (int)(angle / MathHelper.TwoPi) * MathHelper.TwoPi;
                                weaponJoint.CollideConnected = false;
                                weaponJoint.MaxImpulse = 100f;
                                switchingHands = false;
                            }
                        }
                    }
                }
                else
                    switchingHands = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Removes major joints connecting limbs with no health
        /// </summary>
        private void UpdateLimbAttachment()
        {
            // Left arm
            if (health[leftUpperArm] <= 0 && health[leftLowerArm] <= 0)
            {
                leftUpperArm.Friction = 3.0f;
                if (world.JointList.Contains(leftShoulder))
                    world.RemoveJoint(leftShoulder);
                if (world.JointList.Contains(r_leftShoulder))
                    world.RemoveJoint(r_leftShoulder);
            }
            if (health[leftLowerArm] <= 0)
            {
                leftLowerArm.Friction = 3.0f;
                if (world.JointList.Contains(leftElbow))
                    world.RemoveJoint(leftElbow);
                if (world.JointList.Contains(r_leftElbow))
                    world.RemoveJoint(r_leftElbow);
                if (leftHanded && weapon != null)
                {
                    weaponJoint.MaxImpulse = 0f;
                    if (world.JointList.Contains(weaponJoint))
                        world.RemoveJoint(weaponJoint);
                    if (world.JointList.Contains(r_weaponJoint))
                        world.RemoveJoint(r_weaponJoint);
                    weapon.BeingHeld = false;
                    this.weapon = null;
                }
            }

            // Right arm
            if (health[rightUpperArm] <= 0 && health[rightLowerArm] <= 0)
            {
                rightUpperArm.Friction = 3.0f;
                if (world.JointList.Contains(rightShoulder))
                    world.RemoveJoint(rightShoulder);
                if (world.JointList.Contains(r_rightShoulder))
                    world.RemoveJoint(r_rightShoulder);
            }
            if (health[rightLowerArm] <= 0)
            {
                rightLowerArm.Friction = 3.0f;
                if (world.JointList.Contains(rightElbow))
                    world.RemoveJoint(rightElbow);
                if (world.JointList.Contains(r_rightElbow))
                    world.RemoveJoint(r_rightElbow);
                if (!leftHanded && weapon != null)
                {
                    if (world.JointList.Contains(weaponJoint))
                        world.RemoveJoint(weaponJoint);
                    if (world.JointList.Contains(r_weaponJoint))
                        world.RemoveJoint(r_weaponJoint);
                    weapon.BeingHeld = false;
                    this.weapon = null;
                }
            }

            // Left leg
            if (health[leftUpperLeg] <= 0 && health[leftLowerLeg] <= 0)
            {
                leftUpperLeg.Friction = 3.0f;
                if (world.JointList.Contains(leftHip))
                    world.RemoveJoint(leftHip);
                if (world.JointList.Contains(r_leftHip))
                    world.RemoveJoint(r_leftHip);
            }
            if (health[leftLowerLeg] <= 0)
            {
                leftLowerLeg.Friction = 3.0f;
                if (world.JointList.Contains(leftKnee))
                    world.RemoveJoint(leftKnee);
                if (world.JointList.Contains(r_leftKnee))
                    world.RemoveJoint(r_leftKnee);
            }

            // Right leg
            if (health[rightUpperLeg] <= 0 && health[rightLowerLeg] <= 0)
            {
                rightUpperLeg.Friction = 3.0f;
                if (world.JointList.Contains(rightHip))
                    world.RemoveJoint(rightHip);
                if (world.JointList.Contains(r_rightHip))
                    world.RemoveJoint(r_rightHip);
            }
            if (health[rightLowerLeg] <= 0)
            {
                rightLowerLeg.Friction = 3.0f;
                if (world.JointList.Contains(rightKnee))
                    world.RemoveJoint(rightKnee);
                if (world.JointList.Contains(r_rightKnee))
                    world.RemoveJoint(r_rightKnee);
            }

            // Torso
            if (health[torso] <= 0)
            {
                torso.Friction = 3.0f;
                if (world.JointList.Contains(upright))
                    world.RemoveJoint(upright);
            }

            // Head
            if (health[head] <= 0)
            {
                head.Friction = 3.0f;
                if (world.JointList.Contains(neck))
                    world.RemoveJoint(neck);
                if (world.JointList.Contains(r_neck))
                    world.RemoveJoint(r_neck);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Picks up the weapon
        /// </summary>
        /// <param name="w"></param>
        public void PickUpWeapon(Weapon w)
        {
            if (!w.BeingHeld && weapon == null && touchingWeapons.Contains(w))
            {
                if (health[leftLowerArm] == 0 && health[rightLowerArm] == 0)
                    return;

                this.weapon = w;
                this.weapon.PickUp(collisionCat);

                float angle;
                if (health[leftLowerArm] >= health[rightLowerArm])
                {
                    this.weapon.Position = LeftHandPosition;
                    r_weaponJoint = JointFactory.CreateRevoluteJoint(world, leftLowerArm, this.weapon.Body, Vector2.Zero);
                    weaponJoint = JointFactory.CreateAngleJoint(world, leftLowerArm, this.weapon.Body);
                    leftHanded = true;
                    angle = weapon.Body.Rotation - leftLowerArm.Rotation;
                }
                else
                {
                    this.weapon.Position = RightHandPosition;
                    r_weaponJoint = JointFactory.CreateRevoluteJoint(world, rightLowerArm, this.weapon.Body, Vector2.Zero);
                    weaponJoint = JointFactory.CreateAngleJoint(world, rightLowerArm, this.weapon.Body);
                    leftHanded = false;
                    angle = weapon.Body.Rotation - rightLowerArm.Rotation;
                }

                weaponJoint.TargetAngle = (int)(angle / MathHelper.TwoPi) * MathHelper.TwoPi;
                weaponJoint.CollideConnected = false;
                weaponJoint.MaxImpulse = 100f;
            }
        }