コード例 #1
0
 private static Single CalculateRotation(Single rotation, Single gamePadLeftX, Single gamePadLeftY, Boolean turnLeft, Boolean turnRight)
 {
     if (gamePadLeftX >= TURN_AXIS_DEADBAND || gamePadLeftX <= -TURN_AXIS_DEADBAND || gamePadLeftY >= TURN_AXIS_DEADBAND || gamePadLeftY <= -TURN_AXIS_DEADBAND)
     {
         Single desiredRotation = FloatMathHelper.Atan2(gamePadLeftY, gamePadLeftX);
         if (Math.Abs(rotation - desiredRotation) < TOP_TURN_SPEED)
         {
             rotation = desiredRotation;
         }
         else
         {
             if (FloatMathHelper.CounterClockwiseAngularDistance(rotation, desiredRotation) < FloatMathHelper.ClockwiseAngularDistance(rotation, desiredRotation))
             {
                 rotation -= TOP_TURN_SPEED;
             }
             else
             {
                 rotation += TOP_TURN_SPEED;
             }
         }
     }
     else
     {
         if (turnLeft)
         {
             rotation -= TOP_TURN_SPEED * 0.5f;
         }
         else if (turnRight)
         {
             rotation += TOP_TURN_SPEED * 0.5f;
         }
     }
     return(MathHelper.WrapAngle(rotation));
 }
コード例 #2
0
        public Collectable CreateNewShotgunAmmoCollectable()
        {
            Collectable shotgunAmmoCollectable = new Collectable(Game,
                                                                 RandomCollectableSpawnLocation(),
                                                                 FloatMathHelper.Max(MINIMUM_SHOTGUN_AMMO_COLLECTABLE_LIFETIME, RandomHelper.NextRandomDouble() * MAXIMUM_SHOTGUN_AMMO_COLLECTABLE_LIFETIME),
                                                                 CollectableEntityType.ShotgunAmmo);

            this.AddCollectable(shotgunAmmoCollectable);
            return(shotgunAmmoCollectable);
        }
コード例 #3
0
        public Collectable CreateNewEnergyCollectable()
        {
            Collectable energyCollectable = new Collectable(Game,
                                                            RandomCollectableSpawnLocation(),
                                                            FloatMathHelper.Max(MINIMUM_ENERGY_COLLECTABLE_LIFETIME, RandomHelper.NextRandomDouble() * MAXIMUM_ENERGY_COLLECTABLE_LIFETIME),
                                                            CollectableEntityType.Energy);

            this.AddCollectable(energyCollectable);
            return(energyCollectable);
        }
コード例 #4
0
        public Collectable CreateNewPistolAmmoCollectable()
        {
            Collectable pistolAmmoCollectable = new Collectable(Game,
                                                                RandomCollectableSpawnLocation(),
                                                                FloatMathHelper.Max(MINIMUM_PISTOL_AMMO_COLLECTABLE_LIFETIME, RandomHelper.NextRandomDouble() * MAXIMUM_PISTOL_AMMO_COLLECTABLE_LIFETIME),
                                                                CollectableEntityType.PistolAmmo);

            this.AddCollectable(pistolAmmoCollectable);
            return(pistolAmmoCollectable);
        }
コード例 #5
0
        public Collectable CreateNewGasolineCollectable()
        {
            Collectable gasolineCollectable = new Collectable(Game,
                                                              RandomCollectableSpawnLocation(),
                                                              FloatMathHelper.Max(MINIMUM_GASOLINE_COLLECTABLE_LIFETIME, RandomHelper.NextRandomDouble() * MAXIMUM_GASOLINE_COLLECTABLE_LIFETIME),
                                                              CollectableEntityType.Gasoline);

            this.AddCollectable(gasolineCollectable);
            return(gasolineCollectable);
        }
コード例 #6
0
        public Collectable CreateNewHealthCollectable()
        {
            Collectable healthCollectable = new Collectable(Game,
                                                            RandomCollectableSpawnLocation(),
                                                            FloatMathHelper.Max(MINIMUM_HEALTH_COLLECTABLE_LIFETIME, RandomHelper.NextRandomDouble() * MAXIMUM_HEALTH_COLLECTABLE_LIFETIME),
                                                            CollectableEntityType.Health);

            this.AddCollectable(healthCollectable);
            return(healthCollectable);
        }
コード例 #7
0
        private static Single CalculateRotation(Single currentRotation, Vector2 rotationVector, Single topTurningSpeed)
        {
            rotationVector.Normalize();
            Single desiredRotation = FloatMathHelper.Atan2(rotationVector.Y, rotationVector.X);

            if (Math.Abs(currentRotation - desiredRotation) < topTurningSpeed)
            {
                currentRotation = desiredRotation;
            }
            else
            {
                if (FloatMathHelper.CounterClockwiseAngularDistance(currentRotation, desiredRotation) < FloatMathHelper.ClockwiseAngularDistance(currentRotation, desiredRotation))
                {
                    currentRotation -= topTurningSpeed;
                }
                else
                {
                    currentRotation += topTurningSpeed;
                }
            }
            return(MathHelper.WrapAngle(currentRotation));
        }
