2
0

AlignBehavior.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // AlignBehavior.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 System;
  11. using Microsoft.Xna.Framework;
  12. #endregion
  13. namespace Flocking
  14. {
  15. /// <summary>
  16. /// AlignBehavior is a Behavior that makes an animal move in the same
  17. /// direction that the other Animal it sees is
  18. /// </summary>
  19. class AlignBehavior : Behavior
  20. {
  21. #region Initialization
  22. public AlignBehavior(Animal animal)
  23. : base(animal)
  24. {
  25. }
  26. #endregion
  27. #region Update
  28. /// <summary>
  29. /// AlignBehavior.Update infuences the owning animal to move in same the
  30. /// direction as the otherAnimal that it sees.
  31. /// </summary>
  32. /// <param name="otherAnimal">the Animal to react to</param>
  33. /// <param name="aiParams">the Behaviors' parameters</param>
  34. public override void Update(Animal otherAnimal, AIParameters aiParams)
  35. {
  36. base.ResetReaction();
  37. if (otherAnimal != null)
  38. {
  39. reacted = true;
  40. reaction = otherAnimal.Direction * aiParams.PerMemberWeight;
  41. }
  42. }
  43. #endregion
  44. }
  45. }