2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Content;
12 /// A trigger is an invisible entity whose only purpose is
13 /// to check a condition and run a script when the condition
16 public class Trigger : IEntity
18 #region Public Methods
21 /// Construct a trigger entity.
23 /// <param name="identifier">The entity identifier.</param>
24 /// <param name="position">The position.</param>
25 /// <param name="info">The key-value pairs.</param>
26 /// <param name="game">The game reference.</param>
27 public Trigger(char identifier, Point position, Dictionary<string, string> info, Game game)
30 mPrevCondition = false;
31 mCoordinates = position;
34 if (info.TryGetValue("condition", out condition))
36 mCondition = new Script(condition, game);
38 else throw new Exception("Triggers must define a condition script.");
41 if (info.TryGetValue("event", out eventt))
43 mEvent = new Script(eventt, game);
45 else throw new Exception("Triggers must define an event script.");
49 /// Check the trigger condition and execute the event if the
50 /// condition evaluates to true.
54 Player player = mGame.GetPlayerAtCoordinates(mCoordinates);
57 bool condition = mCondition.Run(player);
58 if (condition && condition != mPrevCondition)
62 mPrevCondition = condition;
66 mPrevCondition = false;
72 /// Calls the trigger.
74 /// <param name="timeSpan">Unused.</param>
75 public virtual void Update(TimeSpan timeSpan)
80 public virtual void LoadContent(ContentManager contentManager)
82 // No implementation needed.
85 public virtual void Draw(SpriteBatch spriteBatch)
87 // No implementation needed.
90 public Vector2 Position
92 get { return Vector2.Zero; }
95 public Point Coordinates
97 get { return new Point(-1, -1); }
103 #region Private Variables