コード例 #8
0
 /// <summary>
 /// Calculate the angular distance from r to R in a clockwise direction
 /// </summary>
 /// <param name="r">First angle in Radians</param>
 /// <param name="R">First angle in Radians</param>
 /// <returns>Distance in Radians</returns>
 public static Single ClockwiseAngularDistance(Single r, Single R)
 {
     return(MathHelper.TwoPi - FloatMathHelper.CounterClockwiseAngularDistance(r, R));
 }
コード例 #9
0
        public void Control(GameTime gameTime, GamePadState gamePadState, KeyboardState keyboardState, MouseState mouseState)
        {
            // Get Position and Rotation
            Vector2 oldPosition = Location.Position;
            Vector2 position    = oldPosition;
            Single  oldRotation = Location.Rotation;
            Single  rotation    = oldRotation;

            // Get Game Pad State
            GameControl gameControl = new GameControl(gamePadState, oldGamePadState, keyboardState, oldKeyboardState, mouseState, oldMouseState);

            // Update Weapon Status
            CalculateWeaponStatus(gameTime, gameControl);

            // Calculate Velocity, Strafe and Rotation
            Single velocity = CalculateVelocity(gameControl.MovementControlY, gameControl.MoveForward, gameControl.MoveBackwards);
            Single strafe   = CalculateStrafe(gameControl.MovementControlX, gameControl.StrafeLeft, gameControl.StrafeRight);

            rotation = CalculateRotation(rotation, gameControl.OrientationControlX, gameControl.OrientationControlY, gameControl.turnLeft, gameControl.turnRight);

            // Calculate Movement Velocity Vector
            Vector2 velocityVector = new Vector2(FloatMathHelper.Cos(rotation), FloatMathHelper.Sin(rotation));
            Single  strafeRotation = MathHelper.WrapAngle(rotation + MathHelper.PiOver2);
            Vector2 strafeVector   = new Vector2(FloatMathHelper.Cos(strafeRotation), FloatMathHelper.Sin(strafeRotation));

            // Check for running condition
            if (gameControl.RunningControl)
            {
                Single multiplicationFactor = 0.0f;
                if (CurrentStamina > (0.2 * MAXIMUM_STAMINA_VALUE))
                {
                    //multiplicationFactor = 1.0f * (CurrentStamina / MAXIMUM_STAMINA_VALUE);
                    multiplicationFactor = 1.0f;
                    CurrentStamina      -= STAMINA_LOSS_RATE;
                }
                velocity *= (1.0f + multiplicationFactor);
            }
            else
            {
                if (CurrentHealth > (0.2 * MAXIMUM_HEALTH_VALUE))
                {
                    CurrentStamina += (STAMINA_GAIN_RATE * (CurrentHealth / MAXIMUM_HEALTH_VALUE));
                }
            }
            if (CurrentStamina > MAXIMUM_STAMINA_VALUE)
            {
                CurrentStamina = MAXIMUM_STAMINA_VALUE;
            }

            // Normalize Vectors and Update Position
            velocityVector.Normalize();
            strafeVector.Normalize();
            position = position + (velocityVector * velocity) + (strafeVector * strafe);

            // Update SpriteSpecifier
            Location.Position = position;
            Location.Rotation = rotation;

            // Check for Collisions
            if (Game.ZombiesSubsystem.ZombiesCollisionManager.CheckForCollisionsWith(this))
            {
                Location.Position = oldPosition;
                Location.Rotation = oldRotation;
            }

            // Check for Collections
            List <CollectableEntityType> collectedEntities = Game.CollectablesSubsystem.CollectablesCollectionManger.Collect(this);

            foreach (CollectableEntityType collectedEntity in collectedEntities)
            {
                switch (collectedEntity)
                {
                case CollectableEntityType.Health:
                    CurrentHealth += HEALTH_COLLECTABLE_HEALTH_VALUES;
                    Game.HUD.AddMessage("Collected Health.", Color.Blue, false);
                    Game.Results.CollectablesResults.HealthCollectablesCollected++;
                    break;

                case CollectableEntityType.Gasoline:
                    Ammunition.CollectGasolineCan();
                    Game.HUD.AddMessage("Collected Gasoline Can.", Color.Blue, false);
                    Game.Results.CollectablesResults.GasolineCollectablesCollected++;
                    break;

                case CollectableEntityType.Energy:
                    //TODO: Implement Enrgy Collectable Action
                    Game.HUD.AddMessage("Collected Energy.", Color.Blue, false);
                    Game.Results.CollectablesResults.EnergyCollectablesCollected++;
                    break;

                case CollectableEntityType.PistolAmmo:
                    Ammunition.CollectPistolClip();
                    Game.HUD.AddMessage("Collected Pistol Ammo.", Color.Blue, false);
                    Game.Results.CollectablesResults.PistolAmmoCollectablesCollected++;
                    break;

                case CollectableEntityType.ShotgunAmmo:
                    Ammunition.CollectShotgunShells(6);
                    Game.HUD.AddMessage("Collected Shotgun Ammo.", Color.Blue, false);
                    Game.Results.CollectablesResults.ShotgunAmmoCollectablesCollected++;
                    break;

                default: break;
                }
            }

            // Normalize State Values
            if (CurrentHealth > MAXIMUM_HEALTH_VALUE)
            {
                CurrentHealth = MAXIMUM_HEALTH_VALUE;
            }
            else if (CurrentHealth < 0.0f)
            {
                CurrentHealth = 0.0f;
            }
            if (CurrentStamina > MAXIMUM_STAMINA_VALUE)
            {
                CurrentStamina = MAXIMUM_STAMINA_VALUE;
            }
            else if (CurrentStamina < 0.0f)
            {
                CurrentStamina = 0.0f;
            }

            // Update Damage Vibration
            if (damageVibrationActive)
            {
                damageVibrationTimer -= gameTime.ElapsedGameTime.TotalSeconds;
                if (damageVibrationTimer <= 0.0)
                {
                    damageVibrationActive = false;
                    GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f);
                }
                else
                {
                    GamePad.SetVibration(PlayerIndex.One, 1.0f, 0.3f);
                }
            }
            else
            {
                GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f);
            }

            // Update Game Pad State Info
            oldGamePadState  = gamePadState;
            oldKeyboardState = keyboardState;
            oldMouseState    = mouseState;
        }
