GameAreaEvent.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GameAreaEvent.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 System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. using RobotGameData;
  16. #endregion
  17. namespace RobotGameData.GameEvent
  18. {
  19. /// <summary>
  20. /// When a particular scene node comes into a particular area,
  21. /// this event is executed.
  22. /// </summary>
  23. public class GameAreaEvent : GameEventBase
  24. {
  25. #region Fields
  26. protected Vector3 actionPosition = Vector3.Zero;
  27. protected float actionRadius = 0.0f;
  28. #endregion
  29. /// <summary>
  30. /// Constructor.
  31. /// </summary>
  32. /// <param name="type">event type</param>
  33. /// <param name="position">position</param>
  34. /// <param name="radius">area radius</param>
  35. /// <param name="owner">event owner</param>
  36. /// <param name="visibledOwner">owner visible flag</param>
  37. public GameAreaEvent(Vector3 position, float radius,
  38. GameSceneNode owner, bool visibledOwner)
  39. {
  40. SetAction(position, radius, owner, visibledOwner);
  41. }
  42. /// <summary>
  43. /// Set area event
  44. /// </summary>
  45. /// <param name="position">The position of this event</param>
  46. /// <param name="radius">The radius of this event</param>
  47. /// <param name="owner">The scene owner of this event</param>
  48. /// <param name="visibledOwner">
  49. /// Visibility of the scene owner before start this event
  50. /// </param>
  51. public void SetAction(Vector3 position, float radius,
  52. GameSceneNode owner, bool visibledOwner)
  53. {
  54. this.actionPosition = position;
  55. this.actionRadius = radius;
  56. this.owner = owner;
  57. this.owner.Enabled = false;
  58. this.owner.Visible = visibledOwner;
  59. }
  60. /// <summary>
  61. /// If the distance between the "targetPosition" and the selected
  62. /// action position is short, the status of the game changes so that
  63. /// an event might occur. In this case, it returns "true".
  64. /// </summary>
  65. public bool IsExecuteAction(Vector3 targetPosition)
  66. {
  67. float distance = Vector3.Distance(targetPosition, this.actionPosition);
  68. if (distance <= this.actionRadius)
  69. return true;
  70. return false;
  71. }
  72. /// <summary>
  73. /// It activates event.
  74. /// scene owner gets reset and starts activating.
  75. /// </summary>
  76. public override void ExecuteAction()
  77. {
  78. this.owner.Reset(true);
  79. this.owner.Enabled = true;
  80. this.owner.Visible = true;
  81. waitingAction = false;
  82. finishedAction = true;
  83. }
  84. }
  85. }