private void CalculateWeaponStatus(GameTime gameTime, GameControl gameControl) { // Cycle through Weapons if (gameControl.WeaponNextCycleControl) { Weapon oldWeapon = WEAPON_SPECIFIERS[currentWeaponSpecifierIndex]; currentWeaponSpecifierIndex++; if (currentWeaponSpecifierIndex >= WEAPON_SPECIFIERS.Length) currentWeaponSpecifierIndex = 0; while (!weaponsEnabled[currentWeaponSpecifierIndex]) { currentWeaponSpecifierIndex++; if (currentWeaponSpecifierIndex >= WEAPON_SPECIFIERS.Length) currentWeaponSpecifierIndex = 0; } oldWeapon.Stow(); CurrentWeapon.Deploy(); } else if (gameControl.WeaponPreviousCycleControl) { Weapon oldWeapon = WEAPON_SPECIFIERS[currentWeaponSpecifierIndex]; currentWeaponSpecifierIndex--; if (currentWeaponSpecifierIndex < 0) currentWeaponSpecifierIndex = WEAPON_SPECIFIERS.Length - 1; while (!weaponsEnabled[currentWeaponSpecifierIndex]) { currentWeaponSpecifierIndex--; if (currentWeaponSpecifierIndex < 0) currentWeaponSpecifierIndex = WEAPON_SPECIFIERS.Length - 1; } oldWeapon.Stow(); CurrentWeapon.Deploy(); } // Update current weapon CurrentWeapon.Update(gameTime, gameControl.WeaponLeftFireControl, gameControl.WeaponRightFireControl, gameControl.WeaponReloadControl, this); }
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; }
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; }