コード例 #10
0
        public override void Update(GameTime gameTime)
        {
            if (this.Alive)
            {
                Vector2 homingPosition = this.Game.SurvivorSubsystem.PlayerOneSurvivorSprite.Location.Position;
                Vector2 oldPosition    = Location.Position;
                Single  oldRotation    = Location.Rotation;

                Single  currentRotation = Location.Rotation;
                Vector2 currentPosition = Location.Position;
                Vector2 deltaPosition   = homingPosition - currentPosition;
                Single  rotation        = CalculateRotation(currentRotation, deltaPosition, TopTurningSpeed());
                Vector2 velocityVector  = new Vector2(FloatMathHelper.Cos(rotation), FloatMathHelper.Sin(rotation));
                if (Math.Abs(deltaPosition.Length()) > TopMovementSpeed())
                {
                    Single speed              = 0.0f;
                    Single cwAngularDistance  = FloatMathHelper.ClockwiseAngularDistance(currentRotation, rotation);
                    Single ccwAngularDistance = FloatMathHelper.CounterClockwiseAngularDistance(currentRotation, rotation);
                    Single deltaRotation      = MathHelper.Min(cwAngularDistance, ccwAngularDistance);
                    if (deltaRotation <= TURNING_MOVEMENT_LIMIT)
                    {
                        speed = TopMovementSpeed() * ((TURNING_MOVEMENT_LIMIT - deltaRotation) / TURNING_MOVEMENT_LIMIT);
                    }
                    Location.Position += (velocityVector * speed);
                    Location.Rotation  = rotation;
                    if (Game.SurvivorSubsystem.SurvivorsCollisionManager.CheckForCollisionsWith(this) || Game.ZombiesSubsystem.ZombiesCollisionManager.CheckForCollisionsWith(this))
                    {
                        Location.Position     = oldPosition;
                        Location.Rotation     = oldRotation;
                        zombieStationaryTime += gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        zombieStationaryTime = 0.0;
                    }
                }

                if (zombieStationaryTime >= ZOMBIE_MAXIMUM_STATIONARY_TIME)
                {
                    Alive = false;
                }

                Single zombieAttackValue = 0.0f;

                if (zombieAttackTime >= ZOMBIE_ATTACK_DELAY_TIME[(int)Game.Options.GameDifficulty])
                {
                    zombieAttackValue = ZOMBIE_ATTACK_VALUE;
                }

                if (Game.SurvivorSubsystem.SurvivorsAttackManager.AttackWithMelee(this, zombieAttackValue) == AttackResults.Damage)
                {
                    zombieAttackTime += gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    zombieAttackTime = 0.0;
                }

                if (animating)
                {
                    zombieAnimationTime += gameTime.ElapsedGameTime.TotalSeconds;
                    if (zombieAnimationTime >= ANIMATION_DELAY)
                    {
                        animationIndex++;
                        if (animationIndex < ANIMATION_CELL_INDICIES.Length)
                        {
                            currentCellIndex    = ANIMATION_CELL_INDICIES[animationIndex];
                            zombieAnimationTime = 0.0;
                        }
                        else
                        {
                            currentCellIndex = 0;
                            animating        = false;
                        }
                    }
                }
            }
        }