SoldierBee.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // SoldierBee.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Graphics;
  12. #endregion
  13. namespace HoneycombRush
  14. {
  15. /// <summary>
  16. /// This is a game component that implements IUpdateable.
  17. /// </summary>
  18. public class SoldierBee : Bee
  19. {
  20. #region Fields/Properties
  21. protected float chaseDistance = 70f;
  22. bool isChaseMode = false;
  23. public float DistanceFromBeeKeeper { get; set; }
  24. public Vector2 BeeKeeperVector { get; set; }
  25. protected override int MaxVelocity
  26. {
  27. get
  28. {
  29. return (int)ConfigurationManager.ModesConfiguration[
  30. ConfigurationManager.DifficultyMode.Value].MaxSoldierBeeVelocity;
  31. }
  32. }
  33. protected override float AccelerationFactor
  34. {
  35. get
  36. {
  37. return 20;
  38. }
  39. }
  40. #endregion
  41. #region Initialization
  42. /// <summary>
  43. /// Creates a new soldier bee instance.
  44. /// </summary>
  45. /// <param name="game">Associated game object.</param>
  46. /// <param name="gamePlayScreen">Gameplay screen where the bee will appear.</param>
  47. /// <param name="beehive">The bee's associated beehive.</param>
  48. public SoldierBee(Game game, GameplayScreen gamePlayScreen, Beehive beehive)
  49. : base(game, gamePlayScreen, beehive)
  50. {
  51. AnimationKey = "SoldierBee";
  52. }
  53. /// <summary>
  54. /// Loads the content used by this component.
  55. /// </summary>
  56. protected override void LoadContent()
  57. {
  58. texture = Game.Content.Load<Texture2D>("Textures/SoldierBeeWingFlap");
  59. base.LoadContent();
  60. }
  61. #endregion
  62. #region Update
  63. /// <summary>
  64. /// Updates the component.
  65. /// </summary>
  66. /// <param name="gameTime">Game time information.</param>
  67. public override void Update(GameTime gameTime)
  68. {
  69. if (!gamePlayScreen.IsActive)
  70. {
  71. base.Update(gameTime);
  72. return;
  73. }
  74. // If the bee was hit by smoke use the base behavior
  75. if (isHitBySmoke)
  76. {
  77. base.Update(gameTime);
  78. // Bee can not chase when it has been hit by smoke
  79. isChaseMode = false;
  80. }
  81. else
  82. {
  83. // The bee is chasing the beekeeper
  84. if (isChaseMode)
  85. {
  86. // Move the bee closer to the beekeeper
  87. velocity = BeeKeeperVector / AccelerationFactor;
  88. position += velocity;
  89. AnimationDefinitions[AnimationKey].Update(gameTime, true);
  90. // The chase is over
  91. if (DistanceFromBeeKeeper <= 10f)
  92. {
  93. isChaseMode = false;
  94. SetStartupPosition();
  95. }
  96. }
  97. else
  98. {
  99. // If close enough, start chasing
  100. if (DistanceFromBeeKeeper != 0f && DistanceFromBeeKeeper <= chaseDistance)
  101. {
  102. isChaseMode = true;
  103. }
  104. else
  105. {
  106. base.Update(gameTime);
  107. }
  108. }
  109. }
  110. }
  111. #endregion
  112. }
  113. }