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
20 public Trigger(char identifier, Point position, Dictionary<string, string> info, Game game)
23 mPrevCondition = false;
24 mCoordinates = position;
27 if (info.TryGetValue("condition", out condition))
29 mCondition = new Script(condition, game);
31 else throw new Exception("Triggers must define a condition script.");
34 if (info.TryGetValue("event", out eventt))
36 mEvent = new Script(eventt, game);
38 else throw new Exception("Triggers must define an event script.");
41 public void Update(TimeSpan timeSpan)
43 Player player = mGame.GetPlayerAtCoordinates(mCoordinates);
46 bool condition = mCondition.Run(player);
47 if (condition && condition != mPrevCondition)
51 mPrevCondition = condition;
55 mPrevCondition = false;
59 public void LoadContent(ContentManager contentManager)
61 // No implementation needed.
64 public void Draw(SpriteBatch spriteBatch)
66 // No implementation needed.
69 public Vector2 Position
71 get { return Vector2.Zero; }
74 public Point Coordinates
76 get { return new Point(-1, -1); }
82 #region Private Variables