AlignBehavior.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //-----------------------------------------------------------------------------
  2. // AlignBehavior.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using Microsoft.Xna.Framework;
  9. namespace Flocking
  10. {
  11. /// <summary>
  12. /// AlignBehavior is a Behavior that makes an animal move in the same
  13. /// direction that the other Animal it sees is
  14. /// </summary>
  15. class AlignBehavior : Behavior
  16. {
  17. public AlignBehavior(Animal animal)
  18. : base(animal)
  19. {
  20. }
  21. /// <summary>
  22. /// AlignBehavior.Update infuences the owning animal to move in same the
  23. /// direction as the otherAnimal that it sees.
  24. /// </summary>
  25. /// <param name="otherAnimal">the Animal to react to</param>
  26. /// <param name="aiParams">the Behaviors' parameters</param>
  27. public override void Update(Animal otherAnimal, AIParameters aiParams)
  28. {
  29. base.ResetReaction();
  30. if (otherAnimal != null)
  31. {
  32. reacted = true;
  33. reaction = otherAnimal.Direction * aiParams.PerMemberWeight;
  34. }
  35. }
  36. }
  37. }