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;
        }
Ejemplo n.º 2
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;
                        }
                    }
                }
            }
        }